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

Missing Cancel Implementation #2227

Merged
merged 4 commits into from Oct 24, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -87,6 +87,11 @@ public interface ITestRequestSender : IDisposable
/// </summary>
void SendTestRunAbort();

/// <summary>
/// Send the request to cancel the test discovery
/// </summary>
void SendTestDiscoveryCancel();

/// <summary>
/// Handle client process exit
/// </summary>
Expand Down
Expand Up @@ -317,6 +317,23 @@ public void StartTestRun(TestRunCriteriaWithTests runCriteria, ITestRunEventsHan
this.channel.Send(message);
}

/// <inheritdoc />
public void SendTestDiscoveryCancel()
{
if (this.IsOperationComplete())
{
EqtTrace.Verbose("TestRequestSender: SendTestDiscoveryCancel: Operation is already complete. Skip error message.");
return;
}

if (EqtTrace.IsVerboseEnabled)
{
EqtTrace.Verbose("TestRequestSender.SendTestDiscoveryCancel: Sending test discovery cancel.");
}

this.channel?.Send(this.dataSerializer.SerializeMessage(MessageType.CancelDiscovery));
}

/// <inheritdoc />
public void SendTestRunCancel()
{
Expand Down
Expand Up @@ -140,7 +140,13 @@ public void DiscoverTests(DiscoveryCriteria discoveryCriteria, ITestDiscoveryEve
/// <inheritdoc/>
public void Abort()
{
// This is no-op for the moment. There is no discovery abort message?
// Cancel fast, try to stop testhost deployment/launch
this.CancellationTokenSource.Cancel();

if (this.isCommunicationEstablished)
{
this.RequestSender.SendTestDiscoveryCancel();
}
}

/// <inheritdoc/>
Expand Down
Expand Up @@ -318,6 +318,12 @@ public void OnMessageReceived(object sender, MessageReceivedEventArgs messageRec
break;
}

case MessageType.CancelDiscovery:
jobQueue.Pause();
this.testHostManagerFactoryReady.Wait();
testHostManagerFactory.GetDiscoveryManager().Abort();
break;

case MessageType.CancelTestRun:
jobQueue.Pause();
this.testHostManagerFactoryReady.Wait();
Expand Down
Expand Up @@ -202,6 +202,19 @@ public void EndSessionShouldNotSendTestRunAbortMessageIfClientDisconnected()
this.mockChannel.Verify(mockChannel => mockChannel.Send(MessageType.CancelTestRun), Times.Never);
}

[TestMethod]
public void SendTestDiscoveryCancelShouldSendTestDiscoveryCancelMessage()
{
var serializedCancelMessage = "Message : TestDiscovery.Cancel";
this.SetupFakeCommunicationChannel();
this.testRequestSender.DiscoverTests(new DiscoveryCriteria(), this.mockDiscoveryEventsHandler.Object);
this.mockDataSerializer.Setup(ds => ds.SerializeMessage(MessageType.CancelDiscovery)).Returns(serializedCancelMessage);

this.testRequestSender.SendTestDiscoveryCancel();

this.mockChannel.Verify(mockChannel => mockChannel.Send(serializedCancelMessage), Times.Once);
}

[DataTestMethod]
[DataRow("")]
[DataRow(" ")]
Expand Down
Expand Up @@ -493,6 +493,21 @@ public void DiscoveryManagerShouldPassOnHandleLogMessage()
mockTestDiscoveryEventsHandler.Verify(mtdeh => mtdeh.HandleLogMessage(It.IsAny<TestMessageLevel>(), It.IsAny<string>()), Times.Once);
}

[TestMethod]
public void AbortShouldSendTestDiscoveryCancelIfCommunicationSuccessful()
{
var mockTestDiscoveryEventsHandler = new Mock<ITestDiscoveryEventsHandler2>();
this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny<int>(), It.IsAny<CancellationToken>())).Returns(true);

Mock<ITestRunEventsHandler> mockTestRunEventsHandler = new Mock<ITestRunEventsHandler>();

this.testDiscoveryManager.DiscoverTests(this.discoveryCriteria, mockTestDiscoveryEventsHandler.Object);

this.testDiscoveryManager.Abort();

this.mockRequestSender.Verify(s => s.SendTestDiscoveryCancel(), Times.Once);
}

private void InvokeAndVerifyDiscoverTests(bool skipDefaultAdapters)
{
TestPluginCache.Instance = null;
Expand Down
Expand Up @@ -286,7 +286,17 @@ public void ProcessRequestsExecutionCancelShouldCancelTestRun()
this.SendSessionEnd();
}

// ProcessRequestsExecutionCancelShouldStopRequestProcessing
[TestMethod]
public void ProcessRequestsDiscoveryCancelShouldCancelDiscovery()
{
var message = this.dataSerializer.SerializePayload(MessageType.CancelDiscovery, string.Empty);

this.ProcessRequestsAsync(this.mockTestHostManagerFactory.Object);
this.SendMessageOnChannel(message);

mockDiscoveryManager.Verify(dm => dm.Abort(), Times.Once);
this.SendSessionEnd();
}

[TestMethod]
public void ProcessRequestsExecutionLaunchAdapterProcessWithDebuggerShouldSendAckMessage()
Expand All @@ -312,8 +322,6 @@ public void ProcessRequestsExecutionAbortShouldStopTestRun()
this.SendSessionEnd();
}

// ProcessRequestsExecutionAbortShouldStopRequestProcessing

[TestMethod]
public void SendExecutionCompleteShouldSendTestRunCompletePayloadOnChannel()
{
Expand Down