Merge pull request #1552 from livarcocc/make_version_check_optional
Making the version check an optional message for test discovery and test run.
This commit is contained in:
commit
b00a75e3ea
7 changed files with 104 additions and 27 deletions
|
@ -2,6 +2,7 @@
|
|||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Testing.Abstractions;
|
||||
|
||||
namespace Microsoft.DotNet.Tools.Test
|
||||
|
@ -12,6 +13,8 @@ namespace Microsoft.DotNet.Tools.Test
|
|||
|
||||
int Port { get; }
|
||||
|
||||
void Accept();
|
||||
|
||||
void Send(Message message);
|
||||
|
||||
void SendError(string error);
|
||||
|
|
|
@ -41,6 +41,8 @@ namespace Microsoft.DotNet.Tools.Test
|
|||
|
||||
dotnetTest.StartListeningTo(testRunnerChannel);
|
||||
|
||||
testRunnerChannel.Accept();
|
||||
|
||||
var testRunner = _testRunnerFactory.CreateTestRunner(
|
||||
new RunTestsArgumentsBuilder(dotnetTest.PathToAssemblyUnderTest, testRunnerChannel.Port, message));
|
||||
|
||||
|
@ -55,8 +57,14 @@ namespace Microsoft.DotNet.Tools.Test
|
|||
|
||||
private static bool CanHandleMessage(IDotnetTest dotnetTest, Message message)
|
||||
{
|
||||
return dotnetTest.State == DotnetTestState.VersionCheckCompleted &&
|
||||
return IsAtAnAcceptableState(dotnetTest) &&
|
||||
message.MessageType == TestMessageTypes.TestExecutionGetTestRunnerProcessStartInfo;
|
||||
}
|
||||
|
||||
private static bool IsAtAnAcceptableState(IDotnetTest dotnetTest)
|
||||
{
|
||||
return dotnetTest.State == DotnetTestState.VersionCheckCompleted ||
|
||||
dotnetTest.State == DotnetTestState.InitialState;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,6 +55,8 @@ namespace Microsoft.DotNet.Cli.Tools.Test
|
|||
|
||||
dotnetTest.StartListeningTo(testRunnerChannel);
|
||||
|
||||
testRunnerChannel.Accept();
|
||||
|
||||
var testRunner = _testRunnerFactory.CreateTestRunner(
|
||||
new DiscoverTestsArgumentsBuilder(dotnetTest.PathToAssemblyUnderTest, testRunnerChannel.Port));
|
||||
|
||||
|
@ -68,8 +70,13 @@ namespace Microsoft.DotNet.Cli.Tools.Test
|
|||
|
||||
private static bool CanHandleMessage(IDotnetTest dotnetTest, Message message)
|
||||
{
|
||||
return dotnetTest.State == DotnetTestState.VersionCheckCompleted &&
|
||||
message.MessageType == TestMessageTypes.TestDiscoveryStart;
|
||||
return IsAtAnAcceptableState(dotnetTest) && message.MessageType == TestMessageTypes.TestDiscoveryStart;
|
||||
}
|
||||
|
||||
private static bool IsAtAnAcceptableState(IDotnetTest dotnetTest)
|
||||
{
|
||||
return (dotnetTest.State == DotnetTestState.VersionCheckCompleted ||
|
||||
dotnetTest.State == DotnetTestState.InitialState);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -141,6 +141,8 @@ namespace Microsoft.DotNet.Tools.Test
|
|||
|
||||
dotnetTest.StartListeningTo(adapterChannel);
|
||||
|
||||
adapterChannel.Accept();
|
||||
|
||||
dotnetTest.StartHandlingMessages();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ using System.IO;
|
|||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Testing.Abstractions;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
@ -18,37 +19,47 @@ namespace Microsoft.DotNet.Tools.Test
|
|||
public static ReportingChannel ListenOn(int port)
|
||||
{
|
||||
// This fixes the mono incompatibility but ties it to ipv4 connections
|
||||
using (var listenSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
|
||||
{
|
||||
listenSocket.Bind(new IPEndPoint(IPAddress.Loopback, port));
|
||||
listenSocket.Listen(10);
|
||||
var listenSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||
|
||||
var socket = listenSocket.Accept();
|
||||
listenSocket.Bind(new IPEndPoint(IPAddress.Loopback, port));
|
||||
listenSocket.Listen(10);
|
||||
|
||||
return new ReportingChannel(socket);
|
||||
}
|
||||
return new ReportingChannel(listenSocket);
|
||||
}
|
||||
|
||||
private readonly BinaryWriter _writer;
|
||||
private readonly BinaryReader _reader;
|
||||
private BinaryWriter _writer;
|
||||
private BinaryReader _reader;
|
||||
private Socket _listenSocket;
|
||||
|
||||
private ReportingChannel(Socket socket)
|
||||
private ReportingChannel(Socket listenSocket)
|
||||
{
|
||||
Socket = socket;
|
||||
|
||||
var stream = new NetworkStream(Socket);
|
||||
_writer = new BinaryWriter(stream);
|
||||
_reader = new BinaryReader(stream);
|
||||
|
||||
// Read incoming messages on the background thread
|
||||
new Thread(ReadMessages) { IsBackground = true }.Start();
|
||||
_listenSocket = listenSocket;
|
||||
Port = ((IPEndPoint)listenSocket.LocalEndPoint).Port;
|
||||
}
|
||||
|
||||
public event EventHandler<Message> MessageReceived;
|
||||
|
||||
public Socket Socket { get; private set; }
|
||||
|
||||
public int Port => ((IPEndPoint) Socket.LocalEndPoint).Port;
|
||||
public int Port { get; }
|
||||
|
||||
public void Accept()
|
||||
{
|
||||
new Thread(() =>
|
||||
{
|
||||
using (_listenSocket)
|
||||
{
|
||||
Socket = _listenSocket.Accept();
|
||||
|
||||
var stream = new NetworkStream(Socket);
|
||||
_writer = new BinaryWriter(stream);
|
||||
_reader = new BinaryReader(stream);
|
||||
|
||||
// Read incoming messages on the background thread
|
||||
new Thread(ReadMessages) { IsBackground = true }.Start();
|
||||
}
|
||||
}) { IsBackground = true }.Start();
|
||||
}
|
||||
|
||||
public void Send(Message message)
|
||||
{
|
||||
|
@ -99,7 +110,8 @@ namespace Microsoft.DotNet.Tools.Test
|
|||
{
|
||||
try
|
||||
{
|
||||
var message = JsonConvert.DeserializeObject<Message>(_reader.ReadString());
|
||||
var rawMessage = _reader.ReadString();
|
||||
var message = JsonConvert.DeserializeObject<Message>(rawMessage);
|
||||
|
||||
MessageReceived?.Invoke(this, message);
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ namespace Microsoft.Dotnet.Tools.Test.Tests
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public void It_returns_NoOp_if_the_dotnet_test_state_is_not_VersionCheckCompleted()
|
||||
public void It_returns_NoOp_if_the_dotnet_test_state_is_not_VersionCheckCompleted_or_InitialState()
|
||||
{
|
||||
var dotnetTestMock = new Mock<IDotnetTest>();
|
||||
dotnetTestMock.Setup(d => d.State).Returns(DotnetTestState.Terminated);
|
||||
|
@ -84,7 +84,19 @@ namespace Microsoft.Dotnet.Tools.Test.Tests
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public void It_returns_TestDiscoveryCompleted_when_it_handles_the_message()
|
||||
public void It_returns_TestDiscoveryCompleted_when_it_handles_the_message_and_current_state_is_InitialState()
|
||||
{
|
||||
var dotnetTestMock = new Mock<IDotnetTest>();
|
||||
dotnetTestMock.Setup(d => d.State).Returns(DotnetTestState.InitialState);
|
||||
|
||||
var nextState =
|
||||
_testDiscoveryStartMessageHandler.HandleMessage(dotnetTestMock.Object, _validMessage);
|
||||
|
||||
nextState.Should().Be(DotnetTestState.TestDiscoveryStarted);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_returns_TestDiscoveryCompleted_when_it_handles_the_message_and_current_state_is_VersionCheckCompleted()
|
||||
{
|
||||
var nextState =
|
||||
_testDiscoveryStartMessageHandler.HandleMessage(_dotnetTestAtVersionCheckCompletedState, _validMessage);
|
||||
|
@ -122,6 +134,16 @@ namespace Microsoft.Dotnet.Tools.Test.Tests
|
|||
_reportingChannelFactoryMock.Verify(r => r.CreateChannelWithAnyAvailablePort(), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_calls_accept_on_the_test_runner_channel()
|
||||
{
|
||||
_testDiscoveryStartMessageHandler.HandleMessage(
|
||||
_dotnetTestMock.Object,
|
||||
_validMessage);
|
||||
|
||||
_testRunnerChannelMock.Verify(t => t.Accept(), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_makes_dotnet_test_listen_on_the_test_runner_port_for_messages_when_it_handles_the_message()
|
||||
{
|
||||
|
|
|
@ -68,7 +68,7 @@ namespace Microsoft.Dotnet.Tools.Test.Tests
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public void It_returns_NoOp_if_the_dotnet_test_state_is_not_VersionCheckCompleted()
|
||||
public void It_returns_NoOp_if_the_dotnet_test_state_is_not_VersionCheckCompleted_or_InitialState()
|
||||
{
|
||||
var dotnetTestMock = new Mock<IDotnetTest>();
|
||||
dotnetTestMock.Setup(d => d.State).Returns(DotnetTestState.Terminated);
|
||||
|
@ -91,7 +91,20 @@ namespace Microsoft.Dotnet.Tools.Test.Tests
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public void It_returns_TestExecutionSentTestRunnerProcessStartInfo_when_it_handles_the_message()
|
||||
public void It_returns_TestExecutionSentTestRunnerProcessStartInfo_when_it_handles_the_message_and_current_state_is_InitialState()
|
||||
{
|
||||
var dotnetTestMock = new Mock<IDotnetTest>();
|
||||
dotnetTestMock.Setup(d => d.State).Returns(DotnetTestState.InitialState);
|
||||
|
||||
var nextState = _testGetTestRunnerProcessStartInfoMessageHandler.HandleMessage(
|
||||
dotnetTestMock.Object,
|
||||
_validMessage);
|
||||
|
||||
nextState.Should().Be(DotnetTestState.TestExecutionSentTestRunnerProcessStartInfo);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_returns_TestExecutionSentTestRunnerProcessStartInfo_when_it_handles_the_message_and_current_state_is_VersionCheckCompleted()
|
||||
{
|
||||
var nextState = _testGetTestRunnerProcessStartInfoMessageHandler.HandleMessage(
|
||||
_dotnetTestMock.Object,
|
||||
|
@ -135,6 +148,16 @@ namespace Microsoft.Dotnet.Tools.Test.Tests
|
|||
_reportingChannelFactoryMock.Verify(r => r.CreateChannelWithAnyAvailablePort(), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_calls_accept_on_the_test_runner_channel()
|
||||
{
|
||||
_testGetTestRunnerProcessStartInfoMessageHandler.HandleMessage(
|
||||
_dotnetTestMock.Object,
|
||||
_validMessage);
|
||||
|
||||
_testRunnerChannelMock.Verify(t => t.Accept(), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_makes_dotnet_test_listen_on_the_test_runner_port_for_messages_when_it_handles_the_message()
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue