Skip to content

Commit 5086449

Browse files
Fix hosting tests not capturing beginning process logs (#27565)
1 parent a732567 commit 5086449

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

src/Hosting/Server.IntegrationTesting/src/Deployers/SelfHostDeployer.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ public class SelfHostDeployer : ApplicationDeployer
2424

2525
public Process HostProcess { get; private set; }
2626

27+
// Use this property before calling DeployAsync
28+
// instead of using HostProcess.OutputDataReceived
29+
// in order to capture process output from the beginning of the process
30+
public Action<string> ProcessOutputListener { get; set; }
31+
2732
public SelfHostDeployer(DeploymentParameters deploymentParameters, ILoggerFactory loggerFactory)
2833
: base(deploymentParameters, loggerFactory)
2934
{
@@ -158,6 +163,8 @@ public override async Task<DeploymentResult> DeployAsync()
158163
actualUrl = new Uri(m.Groups["url"].Value);
159164
}
160165
}
166+
167+
ProcessOutputListener?.Invoke(dataArgs.Data);
161168
};
162169
var hostExitTokenSource = new CancellationTokenSource();
163170
HostProcess.Exited += (sender, e) =>

src/Hosting/test/FunctionalTests/ShutdownTests.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,21 +72,20 @@ private async Task ExecuteShutdownTest(string testName, string shutdownMechanic)
7272

7373
using (var deployer = new SelfHostDeployer(deploymentParameters, loggerFactory))
7474
{
75-
await deployer.DeployAsync();
76-
7775
var startedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
7876
var completedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
7977
var output = string.Empty;
80-
deployer.HostProcess.OutputDataReceived += (sender, args) =>
78+
79+
deployer.ProcessOutputListener = (data) =>
8180
{
82-
if (!string.IsNullOrEmpty(args.Data) && args.Data.StartsWith(StartedMessage, StringComparison.Ordinal))
81+
if (!string.IsNullOrEmpty(data) && data.StartsWith(StartedMessage, StringComparison.Ordinal))
8382
{
8483
startedTcs.TrySetResult();
85-
output += args.Data.Substring(StartedMessage.Length) + '\n';
84+
output += data.Substring(StartedMessage.Length) + '\n';
8685
}
8786
else
8887
{
89-
output += args.Data + '\n';
88+
output += data + '\n';
9089
}
9190

9291
if (output.Contains(CompletionMessage))
@@ -95,6 +94,8 @@ private async Task ExecuteShutdownTest(string testName, string shutdownMechanic)
9594
}
9695
};
9796

97+
await deployer.DeployAsync();
98+
9899
try
99100
{
100101
await startedTcs.Task.TimeoutAfter(TimeSpan.FromMinutes(1));

src/Hosting/test/FunctionalTests/WebHostBuilderTests.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,20 @@ public async Task InjectedStartup_DefaultApplicationNameIsEntryAssembly(TestVari
4242

4343
using (var deployer = new SelfHostDeployer(deploymentParameters, loggerFactory))
4444
{
45-
await deployer.DeployAsync();
46-
47-
string output = string.Empty;
4845
var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
49-
deployer.HostProcess.OutputDataReceived += (sender, args) =>
46+
var output = string.Empty;
47+
48+
deployer.ProcessOutputListener = (data) =>
5049
{
51-
if (!string.IsNullOrWhiteSpace(args.Data))
50+
if (!string.IsNullOrWhiteSpace(data))
5251
{
53-
output += args.Data + '\n';
52+
output += data + '\n';
5453
tcs.TrySetResult();
5554
}
5655
};
5756

57+
await deployer.DeployAsync();
58+
5859
try
5960
{
6061
await tcs.Task.TimeoutAfter(TimeSpan.FromMinutes(1));

0 commit comments

Comments
 (0)