-
Notifications
You must be signed in to change notification settings - Fork 288
Add lifecycle callbacks to test host orchestrator #5717
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
00ca8b7
Add lifecycle callbacks to test host orchestrator
Youssef1313 59f4c15
Add test
Youssef1313 22ef535
Add comment
Youssef1313 d7fc885
Adjust
Youssef1313 961dda2
Comments
Youssef1313 4a42a65
Fix
Youssef1313 149b778
Merge branch 'main' into dev/ygerges/retry-dotnet-test
Youssef1313 7c5b51d
Update TestHostOrchestratorManager.cs
Youssef1313 01b360c
Update MSBuildOrchestratorLifecycleCallbacks.cs
Youssef1313 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
src/Platform/Microsoft.Testing.Extensions.MSBuild/MSBuildOrchestratorLifecycleCallbacks.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| // 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.Extensions.MSBuild.Serializers; | ||
| using Microsoft.Testing.Platform.CommandLine; | ||
| using Microsoft.Testing.Platform.Configurations; | ||
| using Microsoft.Testing.Platform.Extensions.TestHostOrchestrator; | ||
| using Microsoft.Testing.Platform.Helpers; | ||
| using Microsoft.Testing.Platform.IPC; | ||
| using Microsoft.Testing.Platform.IPC.Models; | ||
| using Microsoft.Testing.Platform.IPC.Serializers; | ||
| using Microsoft.Testing.Platform.Services; | ||
|
|
||
| namespace Microsoft.Testing.Extensions.MSBuild; | ||
|
|
||
| internal sealed class MSBuildOrchestratorLifetime : ITestHostOrchestratorApplicationLifetime | ||
| { | ||
| private readonly IConfiguration _configuration; | ||
| private readonly ICommandLineOptions _commandLineOptions; | ||
| private readonly ITestApplicationCancellationTokenSource _testApplicationCancellationTokenSource; | ||
|
|
||
| public MSBuildOrchestratorLifetime( | ||
| IConfiguration configuration, | ||
| ICommandLineOptions commandLineOptions, | ||
| ITestApplicationCancellationTokenSource testApplicationCancellationTokenSource) | ||
| { | ||
| _configuration = configuration; | ||
| _commandLineOptions = commandLineOptions; | ||
| _testApplicationCancellationTokenSource = testApplicationCancellationTokenSource; | ||
| } | ||
|
|
||
| public string Uid => nameof(MSBuildOrchestratorLifetime); | ||
|
|
||
| public string Version => AppVersion.DefaultSemVer; | ||
|
|
||
| public string DisplayName => nameof(MSBuildOrchestratorLifetime); | ||
|
|
||
| public string Description => Resources.ExtensionResources.MSBuildExtensionsDescription; | ||
|
|
||
| public Task<bool> IsEnabledAsync() | ||
| => Task.FromResult(_commandLineOptions.IsOptionSet(MSBuildConstants.MSBuildNodeOptionKey)); | ||
|
|
||
| public async Task BeforeRunAsync(CancellationToken cancellationToken) | ||
| { | ||
| if (!_commandLineOptions.TryGetOptionArgumentList(MSBuildConstants.MSBuildNodeOptionKey, out string[]? msbuildInfo)) | ||
| { | ||
| throw new InvalidOperationException($"MSBuild pipe name not found in the command line, missing {MSBuildConstants.MSBuildNodeOptionKey}"); | ||
| } | ||
|
|
||
| if (msbuildInfo is null || msbuildInfo.Length != 1 || string.IsNullOrEmpty(msbuildInfo[0])) | ||
| { | ||
| throw new InvalidOperationException($"MSBuild pipe name not found in the command line, missing argument for {MSBuildConstants.MSBuildNodeOptionKey}"); | ||
| } | ||
|
|
||
| using var pipeClient = new NamedPipeClient(msbuildInfo[0]); | ||
| pipeClient.RegisterSerializer(new ModuleInfoRequestSerializer(), typeof(ModuleInfoRequest)); | ||
| pipeClient.RegisterSerializer(new VoidResponseSerializer(), typeof(VoidResponse)); | ||
| using var cancellationTokenSource = new CancellationTokenSource(TimeoutHelper.DefaultHangTimeSpanTimeout); | ||
| using var linkedCancellationToken = CancellationTokenSource.CreateLinkedTokenSource(cancellationTokenSource.Token, _testApplicationCancellationTokenSource.CancellationToken); | ||
| await pipeClient.ConnectAsync(linkedCancellationToken.Token); | ||
| await pipeClient.RequestReplyAsync<ModuleInfoRequest, VoidResponse>( | ||
| new ModuleInfoRequest( | ||
| RuntimeInformation.FrameworkDescription, | ||
| RuntimeInformation.ProcessArchitecture.ToString().ToLowerInvariant(), | ||
| _configuration.GetTestResultDirectory()), | ||
| _testApplicationCancellationTokenSource.CancellationToken); | ||
| } | ||
|
|
||
| public Task AfterRunAsync(int exitCode, CancellationToken cancellation) => Task.CompletedTask; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
...latform/Microsoft.Testing.Platform/TestHostOrcherstrator/ITestHostControllersExtension.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| namespace Microsoft.Testing.Platform.Extensions.TestHostOrchestrator; | ||
|
|
||
| /// <summary> | ||
| /// Represents an extension for test host orchestrators. | ||
| /// </summary> | ||
| internal interface ITestHostOrchestratorExtension : IExtension; |
25 changes: 25 additions & 0 deletions
25
...rosoft.Testing.Platform/TestHostOrcherstrator/ITestHostOrchestratorApplicationLifetime.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| namespace Microsoft.Testing.Platform.Extensions.TestHostOrchestrator; | ||
|
|
||
| // NOTE: The equivalent of this for "test host" is ITestApplicationLifecycleCallbacks, which is an unfortunate naming. | ||
| // If we ever open orchestration before MTP v2 (https://github.com/microsoft/testfx/issues/5733), we should | ||
| // consider if we are okay with this kinda inconsistent naming between test host and test host orchestrator. | ||
| internal interface ITestHostOrchestratorApplicationLifetime : ITestHostOrchestratorExtension | ||
| { | ||
| /// <summary> | ||
| /// Executes before the orchestrator runs. | ||
| /// </summary> | ||
| /// <param name="cancellationToken">The cancellation token.</param> | ||
| /// <returns>A task representing the asynchronous operation.</returns> | ||
| Task BeforeRunAsync(CancellationToken cancellationToken); | ||
|
|
||
| /// <summary> | ||
| /// Executes after the orchestrator runs. | ||
| /// </summary> | ||
| /// <param name="exitCode">The exit code of the orchestrator.</param> | ||
| /// <param name="cancellation">The cancellation token.</param> | ||
| /// <returns>A task representing the asynchronous operation.</returns> | ||
| Task AfterRunAsync(int exitCode, CancellationToken cancellation); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.