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

Honor request.Complete() #2448

Merged
merged 3 commits into from
Feb 26, 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
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public async Task ExecuteAsync(ITestFramework testFrameworkAdapter, ClientInfo c

public virtual async Task ExecuteRequestAsync(ITestFramework testFrameworkAdapter, TestExecutionRequest request, IMessageBus messageBus, CancellationToken cancellationToken)
{
using SemaphoreSlim requestSemaphore = new(1);
using SemaphoreSlim requestSemaphore = new(0, 1);
await testFrameworkAdapter.ExecuteRequestAsync(new(request, messageBus, requestSemaphore, cancellationToken));
await requestSemaphore.WaitAsync(cancellationToken);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Diagnostics;

using Microsoft.Testing.Platform.Acceptance.IntegrationTests.Helpers;
using Microsoft.Testing.Platform.Helpers;

Expand All @@ -10,6 +12,8 @@ namespace Microsoft.Testing.Platform.Acceptance.IntegrationTests;
public class ExecutionTests : AcceptanceTestBase
{
private const string AssetName = "ExecutionTests";
private const string AssetName2 = "ExecutionTests2";

private readonly TestAssetFixture _testAssetFixture;

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

[ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))]
public async Task Exec_Honor_Request_Complete(string tfm)
{
TestInfrastructure.TestHost testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath2, AssetName2, tfm);
Stopwatch stopwatch = Stopwatch.StartNew();
TestHostResult testHostResult = await testHost.ExecuteAsync();
stopwatch.Stop();
Assert.AreEqual(ExitCodes.Success, testHostResult.ExitCode);
Assert.IsTrue(stopwatch.Elapsed.TotalSeconds > 3);
}

