forked from microsoft/testfx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathServerModeTests.cs
92 lines (73 loc) · 4.8 KB
/
ServerModeTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using Microsoft.Testing.Platform.Acceptance.IntegrationTests;
using Microsoft.Testing.Platform.ServerMode.IntegrationTests.Messages.V100;
using MSTest.Acceptance.IntegrationTests.Messages.V100;
namespace MSTest.Acceptance.IntegrationTests;
[TestGroup]
public sealed class ServerModeTests : ServerModeTestsBase
{
private readonly TestAssetFixture _fixture;
public ServerModeTests(ITestExecutionContext testExecutionContext, TestAssetFixture fixture)
: base(testExecutionContext) => _fixture = fixture;
[ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))]
public async Task DiscoverAndRun(string tfm)
{
using TestingPlatformClient jsonClient = await StartAsServerAndConnectToTheClientAsync(TestHost.LocateFrom(_fixture.ProjectPath, "MSTestProject", tfm, buildConfiguration: BuildConfiguration.Release));
LogsCollector logs = new();
jsonClient.RegisterLogListener(logs);
TelemetryCollector telemetry = new();
jsonClient.RegisterTelemetryListener(telemetry);
InitializeResponse initializeResponseArgs = await jsonClient.Initialize();
Assert.IsTrue(initializeResponseArgs.Capabilities.Testing.VSTestProvider);
Assert.IsFalse(initializeResponseArgs.Capabilities.Testing.MultiRequestSupport);
Assert.IsTrue(initializeResponseArgs.Capabilities.Testing.SupportsDiscovery);
TestNodeUpdateCollector discoveryCollector = new();
ResponseListener discoveryListener = await jsonClient.DiscoverTests(Guid.NewGuid(), discoveryCollector.CollectNodeUpdates);
TestNodeUpdateCollector runCollector = new();
ResponseListener runListener = await jsonClient.RunTests(Guid.NewGuid(), runCollector.CollectNodeUpdates);
await Task.WhenAll(discoveryListener.WaitCompletion(), runListener.WaitCompletion());
Assert.AreEqual(1, discoveryCollector.TestNodeUpdates.Count(x => x.Node.NodeType == "action"), $"Wrong number of discovery");
Assert.AreEqual(2, runCollector.TestNodeUpdates.Count, $"Wrong number of updates");
Assert.IsTrue(logs.IsEmpty, $"Logs are not empty");
Assert.IsFalse(telemetry.IsEmpty, $"telemetry is empty");
await jsonClient.Exit();
Assert.AreEqual(0, await jsonClient.WaitServerProcessExit());
Assert.AreEqual(0, jsonClient.ExitCode);
}
[ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))]
public async Task WhenClientDies_Server_ShouldClose_Gracefully(string tfm)
{
using TestingPlatformClient jsonClient = await StartAsServerAndConnectToTheClientAsync(TestHost.LocateFrom(_fixture.ProjectPath, "MSTestProject", tfm, buildConfiguration: BuildConfiguration.Release));
LogsCollector logs = new();
jsonClient.RegisterLogListener(logs);
TelemetryCollector telemetry = new();
jsonClient.RegisterTelemetryListener(telemetry);
InitializeResponse initializeResponseArgs = await jsonClient.Initialize();
Assert.IsFalse(initializeResponseArgs.Capabilities.Testing.MultiRequestSupport);
TestNodeUpdateCollector discoveryCollector = new();
// We're not interested we want to start some activity at adapter level
// We know that it's possible that we're fast enough to not start the discovery at all in all cases.
_ = jsonClient.DiscoverTests(Guid.NewGuid(), discoveryCollector.CollectNodeUpdates, @checked: false);
await jsonClient.Exit(gracefully: false);
int exitCode = await jsonClient.WaitServerProcessExit();
Assert.AreEqual(3, exitCode);
}
[TestFixture(TestFixtureSharingStrategy.PerTestGroup)]
public sealed class TestAssetFixture(AcceptanceFixture acceptanceFixture) : TestAssetFixtureBase(acceptanceFixture.NuGetGlobalPackagesFolder)
{
public const string ProjectName = "MSTestProject";
public string ProjectPath => GetAssetPath(ProjectName);
public override IEnumerable<(string ID, string Name, string Code)> GetAssetsToGenerate()
{
yield return (ProjectName, ProjectName,
CurrentMSTestSourceCode
.PatchCodeWithReplace("$TargetFramework$", $"<TargetFrameworks>{TargetFrameworks.All.ToMSBuildTargetFrameworks()}</TargetFrameworks>")
.PatchCodeWithReplace("$MicrosoftNETTestSdkVersion$", MicrosoftNETTestSdkVersion)
.PatchCodeWithReplace("$MSTestVersion$", MSTestVersion)
.PatchCodeWithReplace("$EnableMSTestRunner$", "<EnableMSTestRunner>true</EnableMSTestRunner>")
.PatchCodeWithReplace("$OutputType$", "<OutputType>Exe</OutputType>")
.PatchCodeWithReplace("$Extra$", string.Empty));
}
}
}