Skip to content

Stop trying to connect if the test host exits unexpectedly #1853

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

Merged
merged 4 commits into from
Nov 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,12 @@ public bool WaitForRequestHandlerConnection(int connectionTimeout, CancellationT
EqtTrace.Verbose("TestRequestSender.WaitForRequestHandlerConnection: waiting for connection with timeout: {0}", connectionTimeout);
}

var waitIndex = WaitHandle.WaitAny(new WaitHandle[] { this.connected.WaitHandle, cancellationToken.WaitHandle }, connectionTimeout);
// Wait until either connection is successful, handled by connected.WaitHandle
// or operation is cancelled, handled by cancellationToken.WaitHandle
// or testhost exits unexpectedly, handled by clientExited.WaitHandle
var waitIndex = WaitHandle.WaitAny(new WaitHandle[] { this.connected.WaitHandle, cancellationToken.WaitHandle, this.clientExited.WaitHandle }, connectionTimeout);

// Return true if wait is because of waitHandle.
// Return true if connection was successful.
return waitIndex == 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ public virtual bool SetupChannel(IEnumerable<string> sources)
connTimeout *= 5;
}

// Wait for a timeout for the client to connect.
// If TestHost does not launch then throw exception
// If Testhost launches, wait for connection.
if (!this.testHostLaunched ||
!this.RequestSender.WaitForRequestHandlerConnection(connTimeout * 1000, this.CancellationTokenSource.Token))
{
Expand Down Expand Up @@ -300,7 +301,6 @@ private void TestHostManagerHostLaunched(object sender, HostProviderEventArgs e)
private void TestHostManagerHostExited(object sender, HostProviderEventArgs e)
{
this.testHostProcessStdError = e.Data;

this.RequestSender.OnClientProcessExit(this.testHostProcessStdError);

this.testHostExited.Set();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,33 @@ public void WaitForRequestHandlerConnectionShouldNotConnectIfExceptionWasThrownB
}

[TestMethod]
public void WaitForRequestHandlerConnectionWithInfiniteTimeoutShouldReturnImmediatelyWhenCancellationRequested()
public void WaitForRequestHandlerConnectionWithTimeoutShouldReturnImmediatelyWhenCancellationRequested()
{
var cancellationTokenSource = new CancellationTokenSource();
cancellationTokenSource.Cancel();

var connected = this.testRequestSender.WaitForRequestHandlerConnection(-1, cancellationTokenSource.Token);
var connectionTimeout = 5000;
var watch = System.Diagnostics.Stopwatch.StartNew();
var connected = this.testRequestSender.WaitForRequestHandlerConnection(connectionTimeout, cancellationTokenSource.Token);
watch.Stop();

Assert.IsFalse(connected);
Assert.IsTrue(watch.ElapsedMilliseconds < connectionTimeout);
}

[TestMethod]
public void WaitForRequestHandlerConnectionWithTimeoutShouldReturnImmediatelyIfHostExitedUnexpectedly()
{
var cancellationTokenSource = new CancellationTokenSource();
this.testRequestSender.OnClientProcessExit("DummyError");

var connectionTimeout = 5000;
var watch = System.Diagnostics.Stopwatch.StartNew();
var connected = this.testRequestSender.WaitForRequestHandlerConnection(connectionTimeout, cancellationTokenSource.Token);
watch.Stop();

Assert.IsFalse(connected);
Assert.IsTrue(watch.ElapsedMilliseconds < connectionTimeout);
}

[TestMethod]
Expand Down