public void DiscoverTestsShouldCallHandleDiscoveryCompleteOnDiscoveryCompletion() { var sources = new List <string>() { "Hello", "World" }; string settingsXml = "SettingsXml"; var mockHandler = new Mock <ITestDiscoveryEventsHandler>(); var discoveryCriteria = new DiscoveryCriteria(sources, 100, settingsXml); var rawMessage = "RunComplete"; var completePayload = new DiscoveryCompletePayload() { IsAborted = false, LastDiscoveredTests = null, TotalTests = 1 }; var message = new Message() { MessageType = MessageType.DiscoveryComplete, Payload = null }; this.SetupReceiveRawMessageAsyncAndDeserializeMessageAndInitialize(rawMessage, message); this.mockDataSerializer.Setup(ds => ds.DeserializePayload <DiscoveryCompletePayload>(message)).Returns(completePayload); this.testRequestSender.DiscoverTests(discoveryCriteria, mockHandler.Object); this.mockCommunicationManager.Verify(mc => mc.SendMessage(MessageType.StartDiscovery, discoveryCriteria, this.protocolConfig.Version), Times.Once); this.mockDataSerializer.Verify(ds => ds.DeserializeMessage(rawMessage), Times.Once); mockHandler.Verify(mh => mh.HandleDiscoveryComplete(1, null, false), Times.Once); mockHandler.Verify(mh => mh.HandleRawMessage(rawMessage), Times.Once); }
private void StartDiscovery(DiscoveryRequestPayload discoveryRequestPayload, ITestRequestManager testRequestManager) { Task.Run( delegate { try { testRequestManager.ResetOptions(); testRequestManager.DiscoverTests(discoveryRequestPayload, new DesignModeTestEventsRegistrar(this), this.protocolConfig); } catch (Exception ex) { EqtTrace.Error("DesignModeClient: Exception in StartDiscovery: " + ex); // If there is an exception during test discovery request creation or some time during the process // In such cases, TestPlatform will never send a DiscoveryComplete event and IDE need to be sent a discovery complete message // We need recoverability in translationlayer-designmode scenarios var testMessagePayload = new TestMessagePayload { MessageLevel = TestMessageLevel.Error, Message = ex.ToString() }; this.communicationManager.SendMessage(MessageType.TestMessage, testMessagePayload); var payload = new DiscoveryCompletePayload() { IsAborted = true, LastDiscoveredTests = null, TotalTests = -1 }; // Send run complete to translation layer this.communicationManager.SendMessage(MessageType.DiscoveryComplete, payload); } }); }
public void DiscoveryManagerShouldPassOnHandleDiscoveredTests() { Mock <ITestDiscoveryEventsHandler2> mockTestDiscoveryEventsHandler = new Mock <ITestDiscoveryEventsHandler2>(); var testCases = new List <TestCase>() { new TestCase("x.y.z", new Uri("x://y"), "x.dll") }; this.testDiscoveryManager = this.GetProxyDiscoveryManager(); this.SetupChannelMessage(MessageType.StartDiscovery, MessageType.TestCasesFound, testCases); var completePayload = new DiscoveryCompletePayload() { IsAborted = false, LastDiscoveredTests = null, TotalTests = 1 }; var completeMessage = new Message() { MessageType = MessageType.DiscoveryComplete, Payload = null }; mockTestDiscoveryEventsHandler.Setup(mh => mh.HandleDiscoveredTests(It.IsAny <IEnumerable <TestCase> >())).Callback( () => { this.mockDataSerializer.Setup(ds => ds.DeserializeMessage(It.IsAny <string>())).Returns(completeMessage); this.mockDataSerializer.Setup(ds => ds.DeserializePayload <DiscoveryCompletePayload>(completeMessage)).Returns(completePayload); }); // Act. this.testDiscoveryManager.DiscoverTests(this.discoveryCriteria, mockTestDiscoveryEventsHandler.Object); // Verify mockTestDiscoveryEventsHandler.Verify(mtdeh => mtdeh.HandleDiscoveredTests(It.IsAny <IEnumerable <TestCase> >()), Times.AtLeastOnce); }
public void DiscoverTestsShouldCollectMetricsOnHandleDiscoveryComplete() { var dict = new Dictionary <string, string>(); dict.Add("DummyMessage", "DummyValue"); var mockHandler = new Mock <ITestDiscoveryEventsHandler2>(); var completePayload = new DiscoveryCompletePayload() { IsAborted = false, LastDiscoveredTests = null, TotalTests = 1, Metrics = dict }; this.SetupDeserializeMessage(MessageType.DiscoveryComplete, completePayload); this.SetupFakeCommunicationChannel(); DiscoveryCompleteEventArgs actualDiscoveryCompleteEventArgs = null; mockHandler.Setup(md => md.HandleDiscoveryComplete(It.IsAny <DiscoveryCompleteEventArgs>(), null)) .Callback <DiscoveryCompleteEventArgs, IEnumerable <TestCase> >( (discoveryCompleteEventArgs, testCase) => { actualDiscoveryCompleteEventArgs = discoveryCompleteEventArgs; }); // Act. this.testRequestSender.DiscoverTests(new DiscoveryCriteria(), mockHandler.Object); this.RaiseMessageReceivedEvent(); // Verify Assert.AreEqual(dict, actualDiscoveryCompleteEventArgs.Metrics); }
private void OnDiscoveryAbort(ITestDiscoveryEventsHandler eventHandler) { // Log to vstest console eventHandler.HandleLogMessage(TestMessageLevel.Error, CommonResources.AbortedTestDiscovery); // Log to vs ide test output var testMessagePayload = new TestMessagePayload { MessageLevel = TestMessageLevel.Error, Message = CommonResources.AbortedTestDiscovery }; var rawMessage = this.dataSerializer.SerializePayload(MessageType.TestMessage, testMessagePayload); eventHandler.HandleRawMessage(rawMessage); // Notify discovery abort to IDE test output var payload = new DiscoveryCompletePayload() { IsAborted = true, LastDiscoveredTests = null, TotalTests = -1 }; rawMessage = this.dataSerializer.SerializePayload(MessageType.DiscoveryComplete, payload); eventHandler.HandleRawMessage(rawMessage); // Complete discovery eventHandler.HandleDiscoveryComplete(-1, null, true); this.CleanupCommunicationIfProcessExit(); }
private void OnDiscoveryAbort(ITestDiscoveryEventsHandler2 eventHandler, Exception exception, bool getClientError) { if (this.IsOperationComplete()) { EqtTrace.Verbose("TestRequestSender: OnDiscoveryAbort: Operation is already complete. Skip error message."); return; } EqtTrace.Verbose("TestRequestSender: OnDiscoveryAbort: Set operation complete."); this.SetOperationComplete(); var discoveryCompleteEventArgs = new DiscoveryCompleteEventArgs(-1, true); var reason = this.GetAbortErrorMessage(exception, getClientError); EqtTrace.Error("TestRequestSender: Aborting test discovery because {0}", reason); this.LogErrorMessage(string.Format(CommonResources.AbortedTestDiscovery, reason)); // Notify discovery abort to IDE test output var payload = new DiscoveryCompletePayload() { IsAborted = true, LastDiscoveredTests = null, TotalTests = -1 }; var rawMessage = this.dataSerializer.SerializePayload(MessageType.DiscoveryComplete, payload); eventHandler.HandleRawMessage(rawMessage); // Complete discovery eventHandler.HandleDiscoveryComplete(discoveryCompleteEventArgs, null); }
private void OnDiscoveryAbort(ITestDiscoveryEventsHandler eventHandler, Exception exception) { EqtTrace.Error("Server: TestExecution: Aborting test discovery because {0}", exception); var reason = string.Format(CommonResources.AbortedTestDiscovery, exception?.Message); // Log to vstest console eventHandler.HandleLogMessage(TestMessageLevel.Error, reason); // Log to vs ide test output var testMessagePayload = new TestMessagePayload { MessageLevel = TestMessageLevel.Error, Message = reason }; var rawMessage = this.dataSerializer.SerializePayload(MessageType.TestMessage, testMessagePayload); eventHandler.HandleRawMessage(rawMessage); // Notify discovery abort to IDE test output var payload = new DiscoveryCompletePayload() { IsAborted = true, LastDiscoveredTests = null, TotalTests = -1 }; rawMessage = this.dataSerializer.SerializePayload(MessageType.DiscoveryComplete, payload); eventHandler.HandleRawMessage(rawMessage); // Complete discovery eventHandler.HandleDiscoveryComplete(-1, null, true); this.CleanupCommunicationIfProcessExit(); }
private void StartDiscovery(DiscoveryRequestPayload discoveryRequestPayload, ITestRequestManager testRequestManager) { Task.Run( delegate { try { testRequestManager.ResetOptions(); testRequestManager.DiscoverTests(discoveryRequestPayload, new DesignModeTestEventsRegistrar(this), this.protocolConfig); } catch (Exception ex) { EqtTrace.Error("DesignModeClient: Exception in StartDiscovery: " + ex); var testMessagePayload = new TestMessagePayload { MessageLevel = TestMessageLevel.Error, Message = ex.ToString() }; this.communicationManager.SendMessage(MessageType.TestMessage, testMessagePayload); var payload = new DiscoveryCompletePayload() { IsAborted = true, LastDiscoveredTests = null, TotalTests = -1 }; // Send run complete to translation layer this.communicationManager.SendMessage(MessageType.DiscoveryComplete, payload); } }); }
/// <inheritdoc/> public void HandleDiscoveryComplete(DiscoveryCompleteEventArgs discoveryCompleteEventArgs, IEnumerable <TestCase> lastChunk) { var totalTests = discoveryCompleteEventArgs.TotalCount; var isAborted = discoveryCompleteEventArgs.IsAborted; // we get discovery complete events from each host process // so we cannot "complete" the actual operation until all sources are consumed // We should not block last chunk results while we aggregate overall discovery data if (lastChunk != null) { ConvertToRawMessageAndSend(MessageType.TestCasesFound, lastChunk); this.HandleDiscoveredTests(lastChunk); } // Aggregate for final discovery complete discoveryDataAggregator.Aggregate(totalTests, isAborted); // Aggregate Discovery Data Metrics discoveryDataAggregator.AggregateDiscoveryDataMetrics(discoveryCompleteEventArgs.Metrics); // Do not send TestDiscoveryComplete to actual test discovery handler // We need to see if there are still sources left - let the parallel manager decide var parallelDiscoveryComplete = this.parallelProxyDiscoveryManager.HandlePartialDiscoveryComplete( this.proxyDiscoveryManager, totalTests, null, // lastChunk should be null as we already sent this data above isAborted); if (parallelDiscoveryComplete) { // In case of sequential discovery - RawMessage would have contained a 'DiscoveryCompletePayload' object // To send a raw message - we need to create raw message from an aggregated payload object var testDiscoveryCompletePayload = new DiscoveryCompletePayload() { TotalTests = discoveryDataAggregator.TotalTests, IsAborted = discoveryDataAggregator.IsAborted, LastDiscoveredTests = null }; // Collecting Final Discovery State this.requestData.MetricsCollection.Add(TelemetryDataConstants.DiscoveryState, isAborted ? "Aborted" : "Completed"); // Collect Aggregated Metrics Data var aggregatedDiscoveryDataMetrics = discoveryDataAggregator.GetAggregatedDiscoveryDataMetrics(); testDiscoveryCompletePayload.Metrics = aggregatedDiscoveryDataMetrics; // we have to send raw messages as we block the discovery complete actual raw messages this.ConvertToRawMessageAndSend(MessageType.DiscoveryComplete, testDiscoveryCompletePayload); var finalDiscoveryCompleteEventArgs = new DiscoveryCompleteEventArgs(this.discoveryDataAggregator.TotalTests, this.discoveryDataAggregator.IsAborted); finalDiscoveryCompleteEventArgs.Metrics = aggregatedDiscoveryDataMetrics; // send actual test discovery complete to clients this.actualDiscoveryEventsHandler.HandleDiscoveryComplete(finalDiscoveryCompleteEventArgs, null); } }
/// <inheritdoc/> public void DiscoveryComplete(long totalTests, IEnumerable <TestCase> lastChunk, bool isAborted) { var discoveryCompletePayload = new DiscoveryCompletePayload { TotalTests = totalTests, LastDiscoveredTests = isAborted ? null : lastChunk, IsAborted = isAborted }; this.communicationManager.SendMessage(MessageType.DiscoveryComplete, discoveryCompletePayload, this.protocolVersion); }
/// <inheritdoc/> public void DiscoveryComplete(DiscoveryCompleteEventArgs discoveryCompleteEventArgs, IEnumerable <TestCase> lastChunk) { var discoveryCompletePayload = new DiscoveryCompletePayload { TotalTests = discoveryCompleteEventArgs.TotalCount, LastDiscoveredTests = discoveryCompleteEventArgs.IsAborted ? null : lastChunk, IsAborted = discoveryCompleteEventArgs.IsAborted, Metrics = discoveryCompleteEventArgs.Metrics }; this.communicationManager.SendMessage(MessageType.DiscoveryComplete, discoveryCompletePayload, this.protocolVersion); }
public void DiscoveryCompleteShouldSendDiscoveryCompletePayloadOnChannel() { var discoveryComplete = new DiscoveryCompletePayload { TotalTests = 1, LastDiscoveredTests = Enumerable.Empty<TestCase>(), IsAborted = false }; var message = this.dataSerializer.SerializePayload(MessageType.DiscoveryComplete, discoveryComplete); this.SetupChannel(); this.ProcessRequestsAsync(this.mockTestHostManagerFactory.Object); this.requestHandler.DiscoveryComplete(new DiscoveryCompleteEventArgs(discoveryComplete.TotalTests, discoveryComplete.IsAborted), discoveryComplete.LastDiscoveredTests); this.VerifyResponseMessageEquals(message); this.SendSessionEnd(); }
public void DiscoverTestsShouldNotifyDiscoveryCompleteOnCompleteMessageReceived() { var completePayload = new DiscoveryCompletePayload { TotalTests = 10, IsAborted = false }; this.SetupDeserializeMessage(MessageType.DiscoveryComplete, completePayload); this.SetupFakeCommunicationChannel(); this.testRequestSender.DiscoverTests(new DiscoveryCriteria(), this.mockDiscoveryEventsHandler.Object); this.RaiseMessageReceivedEvent(); this.mockDiscoveryEventsHandler.Verify(eh => eh.HandleDiscoveryComplete(It.IsAny <DiscoveryCompleteEventArgs>(), null)); }
public void DiscoverTestsShouldCallHandleLogMessageOnTestMessage() { var sources = new List <string>() { "Hello", "World" }; string settingsXml = "SettingsXml"; var mockHandler = new Mock <ITestDiscoveryEventsHandler>(); var discoveryCriteria = new DiscoveryCriteria(sources, 100, settingsXml); var rawMessage = "TestMessage"; var messagePayload = new TestMessagePayload() { MessageLevel = TestMessageLevel.Error, Message = rawMessage }; var message = new Message() { MessageType = MessageType.TestMessage, Payload = null }; this.SetupReceiveRawMessageAsyncAndDeserializeMessageAndInitialize(rawMessage, message); this.mockDataSerializer.Setup(ds => ds.DeserializePayload <TestMessagePayload>(message)).Returns(messagePayload); var completePayload = new DiscoveryCompletePayload() { IsAborted = false, LastDiscoveredTests = null, TotalTests = 1 }; var completeMessage = new Message() { MessageType = MessageType.DiscoveryComplete, Payload = null }; mockHandler.Setup(mh => mh.HandleLogMessage(TestMessageLevel.Error, rawMessage)).Callback( () => { this.mockDataSerializer.Setup(ds => ds.DeserializeMessage(It.IsAny <string>())).Returns(completeMessage); this.mockDataSerializer.Setup(ds => ds.DeserializePayload <DiscoveryCompletePayload>(completeMessage)).Returns(completePayload); }); this.testRequestSender.DiscoverTests(discoveryCriteria, mockHandler.Object); this.mockCommunicationManager.Verify(mc => mc.SendMessage(MessageType.StartDiscovery, discoveryCriteria), Times.Once); this.mockDataSerializer.Verify(ds => ds.DeserializeMessage(rawMessage), Times.Exactly(2)); mockHandler.Verify(mh => mh.HandleLogMessage(TestMessageLevel.Error, rawMessage), Times.Once); mockHandler.Verify(mh => mh.HandleRawMessage(rawMessage), Times.Exactly(2)); }
public void DiscoverTestsShouldStopServerOnCompleteMessageReceived() { var completePayload = new DiscoveryCompletePayload { TotalTests = 10, IsAborted = false }; this.SetupDeserializeMessage(MessageType.DiscoveryComplete, completePayload); this.SetupFakeCommunicationChannel(); this.testRequestSender.DiscoverTests(new DiscoveryCriteria(), this.mockDiscoveryEventsHandler.Object); this.RaiseMessageReceivedEvent(); this.mockServer.Verify(ms => ms.Stop()); }
public void DiscoverTestsShouldCallHandleDiscoveredTestsOnTestCaseEvent() { var sources = new List <string>() { "Hello", "World" }; string settingsXml = "SettingsXml"; var mockHandler = new Mock <ITestDiscoveryEventsHandler>(); var discoveryCriteria = new DiscoveryCriteria(sources, 100, settingsXml); var testCases = new List <TestCase>() { new TestCase("x.y.z", new Uri("x://y"), "x.dll") }; var rawMessage = "OnDiscoveredTests"; var message = new Message() { MessageType = MessageType.TestCasesFound, Payload = null }; this.SetupReceiveRawMessageAsyncAndDeserializeMessageAndInitialize(rawMessage, message); this.mockDataSerializer.Setup(ds => ds.DeserializePayload <IEnumerable <TestCase> >(message)).Returns(testCases); var completePayload = new DiscoveryCompletePayload() { IsAborted = false, LastDiscoveredTests = null, TotalTests = 1 }; var completeMessage = new Message() { MessageType = MessageType.DiscoveryComplete, Payload = null }; mockHandler.Setup(mh => mh.HandleDiscoveredTests(testCases)).Callback( () => { this.mockDataSerializer.Setup(ds => ds.DeserializeMessage(It.IsAny <string>())).Returns(completeMessage); this.mockDataSerializer.Setup(ds => ds.DeserializePayload <DiscoveryCompletePayload>(completeMessage)).Returns(completePayload); }); this.testRequestSender.DiscoverTests(discoveryCriteria, mockHandler.Object); this.mockCommunicationManager.Verify(mc => mc.SendMessage(MessageType.StartDiscovery, discoveryCriteria, this.protocolConfig.Version), Times.Once); this.mockDataSerializer.Verify(ds => ds.DeserializeMessage(rawMessage), Times.Exactly(2)); mockHandler.Verify(mh => mh.HandleDiscoveredTests(testCases), Times.Once); mockHandler.Verify(mh => mh.HandleRawMessage(rawMessage), Times.Exactly(2)); }
public void DiscoverTestsShouldNotAbortDiscoveryIfClientDisconnectedAndOperationIsComplete() { var completePayload = new DiscoveryCompletePayload { TotalTests = 10, IsAborted = false }; this.SetupDeserializeMessage(MessageType.DiscoveryComplete, completePayload); this.SetupFakeCommunicationChannel(); this.testRequestSender.DiscoverTests(new DiscoveryCriteria(), this.mockDiscoveryEventsHandler.Object); this.RaiseMessageReceivedEvent(); // Raise discovery complete this.RaiseClientDisconnectedEvent(); this.mockDiscoveryEventsHandler.Verify(eh => eh.HandleLogMessage(TestMessageLevel.Error, It.IsAny <string>()), Times.Never); this.mockDiscoveryEventsHandler.Verify(eh => eh.HandleDiscoveryComplete(It.IsAny <DiscoveryCompleteEventArgs>(), null), Times.Once); }
/// <summary> /// Handles LoggerManager's DiscoveryComplete. /// </summary> /// <param name="discoveryCompletePayload">Discovery complete payload.</param> private void HandleLoggerManagerDiscoveryComplete(DiscoveryCompletePayload discoveryCompletePayload) { if (this.LoggerManager.LoggersInitialized && discoveryCompletePayload != null) { // Send last chunk to logger manager. if (discoveryCompletePayload.LastDiscoveredTests != null) { var discoveredTestsEventArgs = new DiscoveredTestsEventArgs(discoveryCompletePayload.LastDiscoveredTests); this.LoggerManager.HandleDiscoveredTests(discoveredTestsEventArgs); } // Send discovery complete to logger manager. var discoveryCompleteEventArgs = new DiscoveryCompleteEventArgs(discoveryCompletePayload.TotalTests, discoveryCompletePayload.IsAborted); discoveryCompleteEventArgs.Metrics = discoveryCompletePayload.Metrics; this.LoggerManager.HandleDiscoveryComplete(discoveryCompleteEventArgs); } }
/// <summary> /// Update raw message with telemetry info. /// </summary> /// <param name="discoveryCompletePayload">Discovery complete payload.</param> /// <param name="message">Message.</param> /// <returns>Updated rawMessage.</returns> private string UpdateRawMessageWithTelemetryInfo(DiscoveryCompletePayload discoveryCompletePayload, Message message) { var rawMessage = default(string); if (this.requestData.IsTelemetryOptedIn) { if (discoveryCompletePayload != null) { if (discoveryCompletePayload.Metrics == null) { discoveryCompletePayload.Metrics = this.requestData.MetricsCollection.Metrics; } else { foreach (var kvp in this.requestData.MetricsCollection.Metrics) { discoveryCompletePayload.Metrics[kvp.Key] = kvp.Value; } } var discoveryFinalTimeTakenForDesignMode = DateTime.UtcNow - this.discoveryStartTime; // Collecting Total Time Taken discoveryCompletePayload.Metrics[TelemetryDataConstants.TimeTakenInSecForDiscovery] = discoveryFinalTimeTakenForDesignMode.TotalSeconds; } if (message is VersionedMessage message1) { var version = message1.Version; rawMessage = this.dataSerializer.SerializePayload( MessageType.DiscoveryComplete, discoveryCompletePayload, version); } else { rawMessage = this.dataSerializer.SerializePayload( MessageType.DiscoveryComplete, discoveryCompletePayload); } } return(rawMessage); }
/// <summary> /// Discovers tests /// </summary> /// <param name="discoveryCriteria">Settings, parameters for the discovery request</param> /// <param name="eventHandler">EventHandler for handling discovery events from Engine</param> public void DiscoverTests(DiscoveryCriteria discoveryCriteria, ITestDiscoveryEventsHandler2 eventHandler) { this.baseTestDiscoveryEventsHandler = eventHandler; try { this.isCommunicationEstablished = this.SetupChannel(discoveryCriteria.Sources, discoveryCriteria.RunSettings); if (this.isCommunicationEstablished) { this.InitializeExtensions(discoveryCriteria.Sources); discoveryCriteria.UpdateDiscoveryCriteria(testHostManager); this.RequestSender.DiscoverTests(discoveryCriteria, this); } } catch (Exception exception) { EqtTrace.Error("ProxyDiscoveryManager.DiscoverTests: Failed to discover tests: {0}", exception); // Log to vs ide test output var testMessagePayload = new TestMessagePayload { MessageLevel = TestMessageLevel.Error, Message = exception.ToString() }; var rawMessage = this.dataSerializer.SerializePayload(MessageType.TestMessage, testMessagePayload); this.HandleRawMessage(rawMessage); // Log to vstest.console // Send a discovery complete to caller. Similar logic is also used in ParallelProxyDiscoveryManager.DiscoverTestsOnConcurrentManager // Aborted is `true`: in case of parallel discovery (or non shared host), an aborted message ensures another discovery manager // created to replace the current one. This will help if the current discovery manager is aborted due to irreparable error // and the test host is lost as well. this.HandleLogMessage(TestMessageLevel.Error, exception.ToString()); var discoveryCompletePayload = new DiscoveryCompletePayload() { IsAborted = true, LastDiscoveredTests = null, TotalTests = -1 }; this.HandleRawMessage(this.dataSerializer.SerializePayload(MessageType.DiscoveryComplete, discoveryCompletePayload)); var discoveryCompleteEventsArgs = new DiscoveryCompleteEventArgs(-1, true); this.HandleDiscoveryComplete(discoveryCompleteEventsArgs, new List <ObjectModel.TestCase>()); } }
public void DiscoveryManagerShouldPassOnHandleDiscoveredTests() { Mock <ITestDiscoveryEventsHandler2> mockTestDiscoveryEventsHandler = new Mock <ITestDiscoveryEventsHandler2>(); this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny <int>())).Returns(true); var testCases = new List <TestCase>() { new TestCase("x.y.z", new Uri("x://y"), "x.dll") }; var rawMessage = "OnDiscoveredTests"; var message = new Message() { MessageType = MessageType.TestCasesFound, Payload = null }; this.SetupReceiveRawMessageAsyncAndDeserializeMessageAndInitialize(rawMessage, message); var completePayload = new DiscoveryCompletePayload() { IsAborted = false, LastDiscoveredTests = null, TotalTests = 1 }; var completeMessage = new Message() { MessageType = MessageType.DiscoveryComplete, Payload = null }; mockTestDiscoveryEventsHandler.Setup(mh => mh.HandleDiscoveredTests(It.IsAny <IEnumerable <TestCase> >())).Callback( () => { this.mockDataSerializer.Setup(ds => ds.DeserializeMessage(It.IsAny <string>())).Returns(completeMessage); this.mockDataSerializer.Setup(ds => ds.DeserializePayload <DiscoveryCompletePayload>(completeMessage)).Returns(completePayload); }); // Act. this.testDiscoveryManager.DiscoverTests(this.discoveryCriteria, mockTestDiscoveryEventsHandler.Object); // Verify mockTestDiscoveryEventsHandler.Verify(mtdeh => mtdeh.HandleDiscoveredTests(It.IsAny <IEnumerable <TestCase> >()), Times.AtLeastOnce); }
/// <inheritdoc/> public void HandleDiscoveryComplete(long totalTests, IEnumerable <TestCase> lastChunk, bool isAborted) { // we get discovery complete events from each host process // so we cannot "complete" the actual operation until all sources are consumed // We should not block last chunk results while we aggregate overall discovery data if (lastChunk != null) { ConvertToRawMessageAndSend(MessageType.TestCasesFound, lastChunk); this.HandleDiscoveredTests(lastChunk); } // Aggregate for final discoverycomplete discoveryDataAggregator.Aggregate(totalTests, isAborted); // Do not send TestDiscoveryComplete to actual test discovery handler // We need to see if there are still sources left - let the parallel manager decide var parallelDiscoveryComplete = this.parallelProxyDiscoveryManager.HandlePartialDiscoveryComplete( this.proxyDiscoveryManager, totalTests, null, // lastChunk should be null as we already sent this data above isAborted); if (parallelDiscoveryComplete) { // In case of sequential discovery - RawMessage would have contained a 'DiscoveryCompletePayload' object // To send a raw message - we need to create raw message from an aggregated payload object var testDiscoveryCompletePayload = new DiscoveryCompletePayload() { TotalTests = discoveryDataAggregator.TotalTests, IsAborted = discoveryDataAggregator.IsAborted, LastDiscoveredTests = null }; // we have to send raw messages as we block the discoverycomplete actual raw messages this.ConvertToRawMessageAndSend(MessageType.DiscoveryComplete, testDiscoveryCompletePayload); // send actual test discoverycomplete to clients this.actualDiscoveryEventsHandler.HandleDiscoveryComplete(discoveryDataAggregator.TotalTests, null, discoveryDataAggregator.IsAborted); } }
public void DiscoverTestsShouldCollectMetricsOnHandleDiscoveryComplete() { var dict = new Dictionary <string, object>(); dict.Add("DummyMessage", "DummyValue"); var mockHandler = new Mock <ITestDiscoveryEventsHandler2>(); var rawMessage = "RunComplete"; var completePayload = new DiscoveryCompletePayload() { IsAborted = false, LastDiscoveredTests = null, TotalTests = 1, Metrics = dict }; var message = new Message() { MessageType = MessageType.DiscoveryComplete, Payload = null }; this.SetupReceiveRawMessageAsyncAndDeserializeMessageAndInitialize(rawMessage, message); this.mockDataSerializer.Setup(ds => ds.DeserializePayload <DiscoveryCompletePayload>(message)).Returns(completePayload); DiscoveryCompleteEventArgs actualDiscoveryCompleteEventArgs = null; mockHandler.Setup(md => md.HandleDiscoveryComplete(It.IsAny <DiscoveryCompleteEventArgs>(), null)) .Callback <DiscoveryCompleteEventArgs, IEnumerable <TestCase> >( (discoveryCompleteEventArgs, testCase) => { actualDiscoveryCompleteEventArgs = discoveryCompleteEventArgs; }); // Act. this.testRequestSender.DiscoverTests(new DiscoveryCriteria(), mockHandler.Object); // Verify Assert.AreEqual(actualDiscoveryCompleteEventArgs.Metrics, dict); }