Skip to content

Commit 021e994

Browse files
committed
fixing tests...
1 parent c78bee7 commit 021e994

File tree

2 files changed

+26
-22
lines changed

2 files changed

+26
-22
lines changed

test/Azure.Functions.Cli.Tests/E2E/Helpers/ProcessHelper.cs

+20-16
Original file line numberDiff line numberDiff line change
@@ -103,25 +103,25 @@ public static void RunProcess(string fileName, string arguments, string workingD
103103
CreateNoWindow = true,
104104
UseShellExecute = false,
105105
WorkingDirectory = workingDirectory,
106-
FileName = fileName,
106+
RedirectStandardOutput = true,
107107
RedirectStandardError = true,
108-
RedirectStandardOutput = true
108+
FileName = fileName
109109
};
110110

111111
if (!string.IsNullOrEmpty(arguments))
112112
{
113113
startInfo.Arguments = arguments;
114114
}
115115

116-
Process testProcess = Process.Start(startInfo);
117-
string standardOut = null;
118-
string standardError = null;
116+
Process testProcess = new()
117+
{
118+
StartInfo = startInfo,
119+
};
119120

120121
testProcess.OutputDataReceived += (sender, e) =>
121122
{
122123
if (e.Data != null)
123124
{
124-
standardOut = e.Data + Environment.NewLine;
125125
writeOutput?.Invoke(e.Data);
126126
}
127127
};
@@ -130,31 +130,35 @@ public static void RunProcess(string fileName, string arguments, string workingD
130130
{
131131
if (e.Data != null)
132132
{
133-
standardOut += e.Data + Environment.NewLine;
134133
writeError?.Invoke(e.Data);
135134
}
136135
};
137136

138-
bool completed = testProcess.WaitForExit((int)procTimeout.TotalMilliseconds);
137+
testProcess.Start();
138+
testProcess.BeginOutputReadLine();
139+
testProcess.BeginErrorReadLine();
139140

140-
if (!completed)
141+
bool completed = false;
142+
try
141143
{
142-
testProcess.Kill();
143-
throw new TimeoutException($"Process '{fileName} {arguments}' in working directory '{workingDirectory}' did not complete in {procTimeout}.");
144+
completed = testProcess.WaitForExit((int)procTimeout.TotalMilliseconds);
145+
}
146+
catch (Exception ex)
147+
{
148+
Console.WriteLine($"Process '{fileName} {arguments}' in working directory '{workingDirectory}' threw exception '{ex}'.");
144149
}
145150

146-
if (testProcess.ExitCode != 0)
151+
if (!completed)
147152
{
148-
throw new InvalidOperationException($"Process '{fileName} {arguments}' in working directory '{workingDirectory}' exited with code '{testProcess.ExitCode}'.{Environment.NewLine}" +
149-
$"Output:{Environment.NewLine}{standardOut}{Environment.NewLine}Error:{Environment.NewLine}{standardError}");
153+
throw new TimeoutException($"Process '{fileName} {arguments}' in working directory '{workingDirectory}' did not complete in {procTimeout}.");
150154
}
151155
}
152156

153157
private static string ExecuteCommand(string command)
154158
{
155-
string output = null;
159+
string output = string.Empty;
156160

157-
RunProcess(CommandExe, command, null, writeOutput: o => output = o);
161+
RunProcess(CommandExe, command, null, writeOutput: o => output += o + Environment.NewLine);
158162

159163
return output;
160164
}

test/Azure.Functions.Cli.Tests/E2E/StartTests.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
using System;
2-
using System.IO;
32
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.IO;
5+
using System.Net;
46
using System.Net.Http;
7+
using System.Net.Sockets;
58
using System.Text;
69
using System.Threading.Tasks;
10+
using Azure.Functions.Cli.Common;
711
using Azure.Functions.Cli.Tests.E2E.Helpers;
812
using FluentAssertions;
913
using Xunit;
1014
using Xunit.Abstractions;
11-
using System.Net.Sockets;
12-
using System.Net;
13-
using System.Diagnostics;
14-
using Azure.Functions.Cli.Common;
1515

1616
namespace Azure.Functions.Cli.Tests.E2E
1717
{
@@ -976,7 +976,7 @@ await CliTester.Run(new RunConfiguration[]
976976
},
977977
Test = async (_, p, stdout) =>
978978
{
979-
await LogWatcher.WaitForLogOutput(stdout, "Initializing function HTTP routes", TimeSpan.FromSeconds(5));
979+
await LogWatcher.WaitForLogOutput(stdout, "Worker process started and initialized", TimeSpan.FromSeconds(5));
980980
p.Kill();
981981
},
982982
CommandTimeout = TimeSpan.FromSeconds(300)

0 commit comments

Comments
 (0)