From ba60d75bbc008d8263e844c1d6c25d5e43c18a67 Mon Sep 17 00:00:00 2001 From: Mitchell Hwang Date: Fri, 10 Jul 2020 08:41:06 -0400 Subject: [PATCH] [wasm] Enable System.Threading.Channels.Tests (#38849) * [wasm] Enable System.Threading.Channels.Tests and skip hangs * [wasm] Skip failing tests in System.Threading.Channels.Tests Co-authored-by: Mitchell Hwang --- .../tests/BoundedChannelTests.cs | 16 ++++-- .../tests/ChannelTestBase.cs | 66 +++++++++++----------- .../tests/ChannelTestBase.netcoreapp.cs | 14 ++--- .../tests/ChannelTests.cs | 6 +- 4 files changed, 54 insertions(+), 48 deletions(-) diff --git a/src/libraries/System.Threading.Channels/tests/BoundedChannelTests.cs b/src/libraries/System.Threading.Channels/tests/BoundedChannelTests.cs index d5e8495..4c8989d 100644 --- a/src/libraries/System.Threading.Channels/tests/BoundedChannelTests.cs +++ b/src/libraries/System.Threading.Channels/tests/BoundedChannelTests.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Threading.Tasks; +using Microsoft.DotNet.XUnitExtensions; using Xunit; namespace System.Threading.Channels.Tests @@ -176,7 +177,7 @@ namespace System.Threading.Channels.Tests Assert.Equal(0, result); } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] + [Fact] public async Task TryWrite_DropNewest_WrappedAroundInternalQueue() { var c = Channel.CreateBounded(new BoundedChannelOptions(3) { FullMode = BoundedChannelFullMode.DropNewest }); @@ -248,7 +249,7 @@ namespace System.Threading.Channels.Tests Assert.Equal(0, result); } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] + [Fact] public async Task CancelPendingWrite_Reading_DataTransferredFromCorrectWriter() { var c = Channel.CreateBounded(1); @@ -370,7 +371,7 @@ namespace System.Threading.Channels.Tests Assert.Equal((NumItems * (NumItems + 1L)) / 2, readTotal); } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] + [Fact] public async Task WaitToWriteAsync_AfterFullThenRead_ReturnsTrue() { var c = Channel.CreateBounded(1); @@ -408,11 +409,16 @@ namespace System.Threading.Channels.Tests r.GetAwaiter().GetResult(); } - [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] + [ConditionalTheory] [InlineData(false)] [InlineData(true)] public void AllowSynchronousContinuations_CompletionTask_ContinuationsInvokedAccordingToSetting(bool allowSynchronousContinuations) { + if (!allowSynchronousContinuations && !PlatformDetection.IsThreadingSupported) + { + throw new SkipTestException(nameof(PlatformDetection.IsThreadingSupported)); + } + var c = Channel.CreateBounded(new BoundedChannelOptions(1) { AllowSynchronousContinuations = allowSynchronousContinuations }); int expectedId = Environment.CurrentManagedThreadId; @@ -426,7 +432,7 @@ namespace System.Threading.Channels.Tests r.GetAwaiter().GetResult(); } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] + [Fact] public async Task TryWrite_NoBlockedReaders_WaitingReader_WaiterNotified() { Channel c = CreateChannel(); diff --git a/src/libraries/System.Threading.Channels/tests/ChannelTestBase.cs b/src/libraries/System.Threading.Channels/tests/ChannelTestBase.cs index 0b9a6787..fd2dbed 100644 --- a/src/libraries/System.Threading.Channels/tests/ChannelTestBase.cs +++ b/src/libraries/System.Threading.Channels/tests/ChannelTestBase.cs @@ -66,7 +66,7 @@ namespace System.Threading.Channels.Tests Assert.Equal(TaskStatus.RanToCompletion, completion.Status); } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] + [Fact] public async Task Complete_AfterEmpty_NoWaiters_TriggersCompletion() { Channel c = CreateChannel(); @@ -74,7 +74,7 @@ namespace System.Threading.Channels.Tests await c.Reader.Completion; } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] + [Fact] public async Task Complete_AfterEmpty_WaitingReader_TriggersCompletion() { Channel c = CreateChannel(); @@ -84,7 +84,7 @@ namespace System.Threading.Channels.Tests await Assert.ThrowsAnyAsync(() => r); } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] + [Fact] public async Task Complete_BeforeEmpty_WaitingReaders_TriggersCompletion() { Channel c = CreateChannel(); @@ -111,7 +111,7 @@ namespace System.Threading.Channels.Tests Assert.False(c.Writer.TryComplete()); } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] + [Fact] public async Task TryComplete_ErrorsPropage() { Channel c; @@ -325,7 +325,7 @@ namespace System.Threading.Channels.Tests Assert.True(write.Result); } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] + [Fact] public async Task WaitToWriteAsync_ManyConcurrent_SatisifedByReaders() { if (RequiresSingleReader || RequiresSingleWriter) @@ -374,7 +374,7 @@ namespace System.Threading.Channels.Tests Assert.False(c.Writer.TryWrite(42)); } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] + [Fact] public async Task WriteAsync_AfterComplete_ThrowsException() { Channel c = CreateChannel(); @@ -382,7 +382,7 @@ namespace System.Threading.Channels.Tests await Assert.ThrowsAnyAsync(async () => await c.Writer.WriteAsync(42)); } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] + [Fact] public async Task Complete_WithException_PropagatesToCompletion() { Channel c = CreateChannel(); @@ -391,7 +391,7 @@ namespace System.Threading.Channels.Tests Assert.Same(exc, await Assert.ThrowsAsync(() => c.Reader.Completion)); } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] + [Fact] public async Task Complete_WithCancellationException_PropagatesToCompletion() { Channel c = CreateChannel(); @@ -406,7 +406,7 @@ namespace System.Threading.Channels.Tests await AssertCanceled(c.Reader.Completion, cts.Token); } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] + [Fact] public async Task Complete_WithException_PropagatesToExistingWriter() { Channel c = CreateFullChannel(); @@ -419,7 +419,7 @@ namespace System.Threading.Channels.Tests } } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] + [Fact] public async Task Complete_WithException_PropagatesToNewWriter() { Channel c = CreateChannel(); @@ -429,7 +429,7 @@ namespace System.Threading.Channels.Tests Assert.Same(exc, (await Assert.ThrowsAsync(async () => await write)).InnerException); } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] + [Fact] public async Task Complete_WithException_PropagatesToExistingWaitingReader() { Channel c = CreateChannel(); @@ -439,7 +439,7 @@ namespace System.Threading.Channels.Tests await Assert.ThrowsAsync(async () => await read); } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] + [Fact] public async Task Complete_WithException_PropagatesToNewWaitingReader() { Channel c = CreateChannel(); @@ -449,7 +449,7 @@ namespace System.Threading.Channels.Tests await Assert.ThrowsAsync(async () => await read); } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] + [Fact] public async Task Complete_WithException_PropagatesToNewWaitingWriter() { Channel c = CreateChannel(); @@ -523,7 +523,7 @@ namespace System.Threading.Channels.Tests Assert.True(waitTask.IsCanceled); } - [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] + [Theory] [InlineData(false)] [InlineData(true)] public async Task WaitToReadAsync_DataWritten_CompletesSuccessfully(bool cancelable) @@ -539,7 +539,7 @@ namespace System.Threading.Channels.Tests Assert.True(await read); } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] + [Fact] public async Task WaitToReadAsync_NoDataWritten_Canceled_CompletesAsCanceled() { Channel c = CreateChannel(); @@ -551,7 +551,7 @@ namespace System.Threading.Channels.Tests await Assert.ThrowsAnyAsync(async () => await read); } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] + [Fact] public async Task ReadAsync_ThenWriteAsync_Succeeds() { Channel c = CreateChannel(); @@ -565,7 +565,7 @@ namespace System.Threading.Channels.Tests Assert.Equal(42, await r); } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] + [Fact] public async Task WriteAsync_ReadAsync_Succeeds() { Channel c = CreateChannel(); @@ -593,7 +593,7 @@ namespace System.Threading.Channels.Tests Assert.True(readTask.IsCanceled); } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] + [Fact] public async Task ReadAsync_Canceled_CanceledAsynchronously() { Channel c = CreateChannel(); @@ -612,7 +612,7 @@ namespace System.Threading.Channels.Tests } } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] + [Fact] public async Task ReadAsync_WriteAsync_ManyConcurrentReaders_SerializedWriters_Success() { if (RequiresSingleReader) @@ -632,7 +632,7 @@ namespace System.Threading.Channels.Tests Assert.Equal((Items * (Items - 1)) / 2, Enumerable.Sum(await Task.WhenAll(readers.Select(r => r.AsTask())))); } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] + [Fact] public async Task ReadAsync_TryWrite_ManyConcurrentReaders_SerializedWriters_Success() { if (RequiresSingleReader) @@ -657,7 +657,7 @@ namespace System.Threading.Channels.Tests Assert.Equal((Items * (Items - 1)) / 2, Enumerable.Sum(await Task.WhenAll(readers))); } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] + [Fact] public async Task ReadAsync_AlreadyCompleted_Throws() { Channel c = CreateChannel(); @@ -665,7 +665,7 @@ namespace System.Threading.Channels.Tests await Assert.ThrowsAsync(() => c.Reader.ReadAsync().AsTask()); } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] + [Fact] public async Task ReadAsync_SubsequentlyCompleted_Throws() { Channel c = CreateChannel(); @@ -675,7 +675,7 @@ namespace System.Threading.Channels.Tests await Assert.ThrowsAsync(() => r); } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] + [Fact] public async Task ReadAsync_AfterFaultedChannel_Throws() { Channel c = CreateChannel(); @@ -688,7 +688,7 @@ namespace System.Threading.Channels.Tests Assert.Same(e, cce.InnerException); } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] + [Fact] public async Task ReadAsync_AfterCanceledChannel_Throws() { Channel c = CreateChannel(); @@ -700,7 +700,7 @@ namespace System.Threading.Channels.Tests await Assert.ThrowsAnyAsync(() => c.Reader.ReadAsync().AsTask()); } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] + [Fact] public async Task ReadAsync_Canceled_WriteAsyncCompletesNextReader() { Channel c = CreateChannel(); @@ -721,7 +721,7 @@ namespace System.Threading.Channels.Tests } } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] + [Fact] public async Task ReadAsync_ConsecutiveReadsSucceed() { Channel c = CreateChannel(); @@ -733,7 +733,7 @@ namespace System.Threading.Channels.Tests } } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] + [Fact] public async Task WaitToReadAsync_ConsecutiveReadsSucceed() { Channel c = CreateChannel(); @@ -831,7 +831,7 @@ namespace System.Threading.Channels.Tests } } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] + [Fact] public async Task WaitToReadAsync_AwaitThenGetResult_Throws() { Channel c = CreateChannel(); @@ -844,7 +844,7 @@ namespace System.Threading.Channels.Tests Assert.Throws(() => read.GetAwaiter().GetResult()); } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] + [Fact] public async Task ReadAsync_AwaitThenGetResult_Throws() { Channel c = CreateChannel(); @@ -857,7 +857,7 @@ namespace System.Threading.Channels.Tests Assert.Throws(() => read.GetAwaiter().GetResult()); } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] + [Fact] public async Task WaitToWriteAsync_AwaitThenGetResult_Throws() { Channel c = CreateFullChannel(); @@ -874,7 +874,7 @@ namespace System.Threading.Channels.Tests Assert.Throws(() => write.GetAwaiter().GetResult()); } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] + [Fact] public async Task WriteAsync_AwaitThenGetResult_Throws() { Channel c = CreateFullChannel(); @@ -991,7 +991,7 @@ namespace System.Threading.Channels.Tests from setNonDefaultTaskScheduler in new[] { true, false } select new object[] { readOrWait, completeBeforeOnCompleted, flowExecutionContext, continueOnCapturedContext, setNonDefaultTaskScheduler }; - [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] + [Theory] [MemberData(nameof(Reader_ContinuesOnCurrentContextIfDesired_MemberData))] public async Task Reader_ContinuesOnCurrentSynchronizationContextIfDesired( bool readOrWait, bool completeBeforeOnCompleted, bool flowExecutionContext, bool? continueOnCapturedContext, bool setNonDefaultTaskScheduler) @@ -1087,7 +1087,7 @@ namespace System.Threading.Channels.Tests from setDefaultSyncContext in new[] { true, false } select new object[] { readOrWait, completeBeforeOnCompleted, flowExecutionContext, continueOnCapturedContext, setDefaultSyncContext }; - [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] + [Theory] [MemberData(nameof(Reader_ContinuesOnCurrentSchedulerIfDesired_MemberData))] public async Task Reader_ContinuesOnCurrentTaskSchedulerIfDesired( bool readOrWait, bool completeBeforeOnCompleted, bool flowExecutionContext, bool? continueOnCapturedContext, bool setDefaultSyncContext) diff --git a/src/libraries/System.Threading.Channels/tests/ChannelTestBase.netcoreapp.cs b/src/libraries/System.Threading.Channels/tests/ChannelTestBase.netcoreapp.cs index 1d9b3cb..c7046a6 100644 --- a/src/libraries/System.Threading.Channels/tests/ChannelTestBase.netcoreapp.cs +++ b/src/libraries/System.Threading.Channels/tests/ChannelTestBase.netcoreapp.cs @@ -21,7 +21,7 @@ namespace System.Threading.Channels.Tests Assert.NotSame(e, c.Reader.ReadAllAsync()); } - [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] + [Theory] [InlineData(false)] [InlineData(true)] public async Task ReadAllAsync_UseMoveNextAsyncAfterCompleted_ReturnsFalse(bool completeWhilePending) @@ -75,7 +75,7 @@ namespace System.Threading.Channels.Tests } } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] + [Fact] public async Task ReadAllAsync_UnavailableDataCompletesAsynchronously() { Channel c = CreateChannel(); @@ -101,7 +101,7 @@ namespace System.Threading.Channels.Tests } } - [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] + [Theory] [InlineData(0)] [InlineData(1)] [InlineData(128)] @@ -139,7 +139,7 @@ namespace System.Threading.Channels.Tests Assert.Equal(producedTotal, consumedTotal); } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] + [Fact] public async Task ReadAllAsync_MultipleEnumerationsToEnd() { Channel c = CreateChannel(); @@ -192,7 +192,7 @@ namespace System.Threading.Channels.Tests } } - [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] + [Theory] [InlineData(false)] [InlineData(true)] public async Task ReadAllAsync_DualConcurrentEnumeration_AllItemsEnumerated(bool sameEnumerable) @@ -237,7 +237,7 @@ namespace System.Threading.Channels.Tests Assert.Equal(producerTotal, consumerTotal); } - [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] + [Theory] [InlineData(false)] [InlineData(true)] public async Task ReadAllAsync_CanceledBeforeMoveNextAsync_Throws(bool dataAvailable) @@ -259,7 +259,7 @@ namespace System.Threading.Channels.Tests Assert.Equal(cts.Token, oce.CancellationToken); } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] + [Fact] public async Task ReadAllAsync_CanceledAfterMoveNextAsync_Throws() { Channel c = CreateChannel(); diff --git a/src/libraries/System.Threading.Channels/tests/ChannelTests.cs b/src/libraries/System.Threading.Channels/tests/ChannelTests.cs index bdd7566..c5c37b6 100644 --- a/src/libraries/System.Threading.Channels/tests/ChannelTests.cs +++ b/src/libraries/System.Threading.Channels/tests/ChannelTests.cs @@ -112,7 +112,7 @@ namespace System.Threading.Channels.Tests Assert.False(t.IsCompleted); } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] + [Fact] public async Task DefaultWriteAsync_CatchesTryWriteExceptions() { var w = new TryWriteThrowingWriter(); @@ -121,7 +121,7 @@ namespace System.Threading.Channels.Tests await Assert.ThrowsAsync(async () => await t); } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] + [Fact] public async Task DefaultReadAsync_CatchesTryWriteExceptions() { var r = new TryReadThrowingReader(); @@ -130,7 +130,7 @@ namespace System.Threading.Channels.Tests await Assert.ThrowsAsync(() => t); } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] + [Fact] public async Task TestBaseClassReadAsync() { WrapperChannel channel = new WrapperChannel(10); -- 2.7.4