diff --git a/Directory.Packages.props b/Directory.Packages.props index c5b6b98e8..2cf97ec8a 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -4,9 +4,9 @@ true true + 2.0.2 2.0.208 3.11.0 - 4.13.0 1.1.2 3.11.0-beta1.25076.3 @@ -36,22 +36,17 @@ - - - - - - - - - - + + + - + + + + - - + diff --git a/azure-pipelines/Merge-CodeCoverage.ps1 b/azure-pipelines/Merge-CodeCoverage.ps1 index 32438237e..c552d25f2 100644 --- a/azure-pipelines/Merge-CodeCoverage.ps1 +++ b/azure-pipelines/Merge-CodeCoverage.ps1 @@ -28,6 +28,7 @@ try { if ($reports) { $reports |% { $_.FullName } |% { # In addition to replacing {reporoot}, we also normalize on one kind of slash so that the report aggregates data for a file whether data was collected on Windows or not. + Write-Verbose "Processing $_" $xml = [xml](Get-Content -LiteralPath $_) $xml.coverage.packages.package.classes.class |? { $_.filename} |% { $_.filename = $_.filename.Replace('{reporoot}', $RepoRoot).Replace([IO.Path]::AltDirectorySeparatorChar, [IO.Path]::DirectorySeparatorChar) diff --git a/global.json b/global.json index a04d4cd45..309bbfd49 100644 --- a/global.json +++ b/global.json @@ -1,9 +1,12 @@ { "sdk": { - "version": "10.0.100", + "version": "10.0.101", "rollForward": "patch", "allowPrerelease": false }, + "test": { + "runner": "Microsoft.Testing.Platform" + }, "msbuild-sdks": { "MSBuild.Sdk.Extras": "3.0.44", "Microsoft.Build.NoTargets": "3.7.134", diff --git a/src/Microsoft.VisualStudio.Threading/ListOfOftenOne`1.cs b/src/Microsoft.VisualStudio.Threading/ListOfOftenOne`1.cs index 6ff984ca1..2549aeb50 100644 --- a/src/Microsoft.VisualStudio.Threading/ListOfOftenOne`1.cs +++ b/src/Microsoft.VisualStudio.Threading/ListOfOftenOne`1.cs @@ -3,11 +3,7 @@ using System; using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Text; using System.Threading; -using System.Threading.Tasks; namespace Microsoft.VisualStudio.Threading; diff --git a/src/Microsoft.VisualStudio.Threading/WeakKeyDictionary`2.cs b/src/Microsoft.VisualStudio.Threading/WeakKeyDictionary`2.cs index 562d198aa..5f92e4cc7 100644 --- a/src/Microsoft.VisualStudio.Threading/WeakKeyDictionary`2.cs +++ b/src/Microsoft.VisualStudio.Threading/WeakKeyDictionary`2.cs @@ -214,7 +214,7 @@ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() /// internal bool Any() { - foreach (KeyValuePair.WeakReference, TValue> item in this.dictionary) + foreach (KeyValuePair, TValue> item in this.dictionary) { if (item.Key.IsAlive) { diff --git a/test/.editorconfig b/test/.editorconfig index 988129278..04701aea8 100644 --- a/test/.editorconfig +++ b/test/.editorconfig @@ -80,3 +80,6 @@ dotnet_diagnostic.SA1401.severity = silent # SA1133: Do not combine attributes dotnet_diagnostic.SA1133.severity = silent + +# xUnit1051: Use TestContext.Current.CancellationToken +dotnet_diagnostic.xUnit1051.severity = suggestion diff --git a/test/Directory.Build.props b/test/Directory.Build.props index e8b338a78..466be54e4 100644 --- a/test/Directory.Build.props +++ b/test/Directory.Build.props @@ -3,9 +3,9 @@ - true false true + true diff --git a/test/Directory.Build.targets b/test/Directory.Build.targets index 9f32cd061..3758bb8c9 100644 --- a/test/Directory.Build.targets +++ b/test/Directory.Build.targets @@ -1,5 +1,11 @@ + + + + + + diff --git a/test/Directory.Packages.props b/test/Directory.Packages.props new file mode 100644 index 000000000..6875d8235 --- /dev/null +++ b/test/Directory.Packages.props @@ -0,0 +1,14 @@ + + + + + + 4.13.0 + + + + + + + + diff --git a/test/IsolatedTestHost/App.config b/test/IsolatedTestHost/App.config index e5ab83a70..aed254391 100644 --- a/test/IsolatedTestHost/App.config +++ b/test/IsolatedTestHost/App.config @@ -1,29 +1,12 @@  - - - - - - + - - - - - - - - - - - - diff --git a/test/IsolatedTestHost/IsolatedTestHost.csproj b/test/IsolatedTestHost/IsolatedTestHost.csproj index b5b95cf1e..353005b37 100644 --- a/test/IsolatedTestHost/IsolatedTestHost.csproj +++ b/test/IsolatedTestHost/IsolatedTestHost.csproj @@ -3,10 +3,11 @@ Exe net472 + false - + diff --git a/test/IsolatedTestHost/Program.cs b/test/IsolatedTestHost/Program.cs index 6712fa6e0..a20655442 100644 --- a/test/IsolatedTestHost/Program.cs +++ b/test/IsolatedTestHost/Program.cs @@ -7,7 +7,6 @@ using System.Reflection; using System.Threading; using System.Threading.Tasks; -using Xunit; namespace IsolatedTestHost; @@ -53,8 +52,7 @@ private static ExitCode MyMain(string assemblyFile, string testClassName, string } bool fact = testMethod.GetCustomAttributesData().Any(a => a.AttributeType.Name == "FactAttribute"); - bool skippableFact = testMethod.GetCustomAttributesData().Any(a => a.AttributeType.Name == "SkippableFactAttribute"); - if (fact || skippableFact) + if (fact) { return ExecuteTest(testClass, testMethod); } diff --git a/test/IsolatedTestHost/TestOutputHelper.cs b/test/IsolatedTestHost/TestOutputHelper.cs index b27c20f25..f91502ede 100644 --- a/test/IsolatedTestHost/TestOutputHelper.cs +++ b/test/IsolatedTestHost/TestOutputHelper.cs @@ -1,20 +1,23 @@ // 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; -using Xunit.Abstractions; +using System.Globalization; +using System.Text; +using Xunit; namespace IsolatedTestHost; internal class TestOutputHelper : ITestOutputHelper { - public void WriteLine(string message) - { - Console.WriteLine(message); - } - - public void WriteLine(string format, params object[] args) - { - Console.WriteLine(format, args); - } + private readonly StringBuilder builder = new(); + + public string Output => this.builder.ToString(); + + public void Write(string message) => this.builder.Append(message); + + public void Write(string format, params object[] args) => this.builder.AppendFormat(format, args); + + public void WriteLine(string message) => this.builder.AppendLine(message); + + public void WriteLine(string format, params object[] args) => this.builder.AppendLine(string.Format(CultureInfo.CurrentCulture, format, args)); } diff --git a/test/Microsoft.VisualStudio.Threading.Analyzers.Tests/Helpers/CSharpCodeFixVerifier`2+Test.cs b/test/Microsoft.VisualStudio.Threading.Analyzers.Tests/Helpers/CSharpCodeFixVerifier`2+Test.cs index 18ae7d018..b767fa30e 100644 --- a/test/Microsoft.VisualStudio.Threading.Analyzers.Tests/Helpers/CSharpCodeFixVerifier`2+Test.cs +++ b/test/Microsoft.VisualStudio.Threading.Analyzers.Tests/Helpers/CSharpCodeFixVerifier`2+Test.cs @@ -37,7 +37,7 @@ public Test() #if WINDOWS project = project.AddMetadataReference(MetadataReference.CreateFromFile(typeof(Dispatcher).Assembly.Location)); #else - Skip.If(true); + Assert.SkipWhen(true, "Windows only"); #endif } diff --git a/test/Microsoft.VisualStudio.Threading.Analyzers.Tests/Helpers/VisualBasicCodeFixVerifier`2+Test.cs b/test/Microsoft.VisualStudio.Threading.Analyzers.Tests/Helpers/VisualBasicCodeFixVerifier`2+Test.cs index 8793d3d8c..c3a1ef718 100644 --- a/test/Microsoft.VisualStudio.Threading.Analyzers.Tests/Helpers/VisualBasicCodeFixVerifier`2+Test.cs +++ b/test/Microsoft.VisualStudio.Threading.Analyzers.Tests/Helpers/VisualBasicCodeFixVerifier`2+Test.cs @@ -37,7 +37,7 @@ public Test() #if WINDOWS project = project.AddMetadataReference(MetadataReference.CreateFromFile(typeof(Dispatcher).Assembly.Location)); #else - Skip.If(true); + Assert.SkipWhen(true, "Windows only"); #endif } diff --git a/test/Microsoft.VisualStudio.Threading.Analyzers.Tests/Microsoft.VisualStudio.Threading.Analyzers.Tests.csproj b/test/Microsoft.VisualStudio.Threading.Analyzers.Tests/Microsoft.VisualStudio.Threading.Analyzers.Tests.csproj index c77215d0f..50bbac324 100644 --- a/test/Microsoft.VisualStudio.Threading.Analyzers.Tests/Microsoft.VisualStudio.Threading.Analyzers.Tests.csproj +++ b/test/Microsoft.VisualStudio.Threading.Analyzers.Tests/Microsoft.VisualStudio.Threading.Analyzers.Tests.csproj @@ -1,7 +1,7 @@  net8.0 - true + Exe true true $(NoWarn);NU1701 @@ -25,13 +25,10 @@ - - - - + net472 Exe + false diff --git a/test/Microsoft.VisualStudio.Threading.Tests/AssemblyInfo.cs b/test/Microsoft.VisualStudio.Threading.Tests/AssemblyInfo.cs index da96c1511..194900e3c 100644 --- a/test/Microsoft.VisualStudio.Threading.Tests/AssemblyInfo.cs +++ b/test/Microsoft.VisualStudio.Threading.Tests/AssemblyInfo.cs @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using Xunit; - // Some of our tests measure stress, GC pressure, etc. // It messes with reliable test results when other threads are doing random stuff. [assembly: CollectionBehavior(DisableTestParallelization = true)] diff --git a/test/Microsoft.VisualStudio.Threading.Tests/AsyncAutoResetEventTests.cs b/test/Microsoft.VisualStudio.Threading.Tests/AsyncAutoResetEventTests.cs index ad1d4431c..c6b0ecc11 100644 --- a/test/Microsoft.VisualStudio.Threading.Tests/AsyncAutoResetEventTests.cs +++ b/test/Microsoft.VisualStudio.Threading.Tests/AsyncAutoResetEventTests.cs @@ -4,14 +4,12 @@ using System; using System.Threading; using System.Threading.Tasks; -using Microsoft.VisualStudio.Threading; -using Xunit; public class AsyncAutoResetEventTests : TestBase { private AsyncAutoResetEvent evt; - public AsyncAutoResetEventTests(Xunit.Abstractions.ITestOutputHelper logger) + public AsyncAutoResetEventTests(ITestOutputHelper logger) : base(logger) { this.evt = new AsyncAutoResetEvent(); @@ -200,7 +198,7 @@ public async Task WaitAsync_Canceled_Stress() /// /// Verifies that long-lived, uncanceled CancellationTokens do not result in leaking memory. /// - [SkippableFact(Skip = "It always fails after xunit 2.8 update.")] + [Fact(Skip = "It always fails after xunit 2.8 update.")] [Trait("GC", "true")] [Trait("TestCategory", "FailsInCloudTest")] public async Task WaitAsync_WithCancellationToken_DoesNotLeakWhenNotCanceled() @@ -222,7 +220,7 @@ public async Task WaitAsync_WithCancellationToken_DoesNotLeakWhenNotCanceled() /// /// Verifies that canceled CancellationTokens do not result in leaking memory. /// - [SkippableFact(Skip = "It always fails after xunit 2.8 update.")] + [Fact(Skip = "It always fails after xunit 2.8 update.")] [Trait("GC", "true")] [Trait("TestCategory", "FailsInCloudTest")] public async Task WaitAsync_WithCancellationToken_DoesNotLeakWhenCanceled() diff --git a/test/Microsoft.VisualStudio.Threading.Tests/AsyncBarrierTests.cs b/test/Microsoft.VisualStudio.Threading.Tests/AsyncBarrierTests.cs index 5b9c48559..394cf5bee 100644 --- a/test/Microsoft.VisualStudio.Threading.Tests/AsyncBarrierTests.cs +++ b/test/Microsoft.VisualStudio.Threading.Tests/AsyncBarrierTests.cs @@ -6,9 +6,6 @@ using System.Threading; using System.Threading.Tasks; using Microsoft; -using Microsoft.VisualStudio.Threading; -using Xunit; -using Xunit.Abstractions; public class AsyncBarrierTests : TestBase { diff --git a/test/Microsoft.VisualStudio.Threading.Tests/AsyncCountdownEventTests.cs b/test/Microsoft.VisualStudio.Threading.Tests/AsyncCountdownEventTests.cs index 7c9606aca..2ab242193 100644 --- a/test/Microsoft.VisualStudio.Threading.Tests/AsyncCountdownEventTests.cs +++ b/test/Microsoft.VisualStudio.Threading.Tests/AsyncCountdownEventTests.cs @@ -4,9 +4,6 @@ using System; using System.Threading; using System.Threading.Tasks; -using Microsoft.VisualStudio.Threading; -using Xunit; -using Xunit.Abstractions; public class AsyncCountdownEventTests : TestBase { diff --git a/test/Microsoft.VisualStudio.Threading.Tests/AsyncCrossProcessMutexTests.cs b/test/Microsoft.VisualStudio.Threading.Tests/AsyncCrossProcessMutexTests.cs index 9c72d1d8a..8872ad9aa 100644 --- a/test/Microsoft.VisualStudio.Threading.Tests/AsyncCrossProcessMutexTests.cs +++ b/test/Microsoft.VisualStudio.Threading.Tests/AsyncCrossProcessMutexTests.cs @@ -4,9 +4,6 @@ using System; using System.Threading; using System.Threading.Tasks; -using Microsoft.VisualStudio.Threading; -using Xunit; -using Xunit.Abstractions; public class AsyncCrossProcessMutexTests : TestBase, IDisposable { diff --git a/test/Microsoft.VisualStudio.Threading.Tests/AsyncLazyInitializerTests.cs b/test/Microsoft.VisualStudio.Threading.Tests/AsyncLazyInitializerTests.cs index 5c16ba2a6..69eb2dccd 100644 --- a/test/Microsoft.VisualStudio.Threading.Tests/AsyncLazyInitializerTests.cs +++ b/test/Microsoft.VisualStudio.Threading.Tests/AsyncLazyInitializerTests.cs @@ -4,9 +4,6 @@ using System; using System.Threading; using System.Threading.Tasks; -using Microsoft.VisualStudio.Threading; -using Xunit; -using Xunit.Abstractions; public class AsyncLazyInitializerTests : TestBase { diff --git a/test/Microsoft.VisualStudio.Threading.Tests/AsyncLazyTests.cs b/test/Microsoft.VisualStudio.Threading.Tests/AsyncLazyTests.cs index 0c3e76a21..79fb5b395 100644 --- a/test/Microsoft.VisualStudio.Threading.Tests/AsyncLazyTests.cs +++ b/test/Microsoft.VisualStudio.Threading.Tests/AsyncLazyTests.cs @@ -8,11 +8,6 @@ using System.Threading.Tasks; using Microsoft; -using Microsoft.VisualStudio.Threading; - -using Xunit; -using Xunit.Abstractions; - using NamedSyncContext = AwaitExtensionsTests.NamedSyncContext; public class AsyncLazyTests : TestBase @@ -214,7 +209,7 @@ public async Task ValueFactoryReentersValueFactorySynchronously(bool specifyJtf) Assert.False(executed); executed = true; lazy!.GetValueAsync(); - return Task.FromResult(new object()); + return Task.FromResult(new object()); }, jtf); @@ -389,7 +384,7 @@ public void ToStringForUncreatedValue() [Fact] public async Task ToStringForCreatedValue() { - var lazy = new AsyncLazy(() => Task.FromResult(3)); + var lazy = new AsyncLazy(() => Task.FromResult(3)); int value = await lazy.GetValueAsync(); string result = lazy.ToString(); Assert.Equal(value.ToString(CultureInfo.InvariantCulture), result); diff --git a/test/Microsoft.VisualStudio.Threading.Tests/AsyncLocalTests.cs b/test/Microsoft.VisualStudio.Threading.Tests/AsyncLocalTests.cs index eeb40ead3..0d0b63e88 100644 --- a/test/Microsoft.VisualStudio.Threading.Tests/AsyncLocalTests.cs +++ b/test/Microsoft.VisualStudio.Threading.Tests/AsyncLocalTests.cs @@ -7,9 +7,6 @@ using System.Reflection; using System.Threading; using System.Threading.Tasks; -using Microsoft.VisualStudio.Threading; -using Xunit; -using Xunit.Abstractions; public class AsyncLocalTests : TestBase { diff --git a/test/Microsoft.VisualStudio.Threading.Tests/AsyncManualResetEventTests.cs b/test/Microsoft.VisualStudio.Threading.Tests/AsyncManualResetEventTests.cs index 3e774cf93..556bc7c20 100644 --- a/test/Microsoft.VisualStudio.Threading.Tests/AsyncManualResetEventTests.cs +++ b/test/Microsoft.VisualStudio.Threading.Tests/AsyncManualResetEventTests.cs @@ -4,9 +4,6 @@ using System; using System.Threading; using System.Threading.Tasks; -using Microsoft.VisualStudio.Threading; -using Xunit; -using Xunit.Abstractions; public class AsyncManualResetEventTests : TestBase { @@ -21,7 +18,7 @@ public AsyncManualResetEventTests(ITestOutputHelper logger) [Fact] public void CtorDefaultParameter() { - Assert.False(new System.Threading.ManualResetEventSlim().IsSet); + Assert.False(new ManualResetEventSlim().IsSet); } [Fact] diff --git a/test/Microsoft.VisualStudio.Threading.Tests/AsyncQueueTests.cs b/test/Microsoft.VisualStudio.Threading.Tests/AsyncQueueTests.cs index 65c5700df..c53a34c2c 100644 --- a/test/Microsoft.VisualStudio.Threading.Tests/AsyncQueueTests.cs +++ b/test/Microsoft.VisualStudio.Threading.Tests/AsyncQueueTests.cs @@ -6,14 +6,12 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.VisualStudio.Threading; -using Xunit; public class AsyncQueueTests : TestBase { private AsyncQueue queue; - public AsyncQueueTests(Xunit.Abstractions.ITestOutputHelper logger) + public AsyncQueueTests(ITestOutputHelper logger) : base(logger) { this.queue = new AsyncQueue(); @@ -543,7 +541,7 @@ public void OnCompletedInvoked() Assert.Equal(1, invoked); } - [SkippableFact, Trait("GC", "true")] + [Fact, Trait("GC", "true")] [Trait("TestCategory", "FailsInCloudTest")] public void UnusedQueueGCPressure() { diff --git a/test/Microsoft.VisualStudio.Threading.Tests/AsyncReaderWriterLockTests.cs b/test/Microsoft.VisualStudio.Threading.Tests/AsyncReaderWriterLockTests.cs index 9944108c7..c62e537ab 100644 --- a/test/Microsoft.VisualStudio.Threading.Tests/AsyncReaderWriterLockTests.cs +++ b/test/Microsoft.VisualStudio.Threading.Tests/AsyncReaderWriterLockTests.cs @@ -9,9 +9,6 @@ using System.Threading; using System.Threading.Tasks; using Microsoft; -using Microsoft.VisualStudio.Threading; -using Xunit; -using Xunit.Abstractions; using Xunit.Sdk; #pragma warning disable CA1416 // Validate platform compatibility @@ -230,7 +227,7 @@ public async Task CompleteMethodExecutesContinuationsAsynchronously() await continuation; } - [SkippableFact] + [Fact] [Trait("TestCategory", "FailsInCloudTest")] public async Task NoMemoryLeakForManyLocks() { @@ -3854,10 +3851,10 @@ public async Task MtaLockSharedWithMta() } /// Verifies that when an MTA holding a lock traverses (via CallContext) to an STA that the STA does not appear to hold a lock. - [SkippableFact] + [Fact] public async Task MtaLockNotSharedWithSta() { - Skip.IfNot(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)); + Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.Windows), "Windows only"); using (await this.asyncLock.ReadLockAsync()) { var testComplete = new TaskCompletionSource(); @@ -3880,10 +3877,10 @@ public async Task MtaLockNotSharedWithSta() } /// Verifies that when an MTA holding a lock traverses (via CallContext) to an STA that the STA will be able to access the same lock by marshaling back to an MTA. - [SkippableFact] + [Fact] public async Task ReadLockTraversesAcrossSta() { - Skip.IfNot(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)); + Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.Windows), "Windows only"); using (await this.asyncLock.ReadLockAsync()) { var testComplete = new TaskCompletionSource(); @@ -3920,10 +3917,10 @@ public async Task ReadLockTraversesAcrossSta() } /// Verifies that when an MTA holding a lock traverses (via CallContext) to an STA that the STA will be able to access the same lock by requesting it and moving back to an MTA. - [SkippableFact] + [Fact] public async Task UpgradeableReadLockTraversesAcrossSta() { - Skip.IfNot(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)); + Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.Windows), "Windows only"); using (await this.asyncLock.UpgradeableReadLockAsync()) { @@ -3963,10 +3960,10 @@ public async Task UpgradeableReadLockTraversesAcrossSta() } /// Verifies that when an MTA holding a lock traverses (via CallContext) to an STA that the STA will be able to access the same lock by requesting it and moving back to an MTA. - [SkippableFact] + [Fact] public async Task WriteLockTraversesAcrossSta() { - Skip.IfNot(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)); + Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.Windows), "Windows only"); using (await this.asyncLock.WriteLockAsync()) { var testComplete = new TaskCompletionSource(); @@ -4382,30 +4379,34 @@ public async Task ReadLockAsync_OnCompleted_CapturesExecutionContext() [Fact] public async Task ReadLockAsync_UnsafeOnCompleted_DoesNotCaptureExecutionContext() { - var asyncLocal = new Microsoft.VisualStudio.Threading.AsyncLocal(); - asyncLocal.Value = "expected"; - AsyncReaderWriterLock.Awaiter? awaiter = this.asyncLock.ReadLockAsync().GetAwaiter(); - Assumes.False(awaiter.IsCompleted); - var testResultSource = new TaskCompletionSource(); - awaiter.UnsafeOnCompleted(delegate + // Apply some SynchronizationContext to ensure the issued lock will require us to yield. + using (new SynchronizationContext().Apply(checkForChangesOnRevert: false)) { - try + var asyncLocal = new Microsoft.VisualStudio.Threading.AsyncLocal(); + asyncLocal.Value = "expected"; + AsyncReaderWriterLock.Awaiter? awaiter = this.asyncLock.ReadLockAsync().GetAwaiter(); + Assumes.False(awaiter.IsCompleted); + TaskCompletionSource testResultSource = new(TaskCreationOptions.RunContinuationsAsynchronously); + awaiter.UnsafeOnCompleted(delegate { - using (awaiter.GetResult()) + try + { + using (awaiter.GetResult()) + { + Assert.Null(asyncLocal.Value); + testResultSource.SetResult(null); + } + } + catch (Exception ex) { - Assert.Null(asyncLocal.Value); - testResultSource.SetResult(null); + testResultSource.SetException(ex); } - } - catch (Exception ex) - { - testResultSource.SetException(ex); - } - finally - { - } - }); - await testResultSource.Task; + finally + { + } + }); + await testResultSource.Task; + } } [Fact(Skip = "Disabled after dependency updates introduced failures. See https://dev.azure.com/devdiv/DevDiv/_workitems/edit/1974921")] diff --git a/test/Microsoft.VisualStudio.Threading.Tests/AsyncReaderWriterResourceLockTests.cs b/test/Microsoft.VisualStudio.Threading.Tests/AsyncReaderWriterResourceLockTests.cs index 2b6fb8d15..da1e01462 100644 --- a/test/Microsoft.VisualStudio.Threading.Tests/AsyncReaderWriterResourceLockTests.cs +++ b/test/Microsoft.VisualStudio.Threading.Tests/AsyncReaderWriterResourceLockTests.cs @@ -7,9 +7,6 @@ using System.Threading; using System.Threading.Tasks; using Microsoft; -using Microsoft.VisualStudio.Threading; -using Xunit; -using Xunit.Abstractions; public class AsyncReaderWriterResourceLockTests : TestBase { diff --git a/test/Microsoft.VisualStudio.Threading.Tests/AsyncSemaphoreTests.cs b/test/Microsoft.VisualStudio.Threading.Tests/AsyncSemaphoreTests.cs index 5265569a9..7a5ffd2b1 100644 --- a/test/Microsoft.VisualStudio.Threading.Tests/AsyncSemaphoreTests.cs +++ b/test/Microsoft.VisualStudio.Threading.Tests/AsyncSemaphoreTests.cs @@ -7,9 +7,6 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.VisualStudio.Threading; -using Xunit; -using Xunit.Abstractions; public class AsyncSemaphoreTests : TestBase { diff --git a/test/Microsoft.VisualStudio.Threading.Tests/AwaitExtensionsTests.cs b/test/Microsoft.VisualStudio.Threading.Tests/AwaitExtensionsTests.cs index b2d5af6fb..1a8bad136 100644 --- a/test/Microsoft.VisualStudio.Threading.Tests/AwaitExtensionsTests.cs +++ b/test/Microsoft.VisualStudio.Threading.Tests/AwaitExtensionsTests.cs @@ -9,10 +9,7 @@ using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; -using Microsoft.VisualStudio.Threading; using Microsoft.Win32; -using Xunit; -using Xunit.Abstractions; #pragma warning disable CA1416 // Validate platform compatibility @@ -383,10 +380,10 @@ public async Task WaitForExit_NullArgument() await Assert.ThrowsAsync(() => AwaitExtensions.WaitForExitAsync(null!)); } - [SkippableFact] + [Fact] public async Task WaitForExitAsync_ExitCode() { - Skip.IfNot(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)); + Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.Windows), "Windows only"); Process p = Process.Start( new ProcessStartInfo("cmd.exe", "/c exit /b 55") { @@ -397,10 +394,10 @@ public async Task WaitForExitAsync_ExitCode() Assert.Equal(55, exitCode); } - [SkippableFact] + [Fact] public void WaitForExitAsync_AlreadyExited() { - Skip.IfNot(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)); + Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.Windows), "Windows only"); Process p = Process.Start( new ProcessStartInfo("cmd.exe", "/c exit /b 55") { @@ -613,10 +610,10 @@ public async Task SyncContext_Awaiter() } } - [SkippableFact] + [Fact] public async Task AwaitRegKeyChange() { - Skip.IfNot(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)); + Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.Windows), "Windows only"); using (var test = new RegKeyTest()) { Task changeWatcherTask = test.Key.WaitForChangeAsync(); @@ -626,10 +623,10 @@ public async Task AwaitRegKeyChange() } } - [SkippableFact] + [Fact] public async Task AwaitRegKeyChange_TwoAtOnce_SameKeyHandle() { - Skip.IfNot(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)); + Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.Windows), "Windows only"); using (var test = new RegKeyTest()) { Task changeWatcherTask1 = test.Key.WaitForChangeAsync(); @@ -641,10 +638,10 @@ public async Task AwaitRegKeyChange_TwoAtOnce_SameKeyHandle() } } - [SkippableFact] + [Fact] public async Task AwaitRegKeyChange_NoChange() { - Skip.IfNot(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)); + Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.Windows), "Windows only"); using (var test = new RegKeyTest()) { Task changeWatcherTask = test.Key.WaitForChangeAsync(cancellationToken: test.FinishedToken); @@ -656,10 +653,10 @@ public async Task AwaitRegKeyChange_NoChange() } } - [SkippableFact] + [Fact] public async Task AwaitRegKeyChange_WatchSubtree() { - Skip.IfNot(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)); + Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.Windows), "Windows only"); using (var test = new RegKeyTest()) { using (RegistryKey? subKey = test.CreateSubKey()) @@ -671,10 +668,10 @@ public async Task AwaitRegKeyChange_WatchSubtree() } } - [SkippableFact] + [Fact] public async Task AwaitRegKeyChange_KeyDeleted() { - Skip.IfNot(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)); + Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.Windows), "Windows only"); using (var test = new RegKeyTest()) { using (RegistryKey? subKey = test.CreateSubKey()) @@ -686,10 +683,10 @@ public async Task AwaitRegKeyChange_KeyDeleted() } } - [SkippableFact] + [Fact] public async Task AwaitRegKeyChange_NoWatchSubtree() { - Skip.IfNot(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)); + Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.Windows), "Windows only"); using (var test = new RegKeyTest()) { using (RegistryKey? subKey = test.CreateSubKey()) @@ -705,10 +702,10 @@ public async Task AwaitRegKeyChange_NoWatchSubtree() } } - [SkippableFact] + [Fact] public async Task AwaitRegKeyChange_Canceled() { - Skip.IfNot(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)); + Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.Windows), "Windows only"); using (var test = new RegKeyTest()) { var cts = new CancellationTokenSource(); @@ -727,10 +724,10 @@ public async Task AwaitRegKeyChange_Canceled() } } - [SkippableFact] + [Fact] public async Task AwaitRegKeyChange_KeyDisposedWhileWatching() { - Skip.IfNot(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)); + Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.Windows), "Windows only"); Task watchingTask; using (var test = new RegKeyTest()) { @@ -741,10 +738,10 @@ public async Task AwaitRegKeyChange_KeyDisposedWhileWatching() await watchingTask; } - [SkippableFact] + [Fact] public async Task AwaitRegKeyChange_CanceledAndImmediatelyDisposed() { - Skip.IfNot(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)); + Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.Windows), "Windows only"); Task watchingTask; CancellationToken expectedCancellationToken; using (var test = new RegKeyTest()) @@ -764,10 +761,10 @@ public async Task AwaitRegKeyChange_CanceledAndImmediatelyDisposed() } } - [SkippableFact] + [Fact] public async Task AwaitRegKeyChange_CallingThreadDestroyed() { - Skip.IfNot(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)); + Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.Windows), "Windows only"); using (var test = new RegKeyTest()) { // Start watching and be certain the thread that started watching is destroyed. @@ -789,10 +786,10 @@ public async Task AwaitRegKeyChange_CallingThreadDestroyed() } } - [SkippableFact] + [Fact] public async Task AwaitRegKeyChange_DoesNotPreventAppTerminationOnWin7() { - Skip.IfNot(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)); + Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.Windows), "Windows only"); string testExePath = Path.Combine( AppDomain.CurrentDomain.BaseDirectory!, "..", diff --git a/test/Microsoft.VisualStudio.Threading.Tests/CancellationTokenExtensionsTests.cs b/test/Microsoft.VisualStudio.Threading.Tests/CancellationTokenExtensionsTests.cs index 5a957f05b..2d483b9ec 100644 --- a/test/Microsoft.VisualStudio.Threading.Tests/CancellationTokenExtensionsTests.cs +++ b/test/Microsoft.VisualStudio.Threading.Tests/CancellationTokenExtensionsTests.cs @@ -4,9 +4,6 @@ using System; using System.Linq; using System.Threading; -using Microsoft.VisualStudio.Threading; -using Xunit; -using Xunit.Abstractions; public class CancellationTokenExtensionsTests : TestBase { diff --git a/test/Microsoft.VisualStudio.Threading.Tests/DelegatingJoinableTaskFactoryTests.cs b/test/Microsoft.VisualStudio.Threading.Tests/DelegatingJoinableTaskFactoryTests.cs index 9ca54fa96..2904d364d 100644 --- a/test/Microsoft.VisualStudio.Threading.Tests/DelegatingJoinableTaskFactoryTests.cs +++ b/test/Microsoft.VisualStudio.Threading.Tests/DelegatingJoinableTaskFactoryTests.cs @@ -7,9 +7,6 @@ using System.Threading; using System.Threading.Tasks; using Microsoft; -using Microsoft.VisualStudio.Threading; -using Xunit; -using Xunit.Abstractions; public class DelegatingJoinableTaskFactoryTests : JoinableTaskTestBase { @@ -156,7 +153,7 @@ protected override void WaitSynchronously(Task task) base.WaitSynchronously(task); } - protected override void PostToUnderlyingSynchronizationContext(System.Threading.SendOrPostCallback callback, object state) + protected override void PostToUnderlyingSynchronizationContext(SendOrPostCallback callback, object state) { this.addToLog(FactoryLogEntry.InnerPostToUnderlyingSynchronizationContext); base.PostToUnderlyingSynchronizationContext(callback, state); @@ -196,7 +193,7 @@ protected override void WaitSynchronously(Task task) base.WaitSynchronously(task); } - protected override void PostToUnderlyingSynchronizationContext(System.Threading.SendOrPostCallback callback, object state) + protected override void PostToUnderlyingSynchronizationContext(SendOrPostCallback callback, object state) { this.addToLog(FactoryLogEntry.OuterPostToUnderlyingSynchronizationContext); base.PostToUnderlyingSynchronizationContext(callback, state); diff --git a/test/Microsoft.VisualStudio.Threading.Tests/DispatcherExtensionsTests.cs b/test/Microsoft.VisualStudio.Threading.Tests/DispatcherExtensionsTests.cs index 49c05e0be..65d324840 100644 --- a/test/Microsoft.VisualStudio.Threading.Tests/DispatcherExtensionsTests.cs +++ b/test/Microsoft.VisualStudio.Threading.Tests/DispatcherExtensionsTests.cs @@ -9,8 +9,6 @@ using System.Windows.Threading; using Microsoft; using Microsoft.VisualStudio.Threading; -using Xunit; -using Xunit.Abstractions; public class DispatcherExtensionsTests : JoinableTaskTestBase { diff --git a/test/Microsoft.VisualStudio.Threading.Tests/InternalUtilitiesTests.cs b/test/Microsoft.VisualStudio.Threading.Tests/InternalUtilitiesTests.cs index 5c8f3d75f..bec84f2c4 100644 --- a/test/Microsoft.VisualStudio.Threading.Tests/InternalUtilitiesTests.cs +++ b/test/Microsoft.VisualStudio.Threading.Tests/InternalUtilitiesTests.cs @@ -3,8 +3,6 @@ using System.Collections.Generic; using System.Linq; -using Microsoft.VisualStudio.Threading; -using Xunit; public class InternalUtilitiesTests { diff --git a/test/Microsoft.VisualStudio.Threading.Tests/JoinableTaskAndAsyncReaderWriterLockTests.cs b/test/Microsoft.VisualStudio.Threading.Tests/JoinableTaskAndAsyncReaderWriterLockTests.cs index 2c05ec10f..33a233bfc 100644 --- a/test/Microsoft.VisualStudio.Threading.Tests/JoinableTaskAndAsyncReaderWriterLockTests.cs +++ b/test/Microsoft.VisualStudio.Threading.Tests/JoinableTaskAndAsyncReaderWriterLockTests.cs @@ -3,9 +3,6 @@ using System; using System.Threading.Tasks; -using Microsoft.VisualStudio.Threading; -using Xunit; -using Xunit.Abstractions; public class JoinableTaskAndAsyncReaderWriterLockTests : TestBase { diff --git a/test/Microsoft.VisualStudio.Threading.Tests/JoinableTaskCollectionTests.cs b/test/Microsoft.VisualStudio.Threading.Tests/JoinableTaskCollectionTests.cs index 02e3d8a7c..1cba90a05 100644 --- a/test/Microsoft.VisualStudio.Threading.Tests/JoinableTaskCollectionTests.cs +++ b/test/Microsoft.VisualStudio.Threading.Tests/JoinableTaskCollectionTests.cs @@ -4,9 +4,6 @@ using System; using System.Threading; using System.Threading.Tasks; -using Microsoft.VisualStudio.Threading; -using Xunit; -using Xunit.Abstractions; public class JoinableTaskCollectionTests : JoinableTaskTestBase { diff --git a/test/Microsoft.VisualStudio.Threading.Tests/JoinableTaskContextNodeTests.cs b/test/Microsoft.VisualStudio.Threading.Tests/JoinableTaskContextNodeTests.cs index 156fc0aea..62393635a 100644 --- a/test/Microsoft.VisualStudio.Threading.Tests/JoinableTaskContextNodeTests.cs +++ b/test/Microsoft.VisualStudio.Threading.Tests/JoinableTaskContextNodeTests.cs @@ -5,9 +5,6 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using Microsoft.VisualStudio.Threading; -using Xunit; -using Xunit.Abstractions; public class JoinableTaskContextNodeTests : JoinableTaskTestBase { diff --git a/test/Microsoft.VisualStudio.Threading.Tests/JoinableTaskContextTests.cs b/test/Microsoft.VisualStudio.Threading.Tests/JoinableTaskContextTests.cs index 2951b647c..b644fc158 100644 --- a/test/Microsoft.VisualStudio.Threading.Tests/JoinableTaskContextTests.cs +++ b/test/Microsoft.VisualStudio.Threading.Tests/JoinableTaskContextTests.cs @@ -8,9 +8,6 @@ using System.Threading.Tasks; using System.Xml.Linq; using Microsoft; -using Microsoft.VisualStudio.Threading; -using Xunit; -using Xunit.Abstractions; public class JoinableTaskContextTests : JoinableTaskTestBase { diff --git a/test/Microsoft.VisualStudio.Threading.Tests/JoinableTaskFactoryTests.cs b/test/Microsoft.VisualStudio.Threading.Tests/JoinableTaskFactoryTests.cs index 47ba640e3..7f05a3d5b 100644 --- a/test/Microsoft.VisualStudio.Threading.Tests/JoinableTaskFactoryTests.cs +++ b/test/Microsoft.VisualStudio.Threading.Tests/JoinableTaskFactoryTests.cs @@ -3,9 +3,6 @@ using System; using System.Threading.Tasks; -using Microsoft.VisualStudio.Threading; -using Xunit; -using Xunit.Abstractions; public class JoinableTaskFactoryTests : JoinableTaskTestBase { diff --git a/test/Microsoft.VisualStudio.Threading.Tests/JoinableTaskInternalsTests.cs b/test/Microsoft.VisualStudio.Threading.Tests/JoinableTaskInternalsTests.cs index 969fb62b9..d13235468 100644 --- a/test/Microsoft.VisualStudio.Threading.Tests/JoinableTaskInternalsTests.cs +++ b/test/Microsoft.VisualStudio.Threading.Tests/JoinableTaskInternalsTests.cs @@ -3,9 +3,6 @@ using System.Threading; using System.Threading.Tasks; -using Microsoft.VisualStudio.Threading; -using Xunit; -using Xunit.Abstractions; public class JoinableTaskInternalsTests : JoinableTaskTestBase { diff --git a/test/Microsoft.VisualStudio.Threading.Tests/JoinableTaskTestBase.cs b/test/Microsoft.VisualStudio.Threading.Tests/JoinableTaskTestBase.cs index 8868d0ec6..f415f93ba 100644 --- a/test/Microsoft.VisualStudio.Threading.Tests/JoinableTaskTestBase.cs +++ b/test/Microsoft.VisualStudio.Threading.Tests/JoinableTaskTestBase.cs @@ -9,8 +9,6 @@ using System.Threading.Tasks; using System.Xml.Linq; using Microsoft; -using Microsoft.VisualStudio.Threading; -using Xunit.Abstractions; public abstract class JoinableTaskTestBase : TestBase { diff --git a/test/Microsoft.VisualStudio.Threading.Tests/JoinableTaskTests.cs b/test/Microsoft.VisualStudio.Threading.Tests/JoinableTaskTests.cs index 15af17a7a..7264640fc 100644 --- a/test/Microsoft.VisualStudio.Threading.Tests/JoinableTaskTests.cs +++ b/test/Microsoft.VisualStudio.Threading.Tests/JoinableTaskTests.cs @@ -10,9 +10,6 @@ using System.Threading; using System.Threading.Tasks; using Microsoft; -using Microsoft.VisualStudio.Threading; -using Xunit; -using Xunit.Abstractions; public class JoinableTaskTests : JoinableTaskTestBase { @@ -1934,7 +1931,7 @@ public void SynchronousTaskStackMaintainedCorrectly() { this.asyncPump.Run(async delegate { - this.asyncPump.Run(() => Task.FromResult(true)); + this.asyncPump.Run(() => Task.FromResult(true)); await Task.Yield(); }); } @@ -2236,7 +2233,7 @@ public void BeginAsyncWithResultOnMTAKicksOffOtherAsyncPumpWorkCanCompleteSynchr Assert.False(joinable.Task.IsCompleted); int result = joinable.Join(); - Assert.Equal(5, result); + Assert.Equal(5, result); Assert.True(taskFinished); Assert.True(joinable.Task.IsCompleted); } @@ -2268,7 +2265,7 @@ public void Join_AlreadyCompletedWithPrecanceledArgument() [Fact] public void Join_AlreadyCompletedWithPrecanceledArgument_Generic() { - JoinableTask jt = this.asyncPump.RunAsync(() => Task.FromResult(0)); + JoinableTask jt = this.asyncPump.RunAsync(() => Task.FromResult(0)); Assert.Throws(() => jt.Join(new CancellationToken(canceled: true))); } @@ -2282,7 +2279,7 @@ public async Task JoinAsync_AlreadyCompletedWithPrecanceledArgument() [Fact] public async Task JoinAsync_AlreadyCompletedWithPrecanceledArgument_Generic() { - JoinableTask jt = this.asyncPump.RunAsync(() => Task.FromResult(0)); + JoinableTask jt = this.asyncPump.RunAsync(() => Task.FromResult(0)); await Assert.ThrowsAsync(() => jt.JoinAsync(new CancellationToken(canceled: true))); } @@ -2977,7 +2974,7 @@ await loPriFactory.RunAsync(async delegate hiPriFactory.DoModalLoopTillEmptyAndTaskCompleted(outer.Task, this.TimeoutToken); } - [SkippableFact] + [Fact] public void NestedFactoriesCanBeCollected() { WeakReference weakOuterFactory = this.NestedFactoriesCanBeCollected_Helper(); @@ -3765,7 +3762,7 @@ public void JoinAsyncShouldCompleteWithoutUIThreadAfterCancellation() // We expect to be able to block on the UI thread and the Task complete. // In completing, it will throw a TaskCanceledException, wrapped by an // AggregateException. If it 'hangs', it will timeout, returning false. - Assert.Throws(() => joinTask.Wait(AsyncDelay)); + Assert.Throws(() => joinTask.Wait(UnexpectedTimeout)); } [Fact] @@ -4491,7 +4488,7 @@ private WeakReference NestedFactoriesCanBeCollected_Helper() }); outerFactory.DoModalLoopTillEmptyAndTaskCompleted(outer.Task, this.TimeoutToken); - Skip.IfNot(outer.IsCompleted, "this is a product defect, but this test assumes this works to test something else."); + Assert.SkipUnless(outer.IsCompleted, "this is a product defect, but this test assumes this works to test something else."); // Allow the dispatcher to drain all messages that may be holding references. SynchronizationContext.Current!.Post(s => this.testFrame.Continue = false, null); diff --git a/test/Microsoft.VisualStudio.Threading.Tests/JoinableTaskTokenTests.cs b/test/Microsoft.VisualStudio.Threading.Tests/JoinableTaskTokenTests.cs index 25c078496..7d2e07360 100644 --- a/test/Microsoft.VisualStudio.Threading.Tests/JoinableTaskTokenTests.cs +++ b/test/Microsoft.VisualStudio.Threading.Tests/JoinableTaskTokenTests.cs @@ -4,9 +4,6 @@ using System; using System.Threading; using System.Threading.Tasks; -using Microsoft.VisualStudio.Threading; -using Xunit; -using Xunit.Abstractions; public class JoinableTaskTokenTests : JoinableTaskTestBase { @@ -171,7 +168,7 @@ public async Task RunAsyncOfT_AvoidsDeadlockWithParent(bool includeOtherContexts TaskCompletionSource tokenSource = new(); AsyncManualResetEvent releaseOuterTask = new(); - JoinableTask outerTask = this.asyncPump.RunAsync( + JoinableTask outerTask = this.asyncPump.RunAsync( async delegate { try @@ -199,7 +196,7 @@ async delegate this.Logger.WriteLine($"Token (modified): {token}"); } - JoinableTask innerTask = this.asyncPump.RunAsync( + JoinableTask innerTask = this.asyncPump.RunAsync( async delegate { await Task.Yield(); diff --git a/test/Microsoft.VisualStudio.Threading.Tests/ListOfOftenOneTests.cs b/test/Microsoft.VisualStudio.Threading.Tests/ListOfOftenOneTests.cs index e9bf81f4b..539f88190 100644 --- a/test/Microsoft.VisualStudio.Threading.Tests/ListOfOftenOneTests.cs +++ b/test/Microsoft.VisualStudio.Threading.Tests/ListOfOftenOneTests.cs @@ -2,9 +2,6 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System.Linq; -using Microsoft.VisualStudio.Threading; -using Xunit; -using Xunit.Abstractions; public class ListOfOftenOneTests : TestBase { @@ -34,11 +31,11 @@ public void EnumerationOfOne() using (ListOfOftenOne.Enumerator enumerator = this.list.GetEnumerator()) { Assert.True(enumerator.MoveNext()); - Assert.Equal(1, enumerator.Current.Data); + Assert.Equal(1, enumerator.Current.Data); Assert.False(enumerator.MoveNext()); enumerator.Reset(); Assert.True(enumerator.MoveNext()); - Assert.Equal(1, enumerator.Current.Data); + Assert.Equal(1, enumerator.Current.Data); Assert.False(enumerator.MoveNext()); } } @@ -51,15 +48,15 @@ public void EnumerationOfTwo() using (ListOfOftenOne.Enumerator enumerator = this.list.GetEnumerator()) { Assert.True(enumerator.MoveNext()); - Assert.Equal(1, enumerator.Current.Data); + Assert.Equal(1, enumerator.Current.Data); Assert.True(enumerator.MoveNext()); - Assert.Equal(2, enumerator.Current.Data); + Assert.Equal(2, enumerator.Current.Data); Assert.False(enumerator.MoveNext()); enumerator.Reset(); Assert.True(enumerator.MoveNext()); - Assert.Equal(1, enumerator.Current.Data); + Assert.Equal(1, enumerator.Current.Data); Assert.True(enumerator.MoveNext()); - Assert.Equal(2, enumerator.Current.Data); + Assert.Equal(2, enumerator.Current.Data); Assert.False(enumerator.MoveNext()); } } diff --git a/test/Microsoft.VisualStudio.Threading.Tests/Microsoft.VisualStudio.Threading.Tests.csproj b/test/Microsoft.VisualStudio.Threading.Tests/Microsoft.VisualStudio.Threading.Tests.csproj index b17c4787e..d92df35cd 100644 --- a/test/Microsoft.VisualStudio.Threading.Tests/Microsoft.VisualStudio.Threading.Tests.csproj +++ b/test/Microsoft.VisualStudio.Threading.Tests/Microsoft.VisualStudio.Threading.Tests.csproj @@ -1,8 +1,8 @@  net8.0 + Exe true - true true true @@ -28,14 +28,11 @@ - - - - + diff --git a/test/Microsoft.VisualStudio.Threading.Tests/NonConcurrentSynchronizationContextTests.cs b/test/Microsoft.VisualStudio.Threading.Tests/NonConcurrentSynchronizationContextTests.cs index 26afaae86..650a23f3b 100644 --- a/test/Microsoft.VisualStudio.Threading.Tests/NonConcurrentSynchronizationContextTests.cs +++ b/test/Microsoft.VisualStudio.Threading.Tests/NonConcurrentSynchronizationContextTests.cs @@ -2,14 +2,9 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; -using System.Collections.Generic; using System.Linq; -using System.Text; using System.Threading; using System.Threading.Tasks; -using Microsoft.VisualStudio.Threading; -using Xunit; -using Xunit.Abstractions; public class NonConcurrentSynchronizationContextTests : TestBase { diff --git a/test/Microsoft.VisualStudio.Threading.Tests/ProgressWithCompletionTests.cs b/test/Microsoft.VisualStudio.Threading.Tests/ProgressWithCompletionTests.cs index f2dd306fc..41f1c29f3 100644 --- a/test/Microsoft.VisualStudio.Threading.Tests/ProgressWithCompletionTests.cs +++ b/test/Microsoft.VisualStudio.Threading.Tests/ProgressWithCompletionTests.cs @@ -5,9 +5,6 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.VisualStudio.Threading; -using Xunit; -using Xunit.Abstractions; public class ProgressWithCompletionTests : TestBase { diff --git a/test/Microsoft.VisualStudio.Threading.Tests/RarelyRemoveItemSetTests.cs b/test/Microsoft.VisualStudio.Threading.Tests/RarelyRemoveItemSetTests.cs index fb4f79b14..d87d0c071 100644 --- a/test/Microsoft.VisualStudio.Threading.Tests/RarelyRemoveItemSetTests.cs +++ b/test/Microsoft.VisualStudio.Threading.Tests/RarelyRemoveItemSetTests.cs @@ -4,9 +4,6 @@ using System; using System.Linq; using System.Runtime.CompilerServices; -using Microsoft.VisualStudio.Threading; -using Xunit; -using Xunit.Abstractions; public class RarelyRemoveItemSetTests : TestBase { @@ -36,11 +33,11 @@ public void EnumerationOfOne() using (RarelyRemoveItemSet.Enumerator enumerator = this.list.EnumerateAndClear().GetEnumerator()) { Assert.True(enumerator.MoveNext()); - Assert.Equal(1, enumerator.Current.Data); + Assert.Equal(1, enumerator.Current.Data); Assert.False(enumerator.MoveNext()); enumerator.Reset(); Assert.True(enumerator.MoveNext()); - Assert.Equal(1, enumerator.Current.Data); + Assert.Equal(1, enumerator.Current.Data); Assert.False(enumerator.MoveNext()); } } @@ -53,15 +50,15 @@ public void EnumerationOfTwo() using (RarelyRemoveItemSet.Enumerator enumerator = this.list.EnumerateAndClear().GetEnumerator()) { Assert.True(enumerator.MoveNext()); - Assert.Equal(1, enumerator.Current.Data); + Assert.Equal(1, enumerator.Current.Data); Assert.True(enumerator.MoveNext()); - Assert.Equal(2, enumerator.Current.Data); + Assert.Equal(2, enumerator.Current.Data); Assert.False(enumerator.MoveNext()); enumerator.Reset(); Assert.True(enumerator.MoveNext()); - Assert.Equal(1, enumerator.Current.Data); + Assert.Equal(1, enumerator.Current.Data); Assert.True(enumerator.MoveNext()); - Assert.Equal(2, enumerator.Current.Data); + Assert.Equal(2, enumerator.Current.Data); Assert.False(enumerator.MoveNext()); } } diff --git a/test/Microsoft.VisualStudio.Threading.Tests/ReentrantSemaphoreJTFTests.cs b/test/Microsoft.VisualStudio.Threading.Tests/ReentrantSemaphoreJTFTests.cs index 7ec4ac0d8..6c001e1c2 100644 --- a/test/Microsoft.VisualStudio.Threading.Tests/ReentrantSemaphoreJTFTests.cs +++ b/test/Microsoft.VisualStudio.Threading.Tests/ReentrantSemaphoreJTFTests.cs @@ -6,9 +6,6 @@ using System.Threading; using System.Threading.Tasks; using Microsoft; -using Microsoft.VisualStudio.Threading; -using Xunit; -using Xunit.Abstractions; public class ReentrantSemaphoreJTFTests : ReentrantSemaphoreTestBase { diff --git a/test/Microsoft.VisualStudio.Threading.Tests/ReentrantSemaphoreNonJTFTests.cs b/test/Microsoft.VisualStudio.Threading.Tests/ReentrantSemaphoreNonJTFTests.cs index 5a1ab9ebd..4935e0b64 100644 --- a/test/Microsoft.VisualStudio.Threading.Tests/ReentrantSemaphoreNonJTFTests.cs +++ b/test/Microsoft.VisualStudio.Threading.Tests/ReentrantSemaphoreNonJTFTests.cs @@ -2,9 +2,6 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System.Threading.Tasks; -using Microsoft.VisualStudio.Threading; -using Xunit; -using Xunit.Abstractions; public class ReentrantSemaphoreNonJTFTests : ReentrantSemaphoreTestBase { diff --git a/test/Microsoft.VisualStudio.Threading.Tests/ReentrantSemaphoreTestBase.cs b/test/Microsoft.VisualStudio.Threading.Tests/ReentrantSemaphoreTestBase.cs index 8e58d4317..494de17d1 100644 --- a/test/Microsoft.VisualStudio.Threading.Tests/ReentrantSemaphoreTestBase.cs +++ b/test/Microsoft.VisualStudio.Threading.Tests/ReentrantSemaphoreTestBase.cs @@ -6,9 +6,6 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.VisualStudio.Threading; -using Xunit; -using Xunit.Abstractions; public abstract class ReentrantSemaphoreTestBase : TestBase, IDisposable { diff --git a/test/Microsoft.VisualStudio.Threading.Tests/SingleThreadedSynchronizationContextTests.cs b/test/Microsoft.VisualStudio.Threading.Tests/SingleThreadedSynchronizationContextTests.cs index 7cd17668d..7e9e5ec44 100644 --- a/test/Microsoft.VisualStudio.Threading.Tests/SingleThreadedSynchronizationContextTests.cs +++ b/test/Microsoft.VisualStudio.Threading.Tests/SingleThreadedSynchronizationContextTests.cs @@ -4,9 +4,6 @@ using System; using System.Reflection; using System.Threading.Tasks; -using Microsoft.VisualStudio.Threading; -using Xunit; -using Xunit.Abstractions; public class SingleThreadedSynchronizationContextTests : TestBase { diff --git a/test/Microsoft.VisualStudio.Threading.Tests/SingleThreadedTestSynchronizationContext.cs b/test/Microsoft.VisualStudio.Threading.Tests/SingleThreadedTestSynchronizationContext.cs index 6fd9f5646..0bd798d8a 100644 --- a/test/Microsoft.VisualStudio.Threading.Tests/SingleThreadedTestSynchronizationContext.cs +++ b/test/Microsoft.VisualStudio.Threading.Tests/SingleThreadedTestSynchronizationContext.cs @@ -8,7 +8,6 @@ using System.Diagnostics.CodeAnalysis; using System.Threading; using Microsoft; -using Microsoft.VisualStudio.Threading; #if UseWpfContext using System.Windows.Threading; #endif diff --git a/test/Microsoft.VisualStudio.Threading.Tests/TestBase.cs b/test/Microsoft.VisualStudio.Threading.Tests/TestBase.cs index 5b7b6ff4d..d3a837504 100644 --- a/test/Microsoft.VisualStudio.Threading.Tests/TestBase.cs +++ b/test/Microsoft.VisualStudio.Threading.Tests/TestBase.cs @@ -8,9 +8,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft; -using Microsoft.VisualStudio.Threading; -using Xunit; -using Xunit.Abstractions; +using Xunit.Sdk; public abstract class TestBase { @@ -22,7 +20,7 @@ public abstract class TestBase /// The maximum length of time to wait for something that we expect will happen /// within the timeout. /// - protected static readonly TimeSpan UnexpectedTimeout = Debugger.IsAttached ? Timeout.InfiniteTimeSpan : TimeSpan.FromSeconds(10); + protected static readonly TimeSpan UnexpectedTimeout = Debugger.IsAttached ? Timeout.InfiniteTimeSpan : TimeSpan.FromSeconds(15); /// /// The maximum length of time to wait for something that we do not expect will happen @@ -339,7 +337,7 @@ protected void ExecuteOnDispatcher(Func action) /// A task whose result is if test execution is already isolated and should therefore proceed with the body of the test, /// or after the isolated instance of the test has completed execution. /// - /// Thrown if the isolated test result is a Failure. + /// Thrown if the isolated test result is a Failure. /// Thrown if on a platform that we do not yet support test isolation on. protected Task ExecuteInIsolationAsync([CallerMemberName] string testMethodName = null!) { @@ -355,7 +353,7 @@ protected Task ExecuteInIsolationAsync([CallerMemberName] string testMetho /// if test execution is already isolated and should therefore proceed with the body of the test, /// or after the isolated instance of the test has completed execution. /// - /// Thrown if the isolated test result is a Failure. + /// Thrown if the isolated test result is a Failure. /// Thrown if on a platform that we do not yet support test isolation on. protected bool ExecuteInIsolation([CallerMemberName] string testMethodName = null!) { diff --git a/test/Microsoft.VisualStudio.Threading.Tests/TestBaseTests.cs b/test/Microsoft.VisualStudio.Threading.Tests/TestBaseTests.cs index 52853bcb0..26ef0eb7f 100644 --- a/test/Microsoft.VisualStudio.Threading.Tests/TestBaseTests.cs +++ b/test/Microsoft.VisualStudio.Threading.Tests/TestBaseTests.cs @@ -6,9 +6,6 @@ using System.Threading; using System.Threading.Tasks; using Microsoft; -using Microsoft.VisualStudio.Threading; -using Xunit; -using Xunit.Abstractions; using Xunit.Sdk; public class TestBaseTests : TestBase @@ -18,10 +15,10 @@ public TestBaseTests(ITestOutputHelper logger) { } - [SkippableFact] + [Fact] public void ExecuteOnSTA_ExecutesDelegateOnSTA() { - Skip.IfNot(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)); + Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.Windows), "Windows only"); bool executed = false; this.ExecuteOnSTA(delegate { @@ -32,10 +29,10 @@ public void ExecuteOnSTA_ExecutesDelegateOnSTA() Assert.True(executed); } - [SkippableFact] + [Fact] public void ExecuteOnSTA_PropagatesExceptions() { - Skip.IfNot(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)); + Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.Windows), "Windows only"); Assert.Throws(() => this.ExecuteOnSTA(() => { throw new ApplicationException(); @@ -90,7 +87,7 @@ public void ExecuteOnDispatcher_PropagatesExceptions() })); } - [SkippableFact] + [Fact] [Trait("TestCategory", "FailsInCloudTest")] public async Task ExecuteInIsolation_PassingTest() { @@ -100,7 +97,7 @@ public async Task ExecuteInIsolation_PassingTest() } } - [SkippableFact] + [Fact] public async Task ExecuteInIsolation_FailingTest() { bool executeHere; diff --git a/test/Microsoft.VisualStudio.Threading.Tests/TestUtilities.cs b/test/Microsoft.VisualStudio.Threading.Tests/TestUtilities.cs index 28844c1a1..1c7872500 100644 --- a/test/Microsoft.VisualStudio.Threading.Tests/TestUtilities.cs +++ b/test/Microsoft.VisualStudio.Threading.Tests/TestUtilities.cs @@ -10,9 +10,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft; -using Microsoft.VisualStudio.Threading; -using Xunit; -using Xunit.Abstractions; +using Xunit.Sdk; internal static class TestUtilities { @@ -69,7 +67,7 @@ internal static T[] ConcurrencyTest(Func action, int concurrency = -1) concurrency = Environment.ProcessorCount; } - Skip.If(Environment.ProcessorCount < concurrency, $"The test machine does not have enough CPU cores to exercise a concurrency level of {concurrency}"); + Assert.SkipWhen(Environment.ProcessorCount < concurrency, $"The test machine does not have enough CPU cores to exercise a concurrency level of {concurrency}"); // We use a barrier to guarantee that all threads are fully ready to // execute the provided function at precisely the same time. @@ -94,11 +92,10 @@ internal static T[] ConcurrencyTest(Func action, int concurrency = -1) internal static DebugAssertionRevert DisableAssertionDialog() { #if NETFRAMEWORK - DefaultTraceListener? listener = Debug.Listeners.OfType().FirstOrDefault(); - if (listener is object) - { - listener.AssertUiEnabled = false; - } + Debug.Listeners.OfType().FirstOrDefault()?.AssertUiEnabled = false; + + // Xunit v3 adds a listener that throws on assertions; remove it so we can test actual runtime functionality of the library. + Debug.Listeners.Remove("xUnit.net"); #else Trace.Listeners.Clear(); #endif @@ -170,7 +167,7 @@ internal static IDisposable StarveThreadpool() /// A task whose result is if test execution is already isolated and should therefore proceed with the body of the test, /// or after the isolated instance of the test has completed execution. /// - /// Thrown if the isolated test result is a Failure. + /// Thrown if the isolated test result is a Failure. /// Thrown if on a platform that we do not yet support test isolation on. internal static Task ExecuteInIsolationAsync(object testClass, string testMethodName, ITestOutputHelper logger) { @@ -189,7 +186,7 @@ internal static Task ExecuteInIsolationAsync(object testClass, string test /// A task whose result is if test execution is already isolated and should therefore proceed with the body of the test, /// or after the isolated instance of the test has completed execution. /// - /// Thrown if the isolated test result is a Failure. + /// Thrown if the isolated test result is a Failure. /// Thrown if on a platform that we do not yet support test isolation on. #pragma warning disable CA1801 // Review unused parameters internal static Task ExecuteInIsolationAsync(string testClassName, string testMethodName, ITestOutputHelper logger) @@ -248,7 +245,7 @@ internal static Task ExecuteInIsolationAsync(string testClassName, string switch (t.Result) { case IsolatedTestHost.ExitCode.TestSkipped: - throw new SkipException("Test skipped. See output of isolated task for details."); + throw SkipException.ForSkip("Test skipped. See output of isolated task for details."); case IsolatedTestHost.ExitCode.TestPassed: default: Assert.Equal(IsolatedTestHost.ExitCode.TestPassed, t.Result); @@ -259,7 +256,7 @@ internal static Task ExecuteInIsolationAsync(string testClassName, string }, TaskScheduler.Default); #else - return Task.FromException(new SkipException("Test isolation is not yet supported on this platform.")); + return Task.FromException(SkipException.ForSkip("Test isolation is not yet supported on this platform.")); #endif } diff --git a/test/Microsoft.VisualStudio.Threading.Tests/TestUtilitiesTests.cs b/test/Microsoft.VisualStudio.Threading.Tests/TestUtilitiesTests.cs index 109fb3b6c..82a530f1d 100644 --- a/test/Microsoft.VisualStudio.Threading.Tests/TestUtilitiesTests.cs +++ b/test/Microsoft.VisualStudio.Threading.Tests/TestUtilitiesTests.cs @@ -2,8 +2,6 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System.Threading.Tasks; -using Microsoft.VisualStudio.Threading; -using Xunit; public class TestUtilitiesTests { diff --git a/test/Microsoft.VisualStudio.Threading.Tests/ThreadingToolsTests.cs b/test/Microsoft.VisualStudio.Threading.Tests/ThreadingToolsTests.cs index aec072c82..a670da2c9 100644 --- a/test/Microsoft.VisualStudio.Threading.Tests/ThreadingToolsTests.cs +++ b/test/Microsoft.VisualStudio.Threading.Tests/ThreadingToolsTests.cs @@ -5,9 +5,6 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.VisualStudio.Threading; -using Xunit; -using Xunit.Abstractions; public class ThreadingToolsTests : TestBase { @@ -118,7 +115,7 @@ public void WithCancellationOfPrecanceledTaskOfT() Assert.Same(tcs.Task, tcs.Task.WithCancellation(cts.Token)); } - [SkippableFact] + [Fact] public void WithCancellationAndPrecancelledToken() { var tcs = new TaskCompletionSource(); diff --git a/test/Microsoft.VisualStudio.Threading.Tests/TplExtensionsTests.cs b/test/Microsoft.VisualStudio.Threading.Tests/TplExtensionsTests.cs index aa241bd84..4d0429637 100644 --- a/test/Microsoft.VisualStudio.Threading.Tests/TplExtensionsTests.cs +++ b/test/Microsoft.VisualStudio.Threading.Tests/TplExtensionsTests.cs @@ -6,9 +6,6 @@ using System.Threading; using System.Threading.Tasks; using System.Threading.Tasks.Sources; -using Microsoft.VisualStudio.Threading; -using Xunit; -using Xunit.Abstractions; using TplExtensions = Microsoft.VisualStudio.Threading.TplExtensions; public class TplExtensionsTests : TestBase @@ -1077,7 +1074,7 @@ public void WithTimeout_MinusOneMeansInfiniteTimeout(bool generic) { var tcs = new TaskCompletionSource(); Task? timeoutTask = generic - ? TplExtensions.WithTimeout(tcs.Task, TimeSpan.FromMilliseconds(-1)) + ? TplExtensions.WithTimeout(tcs.Task, TimeSpan.FromMilliseconds(-1)) : TplExtensions.WithTimeout((Task)tcs.Task, TimeSpan.FromMilliseconds(-1)); Assert.False(timeoutTask.IsCompleted); await Task.Delay(AsyncDelay / 2); diff --git a/test/Microsoft.VisualStudio.Threading.Tests/Usings.cs b/test/Microsoft.VisualStudio.Threading.Tests/Usings.cs new file mode 100644 index 000000000..f10604229 --- /dev/null +++ b/test/Microsoft.VisualStudio.Threading.Tests/Usings.cs @@ -0,0 +1,5 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +global using Microsoft.VisualStudio.Threading; +global using Xunit; diff --git a/test/Microsoft.VisualStudio.Threading.Tests/ValidityTests.cs b/test/Microsoft.VisualStudio.Threading.Tests/ValidityTests.cs index 8af8ab8dc..176e1de45 100644 --- a/test/Microsoft.VisualStudio.Threading.Tests/ValidityTests.cs +++ b/test/Microsoft.VisualStudio.Threading.Tests/ValidityTests.cs @@ -2,8 +2,6 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System.Reflection; -using Microsoft.VisualStudio.Threading; -using Xunit; public class ValidityTests { diff --git a/test/Microsoft.VisualStudio.Threading.Tests/WeakKeyDictionaryTests.cs b/test/Microsoft.VisualStudio.Threading.Tests/WeakKeyDictionaryTests.cs index 9c8e17dcf..c533a47cd 100644 --- a/test/Microsoft.VisualStudio.Threading.Tests/WeakKeyDictionaryTests.cs +++ b/test/Microsoft.VisualStudio.Threading.Tests/WeakKeyDictionaryTests.cs @@ -5,9 +5,6 @@ using System.Collections.Generic; using System.Linq; using System.Runtime.CompilerServices; -using Microsoft.VisualStudio.Threading; -using Xunit; -using Xunit.Abstractions; /// /// Tests for the weak dictionary class. diff --git a/tools/artifacts/coverageResults.ps1 b/tools/artifacts/coverageResults.ps1 index 8c68216ed..1aadbb747 100644 --- a/tools/artifacts/coverageResults.ps1 +++ b/tools/artifacts/coverageResults.ps1 @@ -1,25 +1,26 @@ -$RepoRoot = [System.IO.Path]::GetFullPath("$PSScriptRoot\..\..") +$RepoRoot = Resolve-Path "$PSScriptRoot\..\.." -$coverageFiles = @(Get-ChildItem "$RepoRoot/test/*.cobertura.xml" -Recurse | Where {$_.FullName -notlike "*/In/*" -and $_.FullName -notlike "*\In\*" }) +$coverageFilesUnderRoot = @(Get-ChildItem "$RepoRoot/*.cobertura.xml" -Recurse | Where-Object {$_.FullName -notlike "*/In/*" -and $_.FullName -notlike "*\In\*" }) + +# Under MTP, coverage files are written directly to the artifacts output directory, +# so we need to look there too. +$ArtifactStagingFolder = & "$PSScriptRoot/../Get-ArtifactsStagingDirectory.ps1" +$directTestLogs = Join-Path $ArtifactStagingFolder test_logs +$coverageFilesUnderArtifacts = if (Test-Path $directTestLogs) { @(Get-ChildItem "$directTestLogs/*.cobertura.xml" -Recurse) } else { @() } # Prepare code coverage reports for merging on another machine -$repoRoot = $env:SYSTEM_DEFAULTWORKINGDIRECTORY -if (!$repoRoot) { $repoRoot = $env:GITHUB_WORKSPACE } -if ($repoRoot) { - Write-Host "Substituting $repoRoot with `"{reporoot}`"" - $coverageFiles |% { - $content = Get-Content -LiteralPath $_ |% { $_ -Replace [regex]::Escape($repoRoot), "{reporoot}" } - Set-Content -LiteralPath $_ -Value $content -Encoding UTF8 - } -} else { - Write-Warning "coverageResults: Cloud build not detected. Machine-neutral token replacement skipped." +Write-Host "Substituting $repoRoot with `"{reporoot}`"" +@($coverageFilesUnderRoot + $coverageFilesUnderArtifacts) |? { $_ }|% { + $content = Get-Content -LiteralPath $_ |% { $_ -Replace [regex]::Escape($repoRoot), "{reporoot}" } + Set-Content -LiteralPath $_ -Value $content -Encoding UTF8 } if (!((Test-Path $RepoRoot\bin) -and (Test-Path $RepoRoot\obj))) { return } @{ + $directTestLogs = $coverageFilesUnderArtifacts; $RepoRoot = ( - $coverageFiles + + $coverageFilesUnderRoot + (Get-ChildItem "$RepoRoot\obj\*.cs" -Recurse) ); } diff --git a/tools/artifacts/testResults.ps1 b/tools/artifacts/testResults.ps1 index 5310fb52a..a841967e8 100644 --- a/tools/artifacts/testResults.ps1 +++ b/tools/artifacts/testResults.ps1 @@ -4,7 +4,8 @@ Param( $result = @{} -$testRoot = Resolve-Path "$PSScriptRoot\..\..\test" +$RepoRoot = Resolve-Path "$PSScriptRoot\..\.." +$testRoot = Join-Path $RepoRoot test $result[$testRoot] = (Get-ChildItem "$testRoot\TestResults" -Recurse -Directory | Get-ChildItem -Recurse -File) $artifactStaging = & "$PSScriptRoot/../Get-ArtifactsStagingDirectory.ps1" diff --git a/tools/dotnet-test-cloud.ps1 b/tools/dotnet-test-cloud.ps1 index 51919726f..b79fde6ab 100644 --- a/tools/dotnet-test-cloud.ps1 +++ b/tools/dotnet-test-cloud.ps1 @@ -25,6 +25,7 @@ Param( $RepoRoot = (Resolve-Path "$PSScriptRoot/..").Path $ArtifactStagingFolder = & "$PSScriptRoot/Get-ArtifactsStagingDirectory.ps1" +$OnCI = ($env:CI -or $env:TF_BUILD) $dotnet = 'dotnet' if ($x86) { @@ -45,29 +46,60 @@ if ($x86) { } $testBinLog = Join-Path $ArtifactStagingFolder (Join-Path build_logs test.binlog) -$testDiagLog = Join-Path $ArtifactStagingFolder (Join-Path test_logs diag.log) +$testLogs = Join-Path $ArtifactStagingFolder test_logs $extraArgs = @() if ($IsLinux -or $IsMacOS) { $extraArgs += '-p:Platform=NonWindows' } -& $dotnet test $RepoRoot ` - --no-build ` - -c $Configuration ` - --filter "TestCategory!=FailsInCloudTest" ` - --collect "Code Coverage;Format=cobertura" ` - --settings "$PSScriptRoot/test.runsettings" ` - --blame-hang-timeout 60s ` - --blame-crash ` - -bl:"$testBinLog" ` - --diag "$testDiagLog;TraceLevel=info" ` - --logger trx ` - @extraArgs ` +$globalJson = Get-Content $PSScriptRoot/../global.json | ConvertFrom-Json +$isMTP = $globalJson.test.runner -eq 'Microsoft.Testing.Platform' +if ($isMTP) { + if ($OnCI) { $extraArgs += '--no-progress' } + & $dotnet test --solution $RepoRoot ` + --no-build ` + -c $Configuration ` + -bl:"$testBinLog" ` + --filter-not-trait 'TestCategory=FailsInCloudTest' ` + --coverage ` + --coverage-output-format cobertura ` + --coverage-settings "$PSScriptRoot/test.runsettings" ` + --hangdump ` + --hangdump-timeout 60s ` + --crashdump ` + --diagnostic ` + --diagnostic-output-directory $testLogs ` + --diagnostic-verbosity Information ` + --results-directory $testLogs ` + --report-trx ` + @extraArgs + + $trxFiles = Get-ChildItem -Recurse -Path $testLogs\*.trx +} else { + $testDiagLog = Join-Path $ArtifactStagingFolder (Join-Path test_logs diag.log) + & $dotnet test $RepoRoot ` + --no-build ` + -c $Configuration ` + --filter "TestCategory!=FailsInCloudTest" ` + --collect "Code Coverage;Format=cobertura" ` + --settings "$PSScriptRoot/test.runsettings" ` + --blame-hang-timeout 60s ` + --blame-crash ` + -bl:"$testBinLog" ` + --diag "$testDiagLog;TraceLevel=info" ` + --logger trx ` + @extraArgs + + $trxFiles = Get-ChildItem -Recurse -Path $RepoRoot\test\*.trx +} $unknownCounter = 0 -Get-ChildItem -Recurse -Path $RepoRoot\test\*.trx |% { - Copy-Item $_ -Destination $ArtifactStagingFolder/test_logs/ +$trxFiles |% { + New-Item $testLogs -ItemType Directory -Force | Out-Null + if (!($_.FullName.StartsWith($testLogs))) { + Copy-Item $_ -Destination $testLogs + } if ($PublishResults) { $x = [xml](Get-Content -LiteralPath $_)