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

Protocolv2 DesignMode #698

Merged
merged 3 commits into from
Apr 12, 2017
Merged
Show file tree
Hide file tree
Changes from 2 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
15 changes: 7 additions & 8 deletions src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public class DesignModeClient : IDesignModeClient

private object ackLockObject = new object();

ProtocolConfig protocolConfig = Constants.DefaultProtocolConfig;

/// <summary>
/// The timeout for the client to connect to the server.
/// </summary>
Expand Down Expand Up @@ -126,12 +128,9 @@ private void ProcessRequests(ITestRequestManager testRequestManager)
{
case MessageType.VersionCheck:
{
// At this point, we cannot add stuff to object model like "ProtocolVersionMessage"
// as that cannot be acessed from testwindow which still uses TP-V1
// we are sending a version number as an integer for now
// TODO: Find a better way without breaking TW which using TP-V1
var payload = 1;
this.communicationManager.SendMessage(MessageType.VersionCheck, payload);
var version = this.dataSerializer.DeserializePayload<int>(message);
this.protocolConfig.Version = Math.Min(version, this.protocolConfig.Version);
this.communicationManager.SendMessage(MessageType.VersionCheck, this.protocolConfig.Version);
break;
}

Expand All @@ -145,7 +144,7 @@ private void ProcessRequests(ITestRequestManager testRequestManager)
case MessageType.StartDiscovery:
{
var discoveryPayload = message.Payload.ToObject<DiscoveryRequestPayload>();
testRequestManager.DiscoverTests(discoveryPayload, new DesignModeTestEventsRegistrar(this));
testRequestManager.DiscoverTests(discoveryPayload, new DesignModeTestEventsRegistrar(this), this.protocolConfig);
break;
}

Expand Down Expand Up @@ -274,7 +273,7 @@ private void StartTestRun(TestRunRequestPayload testRunPayload, ITestRequestMana
var customLauncher = skipTestHostLaunch ?
DesignModeTestHostLauncherFactory.GetCustomHostLauncherForTestRun(this, testRunPayload) : null;

testRequestManager.RunTests(testRunPayload, customLauncher, new DesignModeTestEventsRegistrar(this));
testRequestManager.RunTests(testRunPayload, customLauncher, new DesignModeTestEventsRegistrar(this), this.protocolConfig);
}
catch(Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace Microsoft.VisualStudio.TestPlatform.Client.RequestHelper

using Microsoft.VisualStudio.TestPlatform.Common.Interfaces;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;

/// <summary>
/// Defines the contract that commandline
Expand All @@ -29,17 +30,19 @@ public interface ITestRequestManager
/// </summary>
/// <param name="discoveryPayload">Discovery payload</param>
/// <param name="disoveryEventsRegistrar">Discovery events registrar - registers and unregisters discovery events</param>
/// <param name="protocolConfig">Protocol related information</param>
/// <returns>True, if successful</returns>
bool DiscoverTests(DiscoveryRequestPayload discoveryPayload, ITestDiscoveryEventsRegistrar disoveryEventsRegistrar);
bool DiscoverTests(DiscoveryRequestPayload discoveryPayload, ITestDiscoveryEventsRegistrar disoveryEventsRegistrar, ProtocolConfig protocolConfig);

/// <summary>
/// Run Tests with given a test of sources
/// </summary>
/// <param name="testRunRequestPayLoad">Test Run Request payload</param>
/// <param name="customTestHostLauncher">Custom testHostLauncher for the run</param>
/// <param name="testRunEventsRegistrar">RunEvents registrar</param>
/// <param name="protocolConfig">Protocol related information</param>
/// <returns>True, if sucessful</returns>
bool RunTests(TestRunRequestPayload testRunRequestPayLoad, ITestHostLauncher customTestHostLauncher, ITestRunEventsRegistrar testRunEventsRegistrar);
bool RunTests(TestRunRequestPayload testRunRequestPayLoad, ITestHostLauncher customTestHostLauncher, ITestRunEventsRegistrar testRunEventsRegistrar, ProtocolConfig protocolConfig);

/// <summary>
/// Cancel the current TestRun request
Expand Down
10 changes: 6 additions & 4 deletions src/Microsoft.TestPlatform.Client/TestPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ protected TestPlatform(ITestEngine testEngine, IFileHelper filehelper, TestRunti
/// The create discovery request.
/// </summary>
/// <param name="discoveryCriteria"> The discovery criteria. </param>
/// <param name="protocolConfig"> Protocol related information. </param>
/// <returns> The <see cref="IDiscoveryRequest"/>. </returns>
/// <exception cref="ArgumentNullException"> Throws if parameter is null. </exception>
public IDiscoveryRequest CreateDiscoveryRequest(DiscoveryCriteria discoveryCriteria)
public IDiscoveryRequest CreateDiscoveryRequest(DiscoveryCriteria discoveryCriteria, ProtocolConfig protocolConfig)
{
if (discoveryCriteria == null)
{
Expand All @@ -79,7 +80,7 @@ public IDiscoveryRequest CreateDiscoveryRequest(DiscoveryCriteria discoveryCrite

var testHostManager = this.testHostProviderManager.GetTestHostManagerByRunConfiguration(discoveryCriteria.RunSettings);

var discoveryManager = this.TestEngine.GetDiscoveryManager(testHostManager, discoveryCriteria);
var discoveryManager = this.TestEngine.GetDiscoveryManager(testHostManager, discoveryCriteria, protocolConfig);
discoveryManager.Initialize();

return new DiscoveryRequest(discoveryCriteria, discoveryManager);
Expand All @@ -89,9 +90,10 @@ public IDiscoveryRequest CreateDiscoveryRequest(DiscoveryCriteria discoveryCrite
/// The create test run request.
/// </summary>
/// <param name="testRunCriteria"> The test run criteria. </param>
/// <param name="protocolConfig"> Protocol related information. </param>
/// <returns> The <see cref="ITestRunRequest"/>. </returns>
/// <exception cref="ArgumentNullException"> Throws if parameter is null. </exception>
public ITestRunRequest CreateTestRunRequest(TestRunCriteria testRunCriteria)
public ITestRunRequest CreateTestRunRequest(TestRunCriteria testRunCriteria, ProtocolConfig protocolConfig)
{
if (testRunCriteria == null)
{
Expand Down Expand Up @@ -119,7 +121,7 @@ public ITestRunRequest CreateTestRunRequest(TestRunCriteria testRunCriteria)
testHostManager.SetCustomLauncher(testRunCriteria.TestHostLauncher);
}

var executionManager = this.TestEngine.GetExecutionManager(testHostManager, testRunCriteria);
var executionManager = this.TestEngine.GetExecutionManager(testHostManager, testRunCriteria, protocolConfig);
executionManager.Initialize();

return new TestRunRequest(testRunCriteria, executionManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,22 @@ public interface ITestEngine
/// <summary>
/// Fetches the DiscoveryManager for this engine. This manager would provide all functionality required for discovery.
/// </summary>
/// <param name="testHostManager">
/// Test host manager for the current test discovery.
/// </param>
/// <param name="discoveryCriteria">
/// The discovery Criteria.
/// </param>
/// <param name="testHostManager">Test host manager for the current test discovery.</param>
/// <param name="discoveryCriteria">The discovery Criteria.</param>
/// <param name="protocolConfig">Protocol related information.</param>
/// <returns>
/// ITestDiscoveryManager object that can do discovery
/// </returns>
IProxyDiscoveryManager GetDiscoveryManager(ITestRuntimeProvider testHostManager, DiscoveryCriteria discoveryCriteria);
IProxyDiscoveryManager GetDiscoveryManager(ITestRuntimeProvider testHostManager, DiscoveryCriteria discoveryCriteria, ProtocolConfig protocolConfig);

/// <summary>
/// Fetches the ExecutionManager for this engine. This manager would provide all functionality required for execution.
/// </summary>
/// <param name="testHostManager">Test host manager for current test run.</param>
/// <param name="testRunCriteria">TestRunCriteria of the current test run</param>
/// <param name="protocolConfig">Protocol related information</param>
/// <returns>ITestExecutionManager object that can do execution</returns>
IProxyExecutionManager GetExecutionManager(ITestRuntimeProvider testHostManager, TestRunCriteria testRunCriteria);
IProxyExecutionManager GetExecutionManager(ITestRuntimeProvider testHostManager, TestRunCriteria testRunCriteria, ProtocolConfig protocolConfig);

/// <summary>
/// Fetches the extension manager for this engine. This manager would provide extensibility
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ public string SerializePayload(string messageType, object payload, int version)
var serializer = this.GetPayloadSerializer(version);
var serializedPayload = JToken.FromObject(payload, serializer);

var message = version == 1 ?
new Message { MessageType = messageType, Payload = serializedPayload } :
new VersionedMessage { MessageType = messageType, Version = version, Payload = serializedPayload };
var message = version > 1 ?
new VersionedMessage { MessageType = messageType, Version = version, Payload = serializedPayload } :
new Message { MessageType = messageType, Payload = serializedPayload };

return JsonConvert.SerializeObject(message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ public sealed class TestRequestSender : ITestRequestSender
/// <summary>
/// Initializes a new instance of the <see cref="TestRequestSender"/> class.
/// </summary>
public TestRequestSender()
: this(new SocketCommunicationManager(), JsonDataSerializer.Instance)
/// <param name="protocolConfig">Protocol related information</param>
public TestRequestSender(ProtocolConfig protocolConfig)
: this(new SocketCommunicationManager(), JsonDataSerializer.Instance, protocolConfig)
{
}

Expand All @@ -50,8 +51,10 @@ public TestRequestSender()
/// </summary>
/// <param name="communicationManager">Communication Manager for sending and receiving messages.</param>
/// <param name="dataSerializer">Serializer for serialization and deserialization of the messages.</param>
internal TestRequestSender(ICommunicationManager communicationManager, IDataSerializer dataSerializer)
/// <param name="protocolConfig">Protocol related information</param>
internal TestRequestSender(ICommunicationManager communicationManager, IDataSerializer dataSerializer, ProtocolConfig protocolConfig)
{
this.highestNegotiatedVersion = protocolConfig.Version;
this.communicationManager = communicationManager;
this.dataSerializer = dataSerializer;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ public class ProxyDiscoveryManager : ProxyOperationManager, IProxyDiscoveryManag
/// <summary>
/// Initializes a new instance of the <see cref="ProxyDiscoveryManager"/> class.
/// </summary>
/// <param name="testRequestSender">Test request sender instance.</param>
/// <param name="testHostManager">Test host manager instance.</param>
public ProxyDiscoveryManager(ITestRuntimeProvider testHostManager)
: this(new TestRequestSender(), testHostManager, CrossPlatEngine.Constants.ClientConnectionTimeout)
public ProxyDiscoveryManager(TestRequestSender testRequestSender, ITestRuntimeProvider testHostManager)
: this(testRequestSender, testHostManager, CrossPlatEngine.Constants.ClientConnectionTimeout)
{
this.testHostManager = testHostManager;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ internal class ProxyExecutionManager : ProxyOperationManager, IProxyExecutionMan
/// <summary>
/// Initializes a new instance of the <see cref="ProxyExecutionManager"/> class.
/// </summary>
/// <param name="testRequestSender">Test request sender instance.</param>
/// <param name="testHostManager">Test host manager for this proxy.</param>
public ProxyExecutionManager(ITestRuntimeProvider testHostManager) : this(new TestRequestSender(), testHostManager, Constants.ClientConnectionTimeout)
public ProxyExecutionManager(ITestRequestSender requestSender, ITestRuntimeProvider testHostManager) : this(requestSender, testHostManager, Constants.ClientConnectionTimeout)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Host;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;
using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Interfaces;

/// <summary>
/// The proxy execution manager with data collection.
Expand All @@ -24,13 +25,17 @@ internal class ProxyExecutionManagerWithDataCollection : ProxyExecutionManager
/// <summary>
/// Initializes a new instance of the <see cref="ProxyExecutionManagerWithDataCollection"/> class.
/// </summary>
/// <param name="testRequestSender">
/// Test request sender instance.
/// </param>
/// <param name="testHostManager">
/// Test host manager for this operation.
/// </param>
/// <param name="proxyDataCollectionManager">
/// The proxy Data Collection Manager.
/// </param>
public ProxyExecutionManagerWithDataCollection(ITestRuntimeProvider testHostManager, IProxyDataCollectionManager proxyDataCollectionManager) : base(testHostManager)
public ProxyExecutionManagerWithDataCollection(ITestRequestSender requestSender, ITestRuntimeProvider testHostManager, IProxyDataCollectionManager proxyDataCollectionManager)
: base(requestSender, testHostManager)
{
this.ProxyDataCollectionManager = proxyDataCollectionManager;
this.DataCollectionRunEventsHandler = new DataCollectionRunEventsHandler();
Expand Down
15 changes: 10 additions & 5 deletions src/Microsoft.TestPlatform.CrossPlatEngine/TestEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Host;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities;
using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities;

/// <summary>
/// Cross Platform test engine entry point for the client.
Expand Down Expand Up @@ -50,10 +51,11 @@ protected TestEngine(TestRuntimeProviderManager testHostProviderManager)
/// <param name="discoveryCriteria">
/// The discovery Criteria.
/// </param>
/// <param name="protocolConfig">Protocol related information</param>
/// <returns>
/// ITestDiscoveryManager object that can do discovery
/// </returns>
public IProxyDiscoveryManager GetDiscoveryManager(ITestRuntimeProvider testHostManager, DiscoveryCriteria discoveryCriteria)
public IProxyDiscoveryManager GetDiscoveryManager(ITestRuntimeProvider testHostManager, DiscoveryCriteria discoveryCriteria, ProtocolConfig protocolConfig)
{
var parallelLevel = this.VerifyParallelSettingAndCalculateParallelLevel(discoveryCriteria.Sources.Count(), discoveryCriteria.RunSettings);

Expand All @@ -62,7 +64,7 @@ public IProxyDiscoveryManager GetDiscoveryManager(ITestRuntimeProvider testHostM
var hostManager = this.testHostProviderManager.GetTestHostManagerByRunConfiguration(discoveryCriteria.RunSettings);
hostManager?.Initialize(TestSessionMessageLogger.Instance, discoveryCriteria.RunSettings);

return new ProxyDiscoveryManager(hostManager);
return new ProxyDiscoveryManager(new TestRequestSender(protocolConfig), hostManager);
};

return !testHostManager.Shared ? new ParallelProxyDiscoveryManager(proxyDiscoveryManagerCreator, parallelLevel, sharedHosts: testHostManager.Shared) : proxyDiscoveryManagerCreator();
Expand All @@ -73,10 +75,11 @@ public IProxyDiscoveryManager GetDiscoveryManager(ITestRuntimeProvider testHostM
/// </summary>
/// <param name="testHostManager">Test host manager.</param>
/// <param name="testRunCriteria">Test run criterion.</param>
/// <param name="config">Protocol related information</param>
/// <returns>
/// ITestExecutionManager object that can do execution
/// </returns>
public IProxyExecutionManager GetExecutionManager(ITestRuntimeProvider testHostManager, TestRunCriteria testRunCriteria)
public IProxyExecutionManager GetExecutionManager(ITestRuntimeProvider testHostManager, TestRunCriteria testRunCriteria, ProtocolConfig config)
{
var distinctSources = GetDistinctNumberOfSources(testRunCriteria);
var parallelLevel = this.VerifyParallelSettingAndCalculateParallelLevel(distinctSources, testRunCriteria.TestRunSettings);
Expand All @@ -95,8 +98,10 @@ public IProxyExecutionManager GetExecutionManager(ITestRuntimeProvider testHostM
hostManager.SetCustomLauncher(testRunCriteria.TestHostLauncher);
}

return isDataCollectorEnabled ? new ProxyExecutionManagerWithDataCollection(hostManager, new ProxyDataCollectionManager(testRunCriteria.TestRunSettings))
: new ProxyExecutionManager(hostManager);
var requestSender = new TestRequestSender(config);

return isDataCollectorEnabled ? new ProxyExecutionManagerWithDataCollection(requestSender, hostManager, new ProxyDataCollectionManager(testRunCriteria.TestRunSettings))
: new ProxyExecutionManager(requestSender, hostManager);
};

// parallelLevel = 1 for desktop should go via else route.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,16 @@ public interface ITestPlatform : IDisposable
/// Creates a discovery request
/// </summary>
/// <param name="discoveryCriteria">Specifies the discovery parameters</param>
/// <param name="protocolConfig">Protocol related information</param>
/// <returns>DiscoveryRequest object</returns>
IDiscoveryRequest CreateDiscoveryRequest(DiscoveryCriteria discoveryCriteria);
IDiscoveryRequest CreateDiscoveryRequest(DiscoveryCriteria discoveryCriteria, ProtocolConfig protocolConfig);

/// <summary>
/// Creates a test run request.
/// </summary>
/// <param name="testRunCriteria">Specifies the test run criteria</param>
/// <param name="protocolConfig">Protocol related information</param>
/// <returns>RunRequest object</returns>
ITestRunRequest CreateTestRunRequest(TestRunCriteria testRunCriteria);
ITestRunRequest CreateTestRunRequest(TestRunCriteria testRunCriteria, ProtocolConfig protocolConfig);
}
}
Loading