diff --git a/src/Microsoft.TestPlatform.Client/TestPlatform.cs b/src/Microsoft.TestPlatform.Client/TestPlatform.cs index 4408c94f4e..89c3d9d8bf 100644 --- a/src/Microsoft.TestPlatform.Client/TestPlatform.cs +++ b/src/Microsoft.TestPlatform.Client/TestPlatform.cs @@ -142,7 +142,6 @@ public bool StartTestSession( // sources tells us we should run in-process (i.e. in vstest.console). Because // of this no session will be created because there's no testhost to be launched. // Expecting a subsequent call to execute tests with the same set of parameters. - eventsHandler.HandleStartTestSessionComplete(new()); return false; } diff --git a/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs b/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs index d76f1cfd23..4faf151b05 100644 --- a/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs +++ b/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs @@ -525,6 +525,13 @@ public void StartTestSession( var testSessionStarted = _testPlatform.StartTestSession(requestData, criteria, eventsHandler, sourceToSourceDetailMap, new NullWarningLogger()); if (!testSessionStarted) { + // Note: We need to send back a TestSessionComplete event, so that the caller + // completes a session start request. + // StartTestSession will invoke the HandleStartTestSessionComplete event + // if the test session is started successfully. However, if it is not started, + // HandleStartTestSessionComplete will not send an event. That's why we need + // to do it here. + eventsHandler.HandleStartTestSessionComplete(new()); EqtTrace.Warning("TestRequestManager.StartTestSession: Unable to start test session."); } } diff --git a/test/Microsoft.TestPlatform.Client.UnitTests/TestPlatformTests.cs b/test/Microsoft.TestPlatform.Client.UnitTests/TestPlatformTests.cs index e2ed568353..b2a1cf8b2f 100644 --- a/test/Microsoft.TestPlatform.Client.UnitTests/TestPlatformTests.cs +++ b/test/Microsoft.TestPlatform.Client.UnitTests/TestPlatformTests.cs @@ -494,10 +494,6 @@ public void StartTestSessionShouldReturnFalseIfTestSessionManagerIsNull() testSessionCriteria, mockEventsHandler.Object, It.IsAny>(), It.IsAny())); - - mockEventsHandler.Verify( - eh => eh.HandleStartTestSessionComplete(It.IsAny()), - Times.Once); } [TestMethod] diff --git a/test/vstest.console.UnitTests/TestPlatformHelpers/TestRequestManagerTests.cs b/test/vstest.console.UnitTests/TestPlatformHelpers/TestRequestManagerTests.cs index bf8bb34be3..d8f8f94a8c 100644 --- a/test/vstest.console.UnitTests/TestPlatformHelpers/TestRequestManagerTests.cs +++ b/test/vstest.console.UnitTests/TestPlatformHelpers/TestRequestManagerTests.cs @@ -2317,6 +2317,56 @@ public void StartTestSessionShouldUpdateSettings() _mockAssemblyMetadataProvider.Verify(a => a.GetFrameworkName(It.IsAny())); } + [TestMethod] + public void StartTestSessionShouldSendCompletedEventIfTestPlatformReturnsFalse() + { + var payload = new StartTestSessionPayload() + { + Sources = new List() { "a.dll" }, + RunSettings = + @" + + + + " + }; + + var eventsHandler = new Mock(); + _commandLineOptions.IsDesignMode = true; + + _mockAssemblyMetadataProvider.Setup( + a => a.GetArchitecture(It.IsAny())) + .Returns(Architecture.ARM); + _mockAssemblyMetadataProvider.Setup( + a => a.GetFrameworkName(It.IsAny())) + .Returns(new FrameworkName(Constants.DotNetFramework46)); + + _mockTestPlatform.Setup( + tp => tp.StartTestSession( + It.IsAny(), + It.IsAny(), + It.IsAny(), + It.IsAny>(), + It.IsAny())) + .Returns(false) + .Callback( + (IRequestData _, StartTestSessionCriteria criteria, ITestSessionEventsHandler _, Dictionary _, IWarningLogger _) => + { + Assert.IsTrue(criteria.RunSettings!.Contains(Constants.DotNetFramework46)); + Assert.IsTrue(criteria.RunSettings.Contains(nameof(Architecture.ARM))); + }); + + _testRequestManager.StartTestSession( + payload, + new Mock().Object, + eventsHandler.Object, + _protocolConfig); + + eventsHandler.Verify(eh => eh.HandleStartTestSessionComplete(It.IsAny())); + _mockAssemblyMetadataProvider.Verify(a => a.GetArchitecture(It.IsAny())); + _mockAssemblyMetadataProvider.Verify(a => a.GetFrameworkName(It.IsAny())); + } + [TestMethod] public void StartTestSessionShouldThrowSettingsExceptionWhenFindingIncompatibleDataCollectorsInTestSettings() {