Skip to content

Commit 0b041f3

Browse files
Honor request.Complete() (#2448) (#2450)
1 parent 49be887 commit 0b041f3

File tree

5 files changed

+111
-3
lines changed

5 files changed

+111
-3
lines changed

src/Platform/Microsoft.Testing.Platform/Requests/TestHostTestFrameworkInvoker.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public async Task ExecuteAsync(ITestFramework testFrameworkAdapter, ClientInfo c
6969

7070
public virtual async Task ExecuteRequestAsync(ITestFramework testFrameworkAdapter, TestExecutionRequest request, IMessageBus messageBus, CancellationToken cancellationToken)
7171
{
72-
using SemaphoreSlim requestSemaphore = new(1);
72+
using SemaphoreSlim requestSemaphore = new(0, 1);
7373
await testFrameworkAdapter.ExecuteRequestAsync(new(request, messageBus, requestSemaphore, cancellationToken));
7474
await requestSemaphore.WaitAsync(cancellationToken);
7575
}

test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/ExecutionTests.cs

+96
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4+
using System.Diagnostics;
5+
46
using Microsoft.Testing.Platform.Acceptance.IntegrationTests.Helpers;
57
using Microsoft.Testing.Platform.Helpers;
68

@@ -10,6 +12,8 @@ namespace Microsoft.Testing.Platform.Acceptance.IntegrationTests;
1012
public class ExecutionTests : AcceptanceTestBase
1113
{
1214
private const string AssetName = "ExecutionTests";
15+
private const string AssetName2 = "ExecutionTests2";
16+
1317
private readonly TestAssetFixture _testAssetFixture;
1418

1519
public ExecutionTests(ITestExecutionContext testExecutionContext, TestAssetFixture testAssetFixture)
@@ -121,6 +125,17 @@ public async Task Exec_WhenListTestsAndMinimumExpectedTestsAreSpecified_Discover
121125
Assert.That(testHostResult.StandardOutput.Contains(OutputPattern), $"Output of the test host is:\n{testHostResult}");
122126
}
123127

128+
[ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))]
129+
public async Task Exec_Honor_Request_Complete(string tfm)
130+
{
131+
TestInfrastructure.TestHost testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath2, AssetName2, tfm);
132+
Stopwatch stopwatch = Stopwatch.StartNew();
133+
TestHostResult testHostResult = await testHost.ExecuteAsync();
134+
stopwatch.Stop();
135+
Assert.AreEqual(ExitCodes.Success, testHostResult.ExitCode);
136+
Assert.IsTrue(stopwatch.Elapsed.TotalSeconds > 3);
137+
}
138+
124139
[TestFixture(TestFixtureSharingStrategy.PerTestGroup)]
125140
public sealed class TestAssetFixture(AcceptanceFixture acceptanceFixture) : TestAssetFixtureBase(acceptanceFixture.NuGetGlobalPackagesFolder)
126141
{
@@ -180,17 +195,98 @@ public void FilteredOutTest()
180195
global using Microsoft.Testing.Platform.Builder;
181196
global using Microsoft.Testing.Framework;
182197
global using Microsoft.Testing.Extensions;
198+
""";
199+
200+
private const string TestCode2 = """
201+
#file ExecutionTests2.csproj
202+
<Project Sdk="Microsoft.NET.Sdk">
203+
<PropertyGroup>
204+
<TargetFrameworks>$TargetFrameworks$</TargetFrameworks>
205+
<ImplicitUsings>enable</ImplicitUsings>
206+
<Nullable>enable</Nullable>
207+
<OutputType>Exe</OutputType>
208+
<UseAppHost>true</UseAppHost>
209+
<LangVersion>preview</LangVersion>
210+
</PropertyGroup>
211+
<ItemGroup>
212+
<PackageReference Include="Microsoft.Testing.Platform" Version="$MicrosoftTestingPlatformVersion$" />
213+
</ItemGroup>
214+
</Project>
215+
216+
#file Program.cs
217+
using Microsoft.Testing.Platform;
218+
using Microsoft.Testing.Platform.Extensions;
219+
using Microsoft.Testing.Platform.Builder;
220+
using Microsoft.Testing.Platform.Capabilities;
221+
using Microsoft.Testing.Platform.Capabilities.TestFramework;
222+
using Microsoft.Testing.Platform.Extensions.Messages;
223+
using Microsoft.Testing.Platform.Extensions.TestFramework;
224+
using System.Threading.Tasks;
225+
226+
ITestApplicationBuilder builder = await TestApplication.CreateBuilderAsync(args);
227+
builder.RegisterTestFramework(_ => new Capabilities(), (_, __) => new DummyAdapter());
228+
using ITestApplication app = await builder.BuildAsync();
229+
return await app.RunAsync();
230+
231+
internal class DummyAdapter : ITestFramework, IDataProducer
232+
{
233+
public string Uid => nameof(DummyAdapter);
234+
235+
public string Version => string.Empty;
236+
237+
public string DisplayName => string.Empty;
238+
239+
public string Description => string.Empty;
240+
241+
public Type[] DataTypesProduced => new[] { typeof(TestNodeUpdateMessage) };
242+
243+
public Task<CloseTestSessionResult> CloseTestSessionAsync(CloseTestSessionContext context) => Task.FromResult(new CloseTestSessionResult() { IsSuccess = true });
244+
245+
public Task<CreateTestSessionResult> CreateTestSessionAsync(CreateTestSessionContext context) => Task.FromResult(new CreateTestSessionResult() { IsSuccess = true });
246+
247+
public Task ExecuteRequestAsync(ExecuteRequestContext context)
248+
{
249+
Task.Run(async() =>
250+
{
251+
await context.MessageBus.PublishAsync(this, new TestNodeUpdateMessage(
252+
context.Request.Session.SessionUid,
253+
new TestNode() { Uid = "0", DisplayName = "Test", Properties = new(PassedTestNodeStateProperty.CachedInstance) }));
254+
255+
Thread.Sleep(3_000);
256+
257+
context.Complete();
258+
});
259+
260+
return Task.CompletedTask;
261+
}
262+
263+
public Task<bool> IsEnabledAsync() => Task.FromResult(true);
264+
}
265+
266+
internal class Capabilities : ITestFrameworkCapabilities
267+
{
268+
IReadOnlyCollection<ITestFrameworkCapability> ICapabilities<ITestFrameworkCapability>.Capabilities => Array.Empty<ITestFrameworkCapability>();
269+
}
270+
183271
""";
184272

185273
public string TargetAssetPath => GetAssetPath(AssetName);
186274

275+
public string TargetAssetPath2 => GetAssetPath(AssetName2);
276+
187277
public override IEnumerable<(string ID, string Name, string Code)> GetAssetsToGenerate()
188278
{
189279
yield return (AssetName, AssetName,
190280
TestCode
191281
.PatchTargetFrameworks(TargetFrameworks.All)
192282
.PatchCodeWithReplace("$MicrosoftTestingPlatformVersion$", MicrosoftTestingPlatformVersion)
193283
.PatchCodeWithReplace("$MicrosoftTestingPlatformExtensionsVersion$", MicrosoftTestingPlatformExtensionsVersion));
284+
285+
yield return (AssetName2, AssetName2,
286+
TestCode2
287+
.PatchTargetFrameworks(TargetFrameworks.All)
288+
.PatchCodeWithReplace("$MicrosoftTestingPlatformVersion$", MicrosoftTestingPlatformVersion)
289+
.PatchCodeWithReplace("$MicrosoftTestingPlatformExtensionsVersion$", MicrosoftTestingPlatformExtensionsVersion));
194290
}
195291
}
196292
}

test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/NoBannerTests.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,11 @@ public Task<CreateTestSessionResult> CreateTestSessionAsync(CreateTestSessionCon
126126
=> Task.FromResult(new CreateTestSessionResult() { IsSuccess = true });
127127
public Task<CloseTestSessionResult> CloseTestSessionAsync(CloseTestSessionContext context)
128128
=> Task.FromResult(new CloseTestSessionResult() { IsSuccess = true });
129-
public Task ExecuteRequestAsync(ExecuteRequestContext context) => Task.CompletedTask;
129+
public Task ExecuteRequestAsync(ExecuteRequestContext context)
130+
{
131+
context.Complete();
132+
return Task.CompletedTask;
133+
}
130134
}
131135
""";
132136

test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/TelemetryTests.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,11 @@ public class DummyTestAdapter : ITestFramework
202202
203203
public Task<CreateTestSessionResult> CreateTestSessionAsync(CreateTestSessionContext context) => Task.FromResult(new CreateTestSessionResult() { IsSuccess = true });
204204
public Task<CloseTestSessionResult> CloseTestSessionAsync(CloseTestSessionContext context) => Task.FromResult(new CloseTestSessionResult() { IsSuccess = true });
205-
public Task ExecuteRequestAsync(ExecuteRequestContext context) => Task.CompletedTask;
205+
public Task ExecuteRequestAsync(ExecuteRequestContext context)
206+
{
207+
context.Complete();
208+
return Task.CompletedTask;
209+
}
206210
}
207211
""";
208212

test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/testsbaseline.txt

+4
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ Microsoft.Testing.Platform.Acceptance.IntegrationTests.Microsoft.Testing.Platfor
7070
Microsoft.Testing.Platform.Acceptance.IntegrationTests.Microsoft.Testing.Platform.Acceptance.IntegrationTests.EnvironmentVariablesConfigurationProviderTests.EnabledEnvironmentVariablesConfiguration_SetEnvironmentVariable_ShouldSucceed(string) (net6.0)
7171
Microsoft.Testing.Platform.Acceptance.IntegrationTests.Microsoft.Testing.Platform.Acceptance.IntegrationTests.EnvironmentVariablesConfigurationProviderTests.EnabledEnvironmentVariablesConfiguration_SetEnvironmentVariable_ShouldSucceed(string) (net7.0)
7272
Microsoft.Testing.Platform.Acceptance.IntegrationTests.Microsoft.Testing.Platform.Acceptance.IntegrationTests.EnvironmentVariablesConfigurationProviderTests.EnabledEnvironmentVariablesConfiguration_SetEnvironmentVariable_ShouldSucceed(string) (net8.0)
73+
Microsoft.Testing.Platform.Acceptance.IntegrationTests.Microsoft.Testing.Platform.Acceptance.IntegrationTests.ExecutionTests.Exec_Honor_Request_Complete(string) (net462)
74+
Microsoft.Testing.Platform.Acceptance.IntegrationTests.Microsoft.Testing.Platform.Acceptance.IntegrationTests.ExecutionTests.Exec_Honor_Request_Complete(string) (net6.0)
75+
Microsoft.Testing.Platform.Acceptance.IntegrationTests.Microsoft.Testing.Platform.Acceptance.IntegrationTests.ExecutionTests.Exec_Honor_Request_Complete(string) (net7.0)
76+
Microsoft.Testing.Platform.Acceptance.IntegrationTests.Microsoft.Testing.Platform.Acceptance.IntegrationTests.ExecutionTests.Exec_Honor_Request_Complete(string) (net8.0)
7377
Microsoft.Testing.Platform.Acceptance.IntegrationTests.Microsoft.Testing.Platform.Acceptance.IntegrationTests.ExecutionTests.Exec_WhenFilterIsSpecified_OnlyFilteredTestsAreRun(string) (net462)
7478
Microsoft.Testing.Platform.Acceptance.IntegrationTests.Microsoft.Testing.Platform.Acceptance.IntegrationTests.ExecutionTests.Exec_WhenFilterIsSpecified_OnlyFilteredTestsAreRun(string) (net6.0)
7579
Microsoft.Testing.Platform.Acceptance.IntegrationTests.Microsoft.Testing.Platform.Acceptance.IntegrationTests.ExecutionTests.Exec_WhenFilterIsSpecified_OnlyFilteredTestsAreRun(string) (net7.0)

0 commit comments

Comments
 (0)