[TestFixture(TestFixtureSharingStrategy.PerTestGroup)]
public sealed class TestAssetFixture(AcceptanceFixture acceptanceFixture) : TestAssetFixtureBase(acceptanceFixture.NuGetGlobalPackagesFolder)
{
Expand Down Expand Up @@ -180,17 +195,98 @@ public void FilteredOutTest()
global using Microsoft.Testing.Platform.Builder;
global using Microsoft.Testing.Framework;
global using Microsoft.Testing.Extensions;
""";

private const string TestCode2 = """
#file ExecutionTests2.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>$TargetFrameworks$</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<OutputType>Exe</OutputType>
<UseAppHost>true</UseAppHost>
<LangVersion>preview</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Testing.Platform" Version="$MicrosoftTestingPlatformVersion$" />
</ItemGroup>
</Project>

#file Program.cs
using Microsoft.Testing.Platform;
using Microsoft.Testing.Platform.Extensions;
using Microsoft.Testing.Platform.Builder;
using Microsoft.Testing.Platform.Capabilities;
using Microsoft.Testing.Platform.Capabilities.TestFramework;
using Microsoft.Testing.Platform.Extensions.Messages;
using Microsoft.Testing.Platform.Extensions.TestFramework;
using System.Threading.Tasks;

ITestApplicationBuilder builder = await TestApplication.CreateBuilderAsync(args);
builder.RegisterTestFramework(_ => new Capabilities(), (_, __) => new DummyAdapter());
using ITestApplication app = await builder.BuildAsync();
return await app.RunAsync();

internal class DummyAdapter : ITestFramework, IDataProducer
{
public string Uid => nameof(DummyAdapter);

public string Version => string.Empty;

public string DisplayName => string.Empty;

public string Description => string.Empty;

public Type[] DataTypesProduced => new[] { typeof(TestNodeUpdateMessage) };

public Task<CloseTestSessionResult> CloseTestSessionAsync(CloseTestSessionContext context) => Task.FromResult(new CloseTestSessionResult() { IsSuccess = true });

public Task<CreateTestSessionResult> CreateTestSessionAsync(CreateTestSessionContext context) => Task.FromResult(new CreateTestSessionResult() { IsSuccess = true });

public Task ExecuteRequestAsync(ExecuteRequestContext context)
{
Task.Run(async() =>
{
await context.MessageBus.PublishAsync(this, new TestNodeUpdateMessage(
context.Request.Session.SessionUid,
new TestNode() { Uid = "0", DisplayName = "Test", Properties = new(PassedTestNodeStateProperty.CachedInstance) }));

Thread.Sleep(3_000);

context.Complete();
});

return Task.CompletedTask;
}

public Task<bool> IsEnabledAsync() => Task.FromResult(true);
}

internal class Capabilities : ITestFrameworkCapabilities
{
IReadOnlyCollection<ITestFrameworkCapability> ICapabilities<ITestFrameworkCapability>.Capabilities => Array.Empty<ITestFrameworkCapability>();
}

""";

public string TargetAssetPath => GetAssetPath(AssetName);

public string TargetAssetPath2 => GetAssetPath(AssetName2);

public override IEnumerable<(string ID, string Name, string Code)> GetAssetsToGenerate()
{
yield return (AssetName, AssetName,
TestCode
.PatchTargetFrameworks(TargetFrameworks.All)
.PatchCodeWithReplace("$MicrosoftTestingPlatformVersion$", MicrosoftTestingPlatformVersion)
.PatchCodeWithReplace("$MicrosoftTestingPlatformExtensionsVersion$", MicrosoftTestingPlatformExtensionsVersion));

yield return (AssetName2, AssetName2,
TestCode2
.PatchTargetFrameworks(TargetFrameworks.All)
.PatchCodeWithReplace("$MicrosoftTestingPlatformVersion$", MicrosoftTestingPlatformVersion)
.PatchCodeWithReplace("$MicrosoftTestingPlatformExtensionsVersion$", MicrosoftTestingPlatformExtensionsVersion));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,11 @@ public Task<CreateTestSessionResult> CreateTestSessionAsync(CreateTestSessionCon
=> Task.FromResult(new CreateTestSessionResult() { IsSuccess = true });
public Task<CloseTestSessionResult> CloseTestSessionAsync(CloseTestSessionContext context)
=> Task.FromResult(new CloseTestSessionResult() { IsSuccess = true });
public Task ExecuteRequestAsync(ExecuteRequestContext context) => Task.CompletedTask;
public Task ExecuteRequestAsync(ExecuteRequestContext context)
{
context.Complete();
return Task.CompletedTask;
}
}
""";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,11 @@ public class DummyTestAdapter : ITestFramework

public Task<CreateTestSessionResult> CreateTestSessionAsync(CreateTestSessionContext context) => Task.FromResult(new CreateTestSessionResult() { IsSuccess = true });
public Task<CloseTestSessionResult> CloseTestSessionAsync(CloseTestSessionContext context) => Task.FromResult(new CloseTestSessionResult() { IsSuccess = true });
public Task ExecuteRequestAsync(ExecuteRequestContext context) => Task.CompletedTask;
public Task ExecuteRequestAsync(ExecuteRequestContext context)
{
context.Complete();
return Task.CompletedTask;
}
}
""";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ Microsoft.Testing.Platform.Acceptance.IntegrationTests.Microsoft.Testing.Platfor
Microsoft.Testing.Platform.Acceptance.IntegrationTests.Microsoft.Testing.Platform.Acceptance.IntegrationTests.EnvironmentVariablesConfigurationProviderTests.EnabledEnvironmentVariablesConfiguration_SetEnvironmentVariable_ShouldSucceed(string) (net6.0)
Microsoft.Testing.Platform.Acceptance.IntegrationTests.Microsoft.Testing.Platform.Acceptance.IntegrationTests.EnvironmentVariablesConfigurationProviderTests.EnabledEnvironmentVariablesConfiguration_SetEnvironmentVariable_ShouldSucceed(string) (net7.0)
Microsoft.Testing.Platform.Acceptance.IntegrationTests.Microsoft.Testing.Platform.Acceptance.IntegrationTests.EnvironmentVariablesConfigurationProviderTests.EnabledEnvironmentVariablesConfiguration_SetEnvironmentVariable_ShouldSucceed(string) (net8.0)
Microsoft.Testing.Platform.Acceptance.IntegrationTests.Microsoft.Testing.Platform.Acceptance.IntegrationTests.ExecutionTests.Exec_Honor_Request_Complete(string) (net462)
Microsoft.Testing.Platform.Acceptance.IntegrationTests.Microsoft.Testing.Platform.Acceptance.IntegrationTests.ExecutionTests.Exec_Honor_Request_Complete(string) (net6.0)
Microsoft.Testing.Platform.Acceptance.IntegrationTests.Microsoft.Testing.Platform.Acceptance.IntegrationTests.ExecutionTests.Exec_Honor_Request_Complete(string) (net7.0)
Microsoft.Testing.Platform.Acceptance.IntegrationTests.Microsoft.Testing.Platform.Acceptance.IntegrationTests.ExecutionTests.Exec_Honor_Request_Complete(string) (net8.0)
Microsoft.Testing.Platform.Acceptance.IntegrationTests.Microsoft.Testing.Platform.Acceptance.IntegrationTests.ExecutionTests.Exec_WhenFilterIsSpecified_OnlyFilteredTestsAreRun(string) (net462)
Microsoft.Testing.Platform.Acceptance.IntegrationTests.Microsoft.Testing.Platform.Acceptance.IntegrationTests.ExecutionTests.Exec_WhenFilterIsSpecified_OnlyFilteredTestsAreRun(string) (net6.0)
Microsoft.Testing.Platform.Acceptance.IntegrationTests.Microsoft.Testing.Platform.Acceptance.IntegrationTests.ExecutionTests.Exec_WhenFilterIsSpecified_OnlyFilteredTestsAreRun(string) (net7.0)
Expand Down