-
Notifications
You must be signed in to change notification settings - Fork 291
Fix AssemblyCleanup running when not all class cleanups might have finished #7173
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 all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a86526f
Fix AssemblyCleanup running when not all class cleanups might have fi…
Youssef1313 916ae0a
Add missing using
Youssef1313 957620d
Fix build
Youssef1313 6d71fdd
Assert output
Youssef1313 21c5b03
typo
Youssef1313 18df8bf
Fix tests
Youssef1313 5b13075
Update src/Adapter/MSTestAdapter.PlatformServices/Execution/UnitTestR…
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
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
127 changes: 127 additions & 0 deletions
127
test/IntegrationTests/MSTest.Acceptance.IntegrationTests/AssemblyCleanupTests.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,127 @@ | ||
| // 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.Acceptance.IntegrationTests.Helpers; | ||
| using Microsoft.Testing.Platform.Helpers; | ||
|
|
||
| namespace MSTest.Acceptance.IntegrationTests; | ||
|
|
||
| [TestClass] | ||
| public sealed class AssemblyCleanupTests : AcceptanceTestBase<AssemblyCleanupTests.TestAssetFixture> | ||
| { | ||
| [TestMethod] | ||
| public async Task AssemblyCleanupShouldRunAfterAllClassCleanupsHaveCompleted() | ||
| { | ||
| var testHost = TestHost.LocateFrom(AssetFixture.ProjectPath, TestAssetFixture.ProjectName, TargetFrameworks.NetCurrent); | ||
| TestHostResult testHostResult = await testHost.ExecuteAsync("--settings my.runsettings", cancellationToken: TestContext.CancellationToken); | ||
|
|
||
| testHostResult.AssertExitCodeIs(ExitCodes.Success); | ||
| testHostResult.AssertOutputContainsSummary(failed: 0, passed: 2, skipped: 0); | ||
| testHostResult.AssertOutputContains(""" | ||
| TestClass1.Test1. | ||
| TestClass1.Cleanup1 started. | ||
| TestClass1.Cleanup1 finished. | ||
| In AsmCleanup | ||
| """); | ||
Youssef1313 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder) | ||
| { | ||
| public const string ProjectName = "AssemblyCleanupTests"; | ||
|
|
||
| public string ProjectPath => GetAssetPath(ProjectName); | ||
|
|
||
| public override IEnumerable<(string ID, string Name, string Code)> GetAssetsToGenerate() | ||
| { | ||
| yield return (ProjectName, ProjectName, | ||
| SourceCode | ||
| .PatchTargetFrameworks(TargetFrameworks.All) | ||
| .PatchCodeWithReplace("$MSTestVersion$", MSTestVersion)); | ||
| } | ||
|
|
||
| private const string SourceCode = """ | ||
| #file AssemblyCleanupTests.csproj | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <EnableMSTestRunner>true</EnableMSTestRunner> | ||
| <TargetFrameworks>$TargetFrameworks$</TargetFrameworks> | ||
| <LangVersion>preview</LangVersion> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <PackageReference Include="MSTest.TestAdapter" Version="$MSTestVersion$" /> | ||
| <PackageReference Include="MSTest.TestFramework" Version="$MSTestVersion$" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <None Update="*.runsettings"> | ||
| <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
| </None> | ||
| </ItemGroup> | ||
| </Project> | ||
| #file TestClass1.cs | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Text; | ||
| using System.Threading; | ||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
| [assembly: Parallelize(Scope = ExecutionScope.MethodLevel, Workers = 0)] | ||
| [TestClass] | ||
| public class TestClass1 | ||
| { | ||
| public static bool ClassCleanupFinished { get; private set; } | ||
Youssef1313 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| [TestMethod] | ||
| public void Test1() | ||
| { | ||
| Console.WriteLine("TestClass1.Test1."); | ||
| } | ||
| [ClassCleanup] | ||
| public static void Cleanup1() | ||
| { | ||
| Console.WriteLine("TestClass1.Cleanup1 started."); | ||
| Thread.Sleep(4000); | ||
| Console.WriteLine("TestClass1.Cleanup1 finished."); | ||
| } | ||
| } | ||
| [TestClass] | ||
| public class TestClass2 | ||
| { | ||
| [TestMethod] | ||
| public void Test2() | ||
| { | ||
| } | ||
| [ClassCleanup] | ||
| public static void Cleanup2() | ||
| => Thread.Sleep(2000); | ||
Youssef1313 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| [TestClass] | ||
| public static class Asm | ||
| { | ||
| [AssemblyCleanup] | ||
| public static void AsmCleanup() | ||
| => Console.WriteLine("In AsmCleanup"); | ||
| } | ||
| #file my.runsettings | ||
| <RunSettings> | ||
| <MSTest> | ||
| <CaptureTraceOutput>false</CaptureTraceOutput> | ||
| </MSTest> | ||
| </RunSettings> | ||
| """; | ||
| } | ||
|
|
||
| public TestContext TestContext { get; set; } | ||
| } | ||
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.
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.