Skip to content

[wasm] Enable System.Threading.Tasks.Extensions tests #38815

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ async ValueTask<int> ValueTaskReturningAsyncMethod(int result)
}

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/38931", TestPlatforms.Browser)]
public static async Task AwaitTasksAndValueTasks_InTaskAndValueTaskMethods()
{
for (int i = 0; i < 2; i++)
Expand Down Expand Up @@ -521,6 +522,7 @@ async ValueTask<int> ValueTaskInt32ReturningMethod()
}

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/38931", TestPlatforms.Browser)]
public async Task NonGeneric_ConcurrentBuilders_WorkCorrectly()
{
await Task.WhenAll(Enumerable.Range(0, Environment.ProcessorCount).Select(async _ =>
Expand All @@ -538,6 +540,7 @@ static async ValueTask ValueTaskAsync()
}

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/38931", TestPlatforms.Browser)]
public async Task Generic_ConcurrentBuilders_WorkCorrectly()
{
await Task.WhenAll(Enumerable.Range(0, Environment.ProcessorCount).Select(async _ =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@

using System.Collections.Generic;
using System.Runtime.CompilerServices;
using Microsoft.DotNet.XUnitExtensions;
using Xunit;

namespace System.Threading.Tasks.Sources.Tests
{
public class ManualResetValueTaskSourceTests
{
[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/38931", TestPlatforms.Browser)]
public async Task ReuseInstanceWithResets_Success()
{
var mrvts = new ManualResetValueTaskSource<int>();
Expand Down Expand Up @@ -62,7 +64,7 @@ public void GetResult_BeforeCompleted_Fails()
}

[Fact]
public void SetResult_BeforeOnCompleted_ResultAvailableSynchronously()
public async Task SetResult_BeforeOnCompleted_ResultAvailableSynchronously()
{
var mrvts = new ManualResetValueTaskSource<int>();
mrvts.Reset();
Expand All @@ -74,14 +76,15 @@ public void SetResult_BeforeOnCompleted_ResultAvailableSynchronously()
Assert.Equal(ValueTaskSourceStatus.Succeeded, mrvts.GetStatus(2));
Assert.Equal(42, mrvts.GetResult(2));

var mres = new ManualResetEventSlim();
mrvts.OnCompleted(s => ((ManualResetEventSlim)s).Set(), mres, 2, ValueTaskSourceOnCompletedFlags.None);
mres.Wait();
var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
mrvts.OnCompleted(s => ((TaskCompletionSource)s).SetResult(), tcs, 2, ValueTaskSourceOnCompletedFlags.None);
await tcs.Task;

Assert.Equal(2, mrvts.Version);
}

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/38931", TestPlatforms.Browser)]
public async Task SetResult_AfterOnCompleted_ResultAvailableAsynchronously()
{
var mrvts = new ManualResetValueTaskSource<int>();
Expand Down Expand Up @@ -109,7 +112,7 @@ public async Task SetResult_AfterOnCompleted_ResultAvailableAsynchronously()
}

[Fact]
public void SetException_BeforeOnCompleted_ResultAvailableSynchronously()
public async Task SetException_BeforeOnCompleted_ResultAvailableSynchronously()
{
var mrvts = new ManualResetValueTaskSource<int>();
mrvts.Reset();
Expand All @@ -122,14 +125,15 @@ public void SetException_BeforeOnCompleted_ResultAvailableSynchronously()
Assert.Equal(ValueTaskSourceStatus.Faulted, mrvts.GetStatus(2));
Assert.Same(e, Assert.Throws<FormatException>(() => mrvts.GetResult(2)));

var mres = new ManualResetEventSlim();
mrvts.OnCompleted(s => ((ManualResetEventSlim)s).Set(), mres, 2, ValueTaskSourceOnCompletedFlags.None);
mres.Wait();
var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
mrvts.OnCompleted(s => ((TaskCompletionSource)s).SetResult(), tcs, 2, ValueTaskSourceOnCompletedFlags.None);
await tcs.Task;

Assert.Equal(2, mrvts.Version);
}

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/38931", TestPlatforms.Browser)]
public async Task SetException_AfterOnCompleted_ResultAvailableAsynchronously()
{
var mrvts = new ManualResetValueTaskSource<int>();
Expand Down Expand Up @@ -172,9 +176,9 @@ public void SetException_OperationCanceledException_StatusIsCanceled()
[Theory]
[InlineData(false)]
[InlineData(true)]
public void FlowContext_SetBeforeOnCompleted_FlowsIfExpected(bool flowContext)
public async Task FlowContext_SetBeforeOnCompleted_FlowsIfExpected(bool flowContext)
{
var mres = new ManualResetEventSlim();
var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
var mrvts = new ManualResetValueTaskSource<int>();

mrvts.RunContinuationsAsynchronously = true;
Expand All @@ -184,36 +188,36 @@ public void FlowContext_SetBeforeOnCompleted_FlowsIfExpected(bool flowContext)
var al = new AsyncLocal<int>();
al.Value = 42;
mrvts.OnCompleted(
_ => { Assert.Equal(flowContext ? 42 : 0, al.Value); mres.Set(); },
_ => { Assert.Equal(flowContext ? 42 : 0, al.Value); tcs.SetResult(); },
null,
0,
flowContext ? ValueTaskSourceOnCompletedFlags.FlowExecutionContext : ValueTaskSourceOnCompletedFlags.None);

mres.Wait();
await tcs.Task;
}

[SkipOnTargetFramework(~TargetFrameworkMonikers.Netcoreapp)]
[Theory]
[InlineData(false)]
[InlineData(true)]
public void FlowContext_SetAfterOnCompleted_FlowsIfExpected(bool flowContext)
public async Task FlowContext_SetAfterOnCompleted_FlowsIfExpected(bool flowContext)
{
var mres = new ManualResetEventSlim();
var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
var mrvts = new ManualResetValueTaskSource<int>();

mrvts.RunContinuationsAsynchronously = true;

var al = new AsyncLocal<int>();
al.Value = 42;
mrvts.OnCompleted(
_ => { Assert.Equal(flowContext ? 42 : 0, al.Value); mres.Set(); },
_ => { Assert.Equal(flowContext ? 42 : 0, al.Value); tcs.SetResult(); },
null,
0,
flowContext ? ValueTaskSourceOnCompletedFlags.FlowExecutionContext : ValueTaskSourceOnCompletedFlags.None);

mrvts.SetResult(1);

mres.Wait();
await tcs.Task;
}

[Fact]
Expand Down Expand Up @@ -241,52 +245,58 @@ public void OnCompleted_UnknownFlagsIgnored()
[Theory]
[InlineData(false)]
[InlineData(true)]
public void OnCompleted_ContinuationAlwaysInvokedAsynchronously(bool runContinuationsAsynchronously)
public async Task OnCompleted_ContinuationAlwaysInvokedAsynchronously(bool runContinuationsAsynchronously)
{
var mres = new ManualResetEventSlim();
var mrvts = new ManualResetValueTaskSource<int>() { RunContinuationsAsynchronously = runContinuationsAsynchronously };
for (short i = 0; i < 10; i++)
{
int threadId = Environment.CurrentManagedThreadId;
var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);

var tl = new ThreadLocal<int> { Value = 42 };
mrvts.SetResult(42);
mrvts.OnCompleted(
_ =>
{
Assert.NotEqual(threadId, Environment.CurrentManagedThreadId);
mres.Set();
Assert.NotEqual(42, tl.Value);
tcs.SetResult();
},
null,
i,
ValueTaskSourceOnCompletedFlags.None);
mrvts.Reset();
mres.Wait();
mres.Reset();

tl.Value = 0;

await tcs.Task;
}
}

[Theory]
[InlineData(false)]
[InlineData(true)]
public void SetResult_RunContinuationsAsynchronously_ContinuationInvokedAccordingly(bool runContinuationsAsynchronously)
public async Task SetResult_RunContinuationsAsynchronously_ContinuationInvokedAccordingly(bool runContinuationsAsynchronously)
{
var mres = new ManualResetEventSlim();
var mrvts = new ManualResetValueTaskSource<int>() { RunContinuationsAsynchronously = runContinuationsAsynchronously };
for (short i = 0; i < 10; i++)
{
int threadId = Environment.CurrentManagedThreadId;
var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);

var tl = new ThreadLocal<int> { Value = 42 };
mrvts.OnCompleted(
_ =>
{
Assert.Equal(!runContinuationsAsynchronously, threadId == Environment.CurrentManagedThreadId);
mres.Set();
Assert.Equal(!runContinuationsAsynchronously, tl.Value == 42);
tcs.SetResult();
},
null,
i,
ValueTaskSourceOnCompletedFlags.None);
mrvts.SetResult(42);
mres.Wait();
mrvts.Reset();
mres.Reset();

tl.Value = 0;

await tcs.Task;
}
}

Expand Down Expand Up @@ -405,6 +415,7 @@ protected override void QueueTask(Task task)
[InlineData(false, true)]
[InlineData(true, false)]
[InlineData(true, true)]
[ActiveIssue("https://github.com/dotnet/runtime/issues/38931", TestPlatforms.Browser)]
public async Task AsyncEnumerable_Success(bool awaitForeach, bool asyncIterator)
{
IAsyncEnumerable<int> enumerable = asyncIterator ?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<TestRuntime>true</TestRuntime>
</PropertyGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.cs" />
<Compile Include="AsyncMethodBuilderAttributeTests.cs" />
<Compile Include="AsyncValueTaskMethodBuilderTests.cs" />
<Compile Include="ManualResetValueTaskSourceTests.cs" />
Expand Down
Loading