Imported Upstream version 5.16.0.100

Former-commit-id: 38faa55fb9669e35e7d8448b15c25dc447f25767
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2018-08-07 15:19:03 +00:00
parent 0a9828183b
commit 7d7f676260
4419 changed files with 170950 additions and 90273 deletions

View File

@ -375,6 +375,16 @@ namespace System.Threading.Tasks.Tests
TaskMethodBuilderT_UsesCompletedCache(result, shouldBeCached);
}
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "https://github.com/dotnet/coreclr/pull/16588")]
[Fact]
[ActiveIssue("TFS 450361 - Codegen optimization issue", TargetFrameworkMonikers.UapAot)]
public static void TaskMethodBuilderDecimal_DoesntUseCompletedCache()
{
TaskMethodBuilderT_UsesCompletedCache(0m, shouldBeCached: false);
TaskMethodBuilderT_UsesCompletedCache(0.0m, shouldBeCached: false);
TaskMethodBuilderT_UsesCompletedCache(42m, shouldBeCached: false);
}
[Theory]
[InlineData((string)null, true)]
[InlineData("test", false)]
@ -393,6 +403,11 @@ namespace System.Threading.Tasks.Tests
atmb2.SetResult(result);
Assert.Equal(shouldBeCached, object.ReferenceEquals(atmb1.Task, atmb2.Task));
if (result != null)
{
Assert.Equal(result.ToString(), atmb1.Task.Result.ToString());
Assert.Equal(result.ToString(), atmb2.Task.Result.ToString());
}
}
[Fact]
@ -529,7 +544,7 @@ namespace System.Threading.Tasks.Tests
{
Assert.NotNull(e);
Assert.NotNull(e.StackTrace);
Assert.Contains("End of stack trace", e.StackTrace);
Assert.Matches(@"---.+---", e.StackTrace);
}
private class TrackOperationsSynchronizationContext : SynchronizationContext

View File

@ -123,6 +123,53 @@ namespace System.Threading.Tasks.Tests
}
}
[Fact]
public async Task Await_TaskCompletesOnNonDefaultSyncCtx_ContinuesOnDefaultSyncCtx()
{
await Task.Run(async delegate // escape xunit's sync context
{
Assert.Null(SynchronizationContext.Current);
Assert.Same(TaskScheduler.Default, TaskScheduler.Current);
var ctx = new ValidateCorrectContextSynchronizationContext();
var tcs = new TaskCompletionSource<bool>();
var ignored = Task.Delay(1).ContinueWith(_ =>
{
SynchronizationContext orig = SynchronizationContext.Current;
SynchronizationContext.SetSynchronizationContext(ctx);
try
{
tcs.SetResult(true);
}
finally
{
SynchronizationContext.SetSynchronizationContext(orig);
}
}, TaskScheduler.Default);
await tcs.Task;
Assert.Null(SynchronizationContext.Current);
Assert.Same(TaskScheduler.Default, TaskScheduler.Current);
});
}
[Fact]
public async Task Await_TaskCompletesOnNonDefaultScheduler_ContinuesOnDefaultScheduler()
{
await Task.Run(async delegate // escape xunit's sync context
{
Assert.Null(SynchronizationContext.Current);
Assert.Same(TaskScheduler.Default, TaskScheduler.Current);
var tcs = new TaskCompletionSource<bool>();
var ignored = Task.Delay(1).ContinueWith(_ => tcs.SetResult(true), new QUWITaskScheduler());
await tcs.Task;
Assert.Null(SynchronizationContext.Current);
Assert.Same(TaskScheduler.Default, TaskScheduler.Current);
});
}
[Fact]
public static void GetResult_Completed_Success()
{

View File

@ -143,8 +143,38 @@ namespace System.Threading.Tasks.Tests
SynchronizationContext.SetSynchronizationContext(new ValidateCorrectContextSynchronizationContext());
var ya = Task.Yield().GetAwaiter();
Assert.Throws<ArgumentNullException>(() => { ya.OnCompleted(null); });
SynchronizationContext.SetSynchronizationContext(null);
}
[Fact]
public static async Task AsyncMethod_Yields_ReturnsToDefaultTaskScheduler()
{
await Task.Yield();
Assert.Same(TaskScheduler.Default, TaskScheduler.Current);
}
[Fact]
public static async Task AsyncMethod_Yields_ReturnsToCorrectTaskScheduler()
{
QUWITaskScheduler ts = new QUWITaskScheduler();
Assert.NotSame(ts, TaskScheduler.Current);
await Task.Factory.StartNew(async delegate
{
Assert.Same(ts, TaskScheduler.Current);
await Task.Yield();
Assert.Same(ts, TaskScheduler.Current);
}, CancellationToken.None, TaskCreationOptions.None, ts).Unwrap();
Assert.NotSame(ts, TaskScheduler.Current);
}
[Fact]
public static async Task AsyncMethod_Yields_ReturnsToCorrectSynchronizationContext()
{
var sc = new ValidateCorrectContextSynchronizationContext ();
SynchronizationContext.SetSynchronizationContext(sc);
await Task.Yield();
Assert.Equal(1, sc.PostCount);
}
#region Helper Methods / Classes
private class ValidateCorrectContextSynchronizationContext : SynchronizationContext

