Test Runner test started needs to handle messages when dotnet test is in a TestStarted state, as we will receive multiple test started messages. Also, to prevent a crash, when we get a message that terminates the adapter or the runner, we need to stop listening. Unfortunately, this needs to be directly where we read the messages, because if we give a handler a chance to handle that message, the reader will already be trying to read again.
This commit is contained in:
parent
b00a75e3ea
commit
46b1fb42c0
3 changed files with 33 additions and 3 deletions
|
@ -14,8 +14,14 @@ namespace Microsoft.DotNet.Tools.Test
|
||||||
|
|
||||||
protected override bool CanHandleMessage(IDotnetTest dotnetTest, Message message)
|
protected override bool CanHandleMessage(IDotnetTest dotnetTest, Message message)
|
||||||
{
|
{
|
||||||
return dotnetTest.State == DotnetTestState.TestExecutionSentTestRunnerProcessStartInfo &&
|
return IsAtAnAcceptableState(dotnetTest) &&
|
||||||
message.MessageType == TestMessageTypes.TestRunnerTestStarted;
|
message.MessageType == TestMessageTypes.TestRunnerTestStarted;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static bool IsAtAnAcceptableState(IDotnetTest dotnetTest)
|
||||||
|
{
|
||||||
|
return dotnetTest.State == DotnetTestState.TestExecutionSentTestRunnerProcessStartInfo ||
|
||||||
|
dotnetTest.State == DotnetTestState.TestExecutionStarted;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,6 +114,11 @@ namespace Microsoft.DotNet.Tools.Test
|
||||||
var message = JsonConvert.DeserializeObject<Message>(rawMessage);
|
var message = JsonConvert.DeserializeObject<Message>(rawMessage);
|
||||||
|
|
||||||
MessageReceived?.Invoke(this, message);
|
MessageReceived?.Invoke(this, message);
|
||||||
|
|
||||||
|
if (ShouldStopListening(message))
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -127,6 +132,12 @@ namespace Microsoft.DotNet.Tools.Test
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static bool ShouldStopListening(Message message)
|
||||||
|
{
|
||||||
|
return message.MessageType == TestMessageTypes.TestRunnerTestCompleted ||
|
||||||
|
message.MessageType == TestMessageTypes.TestSessionTerminate;
|
||||||
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
Socket.Dispose();
|
Socket.Dispose();
|
||||||
|
|
|
@ -36,7 +36,7 @@ namespace Microsoft.Dotnet.Tools.Test.Tests
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void It_returns_NoOp_if_the_dotnet_test_state_is_not_TestExecutionSentTestRunnerProcessStartInfo()
|
public void It_returns_NoOp_if_the_dotnet_test_state_is_not_TestExecutionSentTestRunnerProcessStartInfo_or_TestExecutionTestStarted()
|
||||||
{
|
{
|
||||||
var dotnetTestMock = new Mock<IDotnetTest>();
|
var dotnetTestMock = new Mock<IDotnetTest>();
|
||||||
dotnetTestMock.Setup(d => d.State).Returns(DotnetTestState.Terminated);
|
dotnetTestMock.Setup(d => d.State).Returns(DotnetTestState.Terminated);
|
||||||
|
@ -59,7 +59,7 @@ namespace Microsoft.Dotnet.Tools.Test.Tests
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void It_returns_TestExecutionStarted_when_it_handles_the_message()
|
public void It_returns_TestExecutionStarted_when_it_handles_the_message_and_current_state_is_TestExecutionSentTestRunnerProcessStartInfo()
|
||||||
{
|
{
|
||||||
var nextState = _testRunnerTestStartedMessageHandler.HandleMessage(
|
var nextState = _testRunnerTestStartedMessageHandler.HandleMessage(
|
||||||
_dotnetTestMock.Object,
|
_dotnetTestMock.Object,
|
||||||
|
@ -68,6 +68,19 @@ namespace Microsoft.Dotnet.Tools.Test.Tests
|
||||||
nextState.Should().Be(DotnetTestState.TestExecutionStarted);
|
nextState.Should().Be(DotnetTestState.TestExecutionStarted);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void It_returns_TestExecutionStarted_when_it_handles_the_message_and_current_state_is_TestExecutionTestStarted()
|
||||||
|
{
|
||||||
|
var dotnetTestMock = new Mock<IDotnetTest>();
|
||||||
|
dotnetTestMock.Setup(d => d.State).Returns(DotnetTestState.TestExecutionStarted);
|
||||||
|
|
||||||
|
var nextState = _testRunnerTestStartedMessageHandler.HandleMessage(
|
||||||
|
dotnetTestMock.Object,
|
||||||
|
_validMessage);
|
||||||
|
|
||||||
|
nextState.Should().Be(DotnetTestState.TestExecutionStarted);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void It_sends_a_TestExecutionTestStarted_when_it_handles_the_message()
|
public void It_sends_a_TestExecutionTestStarted_when_it_handles_the_message()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue