Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix hanging issue in dotnet test --coverage #45224

Merged
merged 2 commits into from
Nov 29, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions src/Cli/dotnet/commands/dotnet-test/TestApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ internal sealed class TestApplication : IDisposable
private readonly PipeNameDescription _pipeNameDescription = NamedPipeServer.GetPipeName(Guid.NewGuid().ToString("N"));
private readonly CancellationTokenSource _cancellationToken = new();

private NamedPipeServer _pipeConnection;
private Task _namedPipeConnectionLoop;
private Task _testAppPipeConnectionLoop;
private readonly List<NamedPipeServer> _testAppPipeConnections = new();
private ConcurrentDictionary<string, string> _executionIds = [];

public event EventHandler<HandshakeArgs> HandshakeReceived;
Expand Down Expand Up @@ -70,10 +70,11 @@ public async Task<int> RunAsync(bool isFilterMode, bool enableHelp, BuiltInOptio
processStartInfo.EnvironmentVariables.Add("TESTINGPLATFORM_VSTESTBRIDGE_RUNSETTINGS_FILE", _module.RunSettingsFilePath);
}

_namedPipeConnectionLoop = Task.Run(async () => await WaitConnectionAsync(_cancellationToken.Token), _cancellationToken.Token);
_testAppPipeConnectionLoop = Task.Run(async () => await WaitConnectionAsync(_cancellationToken.Token), _cancellationToken.Token);
var result = await StartProcess(processStartInfo);

_namedPipeConnectionLoop.Wait();
_cancellationToken.Cancel();
_testAppPipeConnectionLoop.Wait();

return result;
}
Expand All @@ -82,10 +83,14 @@ private async Task WaitConnectionAsync(CancellationToken token)
{
try
{
_pipeConnection = new(_pipeNameDescription, OnRequest, NamedPipeServerStream.MaxAllowedServerInstances, token, skipUnknownMessages: true);
_pipeConnection.RegisterAllSerializers();
while (!token.IsCancellationRequested)
{
NamedPipeServer pipeConnection = new(_pipeNameDescription, OnRequest, NamedPipeServerStream.MaxAllowedServerInstances, token, skipUnknownMessages: true);
pipeConnection.RegisterAllSerializers();

await _pipeConnection.WaitConnectionAsync(token);
await pipeConnection.WaitConnectionAsync(token);
_testAppPipeConnections.Add(pipeConnection);
}
}
catch (OperationCanceledException ex) when (ex.CancellationToken == token)
{
Expand Down Expand Up @@ -367,7 +372,10 @@ public override string ToString()

public void Dispose()
{
_pipeConnection?.Dispose();
foreach (var namedPipeServer in _testAppPipeConnections)
{
namedPipeServer.Dispose();
}
}
}
}
Loading