View File

@ -17,6 +17,7 @@
<Compile Include="MethodCoverage.cs" />
<Compile Include="CESchedulerPairTests.cs" />
<!-- Task -->
<Compile Include="Task\ExecutionContextFlowTest.cs" />
<Compile Include="Task\RunContinuationsAsynchronouslyTests.cs" />
<Compile Include="Task\TPLTestException.cs" />
<Compile Include="Task\TaskRunSyncTests.cs" />
@ -54,6 +55,7 @@
</ItemGroup>
<ItemGroup Condition="'$(TargetGroup)' == 'netcoreapp'">
<Compile Include="CancellationTokenTests.netcoreapp.cs" />
<Compile Include="Task\TaskCanceledExceptionTests.netcoreapp.cs" />
<Compile Include="Task\TaskStatusTest.netcoreapp.cs" />
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />

View File

@ -0,0 +1,40 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.CompilerServices;
using Xunit;
namespace System.Threading.Tasks.Tests
{
public class ExecutionContextFlowTest
{
[Theory]
[InlineData(false)]
[InlineData(true)]
public void SuppressFlow_TaskCapturesContextAccordingly(bool suppressFlow)
{
Assert.False(ExecutionContext.IsFlowSuppressed());
if (suppressFlow) ExecutionContext.SuppressFlow();
try
{
var asyncLocal = new AsyncLocal<int>();
Task.Factory.StartNew(() => asyncLocal.Value = 42, CancellationToken.None, TaskCreationOptions.None, new InlineTaskScheduler()).Wait();
Assert.Equal(suppressFlow ? 42 : 0, asyncLocal.Value);
}
finally
{
if (suppressFlow) ExecutionContext.RestoreFlow();
}
}
private sealed class InlineTaskScheduler : TaskScheduler
{
protected override void QueueTask(Task task) => TryExecuteTask(task);
protected override bool TryExecuteTaskInline(Task task, bool taskWasPreviouslyQueued) => TryExecuteTask(task);
protected override IEnumerable<Task> GetScheduledTasks() => null;
}
}
}

View File

@ -70,6 +70,7 @@ namespace System.Threading.Tasks.Tests.CancelWait
{
case API.Cancel:
_taskTree.CancellationTokenSource.Cancel();
_taskTree.Task.Wait();
break;
case API.Wait:
@ -131,8 +132,11 @@ namespace System.Threading.Tasks.Tests.CancelWait
if (current.IsLeaf)
{
if (!_countdownEvent.IsSet)
_countdownEvent.Signal();
lock (_countdownEvent)
{
if (!_countdownEvent.IsSet)
_countdownEvent.Signal();
}
}
else
{
@ -162,10 +166,13 @@ namespace System.Threading.Tasks.Tests.CancelWait
}
finally
{
// stop the tree creation and let the main thread proceed
if (!_countdownEvent.IsSet)
lock (_countdownEvent)
{
_countdownEvent.Signal(_countdownEvent.CurrentCount);
// stop the tree creation and let the main thread proceed
if (!_countdownEvent.IsSet)
{
_countdownEvent.Signal(_countdownEvent.CurrentCount);
}
}
}
}
@ -208,6 +215,7 @@ namespace System.Threading.Tasks.Tests.CancelWait
VerifyCancel(current);
VerifyResult(current);
});
Assert.Null(_caughtException);
break;
//root task was calling wait

View File

@ -1 +1 @@
f103178e31df172d54c81614cbd615b07eff7f74
d0848664b34f24dceeff57468988e52aa486b0a1

View File

@ -0,0 +1,27 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using Xunit;
namespace System.Threading.Tasks.Tests
{
public class TaskCanceledExceptionTests
{
[Fact]
public void TaskCanceledException_Ctor_StringExceptionToken()
{
string message = "my exception message";
var ioe = new InvalidOperationException();
var cts = new CancellationTokenSource();
cts.Cancel();
var tce = new TaskCanceledException(message, ioe, cts.Token);
Assert.Equal(message, tce.Message);
Assert.Null(tce.Task);
Assert.Same(ioe, tce.InnerException);
Assert.Equal(cts.Token, tce.CancellationToken);
}
}
}

View File

@ -292,6 +292,7 @@ namespace System.Threading.Tasks.Tests
[Fact]
[SkipOnTargetFramework(TargetFrameworkMonikers.UapAot, "Uses reflection to access an internal method of the TaskScheduler class.")]
[SkipOnTargetFramework(TargetFrameworkMonikers.Mono, "Needs ConditionalFact in which we can customize linker debug mode")]
public static void GetTaskSchedulersForDebugger_ReturnsDefaultScheduler()
{
MethodInfo getTaskSchedulersForDebuggerMethod = typeof(TaskScheduler).GetTypeInfo().GetDeclaredMethod("GetTaskSchedulersForDebugger");