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

Fixed Selenium test run hang after stopping the debugger #3995

Merged
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -84,6 +84,8 @@ void InitializeAndStart()

if (exitCallBack != null)
{
const int timeout = 500;
cvpoienaru marked this conversation as resolved.
Show resolved Hide resolved

process.Exited += async (sender, args) =>
{
if (sender is Process p)
Expand All @@ -102,11 +104,20 @@ void InitializeAndStart()
//
// For older frameworks, the solution is more tricky but it seems we can get the expected
// behavior using the parameterless 'WaitForExit()' combined with an awaited Task.Run call.
var cts = new CancellationTokenSource(500);
var cts = new CancellationTokenSource(timeout);
#if NET5_0_OR_GREATER
await p.WaitForExitAsync(cts.Token);
#else
await Task.Run(() => p.WaitForExit(), cts.Token);
var os = new PlatformEnvironment().OperatingSystem;
cvpoienaru marked this conversation as resolved.
Show resolved Hide resolved
if (os is PlatformOperatingSystem.Windows)
{
p.WaitForExit(timeout);
Evangelink marked this conversation as resolved.
Show resolved Hide resolved
cvpoienaru marked this conversation as resolved.
Show resolved Hide resolved
}
else
{
cts.Token.Register(() => p.Kill());
await Task.Run(() => p.WaitForExit(), cts.Token).ConfigureAwait(false);
}
#endif
}
catch
Expand Down