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

Ensure to send a session complete event #4878

Merged
merged 3 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 0 additions & 1 deletion src/Microsoft.TestPlatform.Client/TestPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
drognanar marked this conversation as resolved.
Show resolved Hide resolved
eventsHandler.HandleStartTestSessionComplete(new());
return false;
}

Expand Down
7 changes: 7 additions & 0 deletions src/vstest.console/TestPlatformHelpers/TestRequestManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,10 +494,6 @@ public void StartTestSessionShouldReturnFalseIfTestSessionManagerIsNull()
testSessionCriteria,
mockEventsHandler.Object,
It.IsAny<Dictionary<string, SourceDetail>>(), It.IsAny<IWarningLogger>()));

mockEventsHandler.Verify(
eh => eh.HandleStartTestSessionComplete(It.IsAny<StartTestSessionCompleteEventArgs>()),
Times.Once);
}

[TestMethod]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2317,6 +2317,56 @@ public void StartTestSessionShouldUpdateSettings()
_mockAssemblyMetadataProvider.Verify(a => a.GetFrameworkName(It.IsAny<string>()));
}

[TestMethod]
public void StartTestSessionShouldSendCompletedEventIfTestPlatformReturnsFalse()
{
var payload = new StartTestSessionPayload()
{
Sources = new List<string>() { "a.dll" },
RunSettings =
@"<?xml version=""1.0"" encoding=""utf-8""?>
<RunSettings>
<RunConfiguration>
</RunConfiguration>
</RunSettings>"
};

var eventsHandler = new Mock<ITestSessionEventsHandler>();
_commandLineOptions.IsDesignMode = true;

_mockAssemblyMetadataProvider.Setup(
a => a.GetArchitecture(It.IsAny<string>()))
.Returns(Architecture.ARM);
_mockAssemblyMetadataProvider.Setup(
a => a.GetFrameworkName(It.IsAny<string>()))
.Returns(new FrameworkName(Constants.DotNetFramework46));

_mockTestPlatform.Setup(
tp => tp.StartTestSession(
It.IsAny<IRequestData>(),
It.IsAny<StartTestSessionCriteria>(),
It.IsAny<ITestSessionEventsHandler>(),
It.IsAny<Dictionary<string, SourceDetail>>(),
It.IsAny<IWarningLogger>()))
.Returns(false)
.Callback(
(IRequestData _, StartTestSessionCriteria criteria, ITestSessionEventsHandler _, Dictionary<string, SourceDetail> _, IWarningLogger _) =>
{
Assert.IsTrue(criteria.RunSettings!.Contains(Constants.DotNetFramework46));
Assert.IsTrue(criteria.RunSettings.Contains(nameof(Architecture.ARM)));
});

_testRequestManager.StartTestSession(
payload,
new Mock<ITestHostLauncher3>().Object,
eventsHandler.Object,
_protocolConfig);

eventsHandler.Verify(eh => eh.HandleStartTestSessionComplete(It.IsAny<StartTestSessionCompleteEventArgs>()));
_mockAssemblyMetadataProvider.Verify(a => a.GetArchitecture(It.IsAny<string>()));
_mockAssemblyMetadataProvider.Verify(a => a.GetFrameworkName(It.IsAny<string>()));
}

[TestMethod]
public void StartTestSessionShouldThrowSettingsExceptionWhenFindingIncompatibleDataCollectorsInTestSettings()
{
Expand Down