Imported Upstream version 5.4.0.167

Former-commit-id: 5624ac747d633e885131e8349322922b6a59baaa
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2017-08-21 15:34:15 +00:00
parent e49d6f06c0
commit 536cd135cc
12856 changed files with 563812 additions and 223249 deletions

View File

@ -180,6 +180,7 @@ namespace System.Threading.Tasks.Tests
tokenSource.Dispose(); //Repeat calls to Dispose should be ok.
}
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Relies on quirked behavior to not throw in token.Register when already disposed")]
[Fact]
public static void TokenSourceDispose_Negative()
{

View File

@ -2,6 +2,7 @@
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<BuildConfigurations>
netcoreapp;
netstandard;
</BuildConfigurations>
</PropertyGroup>

View File

@ -5,6 +5,8 @@
<ProjectGuid>{B6C09633-D161-499A-8FE1-46B2D53A16E7}</ProjectGuid>
</PropertyGroup>
<!-- Default configurations to help VS understand the configurations -->
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Release|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Release|AnyCPU'" />
<ItemGroup>
@ -31,6 +33,7 @@
<Compile Include="Task\TaskContinueWhenAllTests.cs" />
<Compile Include="Task\TaskFromAsyncWork.cs" />
<Compile Include="Task\TaskFromAsyncTest.cs" />
<Compile Include="Task\TaskFromAsyncTest2.cs" />
<Compile Include="Task\TaskCancelWaitTests.cs" />
<Compile Include="Task\TaskCancelWaitTest.cs" />
<Compile Include="Task\TaskRtTests.cs" />
@ -48,9 +51,10 @@
<Compile Include="$(CommonTestPath)\System\Threading\ThreadPoolHelpers.cs">
<Link>CommonTest\System\Threading\ThreadPoolHelpers.cs</Link>
</Compile>
<Compile Include="Task\TaskDisposeTests.cs" />
</ItemGroup>
<ItemGroup>
<Compile Include="Task\TaskDisposeTests.netstandard.cs" />
<ItemGroup Condition="'$(TargetGroup)' == 'netcoreapp'">
<Compile Include="Task\TaskStatusTest.netcoreapp.cs" />
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
</Project>
</Project>

View File

@ -11,6 +11,7 @@ namespace System.Threading.Tasks.Tests
[Theory]
[InlineData(false)]
[InlineData(true)]
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Requires fix in .NET 4.7.")]
public void Direct(bool useRunContinuationsAsynchronously)
{
Run(useRunContinuationsAsynchronously, t => t);
@ -19,6 +20,7 @@ namespace System.Threading.Tasks.Tests
[Theory]
[InlineData(false)]
[InlineData(true)]
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Requires fix in .NET 4.7.")]
public void ViaUnwrap(bool useRunContinuationsAsynchronously)
{
Run(useRunContinuationsAsynchronously, t => ((Task<Task>)t).Unwrap());
@ -27,6 +29,7 @@ namespace System.Threading.Tasks.Tests
[Theory]
[InlineData(false)]
[InlineData(true)]
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Requires fix in .NET 4.7.")]
public void ViaWhenAll(bool useRunContinuationsAsynchronously)
{
Run(useRunContinuationsAsynchronously, t => Task.WhenAll(t));
@ -35,6 +38,7 @@ namespace System.Threading.Tasks.Tests
[Theory]
[InlineData(false)]
[InlineData(true)]
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Requires fix in .NET 4.7.")]
public void ViaWhenAny(bool useRunContinuationsAsynchronously)
{
Run(useRunContinuationsAsynchronously, t => Task.WhenAny(t));
@ -62,6 +66,5 @@ namespace System.Threading.Tasks.Tests
((IAsyncResult)t).AsyncWaitHandle.WaitOne(); // ensure we don't inline as part of waiting
t.GetAwaiter().GetResult(); // propagate any errors
}
}
}

View File

@ -29,7 +29,7 @@ namespace System.Threading.Tasks.Tests
/// <summary>
/// Defines the amount of time the thread should sleep (to simulate workload)
/// </summary>
private const int DEFAULT_TIME = 1000; // 1s
private const int DEFAULT_TIME = 15;
private List<object> _inputs;
@ -141,14 +141,15 @@ namespace System.Threading.Tasks.Tests
public IAsyncResult BeginInvoke(AsyncCallback cb, object state)
{
return _action.BeginInvoke(cb, state);
Task task = Task.Factory.StartNew(_ => _action(), state, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default);
task.ContinueWith(_ => cb(task));
return task;
}
public void EndInvoke(IAsyncResult iar)
{
CheckState(iar.AsyncState);
_action.EndInvoke(iar);
((Task)iar).GetAwaiter().GetResult();
}
#endregion
@ -178,14 +179,15 @@ namespace System.Threading.Tasks.Tests
public IAsyncResult BeginInvoke(T t, AsyncCallback cb, object state)
{
return _action.BeginInvoke(t, cb, state);
Task task = Task.Factory.StartNew(_ => _action(t), state, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default);
task.ContinueWith(_ => cb(task));
return task;
}
public void EndInvoke(IAsyncResult iar)
{
CheckState(iar.AsyncState);
_action.EndInvoke(iar);
((Task)iar).GetAwaiter().GetResult();
}
#endregion
@ -214,14 +216,15 @@ namespace System.Threading.Tasks.Tests
public IAsyncResult BeginInvoke(T1 t1, T2 t2, AsyncCallback cb, object state)
{
return _action.BeginInvoke(t1, t2, cb, state);
Task task = Task.Factory.StartNew(_ => _action(t1, t2), state, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default);
task.ContinueWith(_ => cb(task));
return task;
}
public void EndInvoke(IAsyncResult iar)
{
CheckState(iar.AsyncState);
_action.EndInvoke(iar);
((Task)iar).GetAwaiter().GetResult();
}
#endregion
@ -251,14 +254,15 @@ namespace System.Threading.Tasks.Tests
public IAsyncResult BeginInvoke(T1 t1, T2 t2, T3 t3, AsyncCallback cb, object state)
{
return _action.BeginInvoke(t1, t2, t3, cb, state);
Task task = Task.Factory.StartNew(_ => _action(t1, t2, t3), state, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default);
task.ContinueWith(_ => cb(task));
return task;
}
public void EndInvoke(IAsyncResult iar)
{
CheckState(iar.AsyncState);
_action.EndInvoke(iar);
((Task)iar).GetAwaiter().GetResult();
}
#endregion
@ -304,14 +308,15 @@ namespace System.Threading.Tasks.Tests
public IAsyncResult BeginInvoke(AsyncCallback cb, object state)
{
return _func.BeginInvoke(cb, state);
Task<ReadOnlyCollection<object>> task = Task.Factory.StartNew(_ => _func(), state, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default);
task.ContinueWith(_ => cb(task));
return task;
}
public ReadOnlyCollection<object> EndInvoke(IAsyncResult iar)
{
CheckState(iar.AsyncState);
return _func.EndInvoke(iar);
return ((Task<ReadOnlyCollection<object>>)iar).GetAwaiter().GetResult();
}
#endregion
@ -339,14 +344,15 @@ namespace System.Threading.Tasks.Tests
public IAsyncResult BeginInvoke(T t, AsyncCallback cb, object state)
{
return _func.BeginInvoke(t, cb, state);
Task<ReadOnlyCollection<object>> task = Task.Factory.StartNew(_ => _func(t), state, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default);
task.ContinueWith(_ => cb(task));
return task;
}
public ReadOnlyCollection<object> EndInvoke(IAsyncResult iar)
{
CheckState(iar.AsyncState);
return _func.EndInvoke(iar);
return ((Task<ReadOnlyCollection<object>>)iar).GetAwaiter().GetResult();
}
#endregion
@ -375,14 +381,15 @@ namespace System.Threading.Tasks.Tests
public IAsyncResult BeginInvoke(T1 t1, T2 t2, AsyncCallback cb, object state)
{
return _func.BeginInvoke(t1, t2, cb, state);
Task<ReadOnlyCollection<object>> task = Task.Factory.StartNew(_ => _func(t1, t2), state, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default);
task.ContinueWith(_ => cb(task));
return task;
}
public ReadOnlyCollection<object> EndInvoke(IAsyncResult iar)
{
CheckState(iar.AsyncState);
return _func.EndInvoke(iar);
return ((Task<ReadOnlyCollection<object>>)iar).GetAwaiter().GetResult();
}
#endregion
@ -412,14 +419,15 @@ namespace System.Threading.Tasks.Tests
public IAsyncResult BeginInvoke(T1 t1, T2 t2, T3 t3, AsyncCallback cb, object state)
{
return _func.BeginInvoke(t1, t2, t3, cb, state);
Task<ReadOnlyCollection<object>> task = Task.Factory.StartNew(_ => _func(t1, t2, t3), state, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default);
task.ContinueWith(_ => cb(task));
return task;
}
public ReadOnlyCollection<object> EndInvoke(IAsyncResult iar)
{
CheckState(iar.AsyncState);
return _func.EndInvoke(iar);
return ((Task<ReadOnlyCollection<object>>)iar).GetAwaiter().GetResult();
}
#endregion

View File

@ -0,0 +1,107 @@
// 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 TaskStatusProperties
{
public static IEnumerable<object[]> Status_IsProperties_Match_MemberData()
{
yield return new object[] { new StrongBox<Task>(Task.CompletedTask) };
yield return new object[] { new StrongBox<Task>(new Task(() => { })) };
yield return new object[] { new StrongBox<Task>(new TaskCompletionSource<int>().Task) };
{
var tcs = new TaskCompletionSource<int>();
tcs.SetResult(42);
yield return new object[] { new StrongBox<Task>(tcs.Task) };
}
{
var tcs = new TaskCompletionSource<int>();
tcs.SetException(new Exception());
yield return new object[] { new StrongBox<Task>(tcs.Task) };
}
{
var tcs = new TaskCompletionSource<int>();
tcs.SetCanceled();
yield return new object[] { new StrongBox<Task>(tcs.Task) };
}
{
var t = Task.Run(() => { });
t.Wait();
yield return new object[] { new StrongBox<Task>(t) };
}
{
var atmb = new AsyncTaskMethodBuilder<bool>();
atmb.SetResult(true);
yield return new object[] { new StrongBox<Task>(atmb.Task) };
}
}
[Theory]
[MemberData(nameof(Status_IsProperties_Match_MemberData))]
public void Status_IsProperties_Match(StrongBox<Task> taskBox)
{
// The StrongBox<Task> is a workaround for xunit trying to automatically
// Dispose of any IDisposable passed into a theory, but Task doesn't like
// being Dispose'd when it's not in a final state.
Task task = taskBox.Value;
if (task.IsCompletedSuccessfully)
{
Assert.Equal(TaskStatus.RanToCompletion, task.Status);
}
else if (task.IsFaulted)
{
Assert.Equal(TaskStatus.Faulted, task.Status);
}
else if (task.IsCanceled)
{
Assert.Equal(TaskStatus.Canceled, task.Status);
}
switch (task.Status)
{
case TaskStatus.RanToCompletion:
Assert.True(task.IsCompleted, "Expected IsCompleted to be true");
Assert.True(task.IsCompletedSuccessfully, "Expected IsCompletedSuccessfully to be true");
Assert.False(task.IsFaulted, "Expected IsFaulted to be false");
Assert.False(task.IsCanceled, "Expected IsCanceled to be false");
break;
case TaskStatus.Faulted:
Assert.True(task.IsCompleted, "Expected IsCompleted to be true");
Assert.False(task.IsCompletedSuccessfully, "Expected IsCompletedSuccessfully to be false");
Assert.True(task.IsFaulted, "Expected IsFaulted to be true");
Assert.False(task.IsCanceled, "Expected IsCanceled to be false");
break;
case TaskStatus.Canceled:
Assert.True(task.IsCompleted, "Expected IsCompleted to be true");
Assert.False(task.IsCompletedSuccessfully, "Expected IsCompletedSuccessfully to be false");
Assert.False(task.IsFaulted, "Expected IsFaulted to be false");
Assert.True(task.IsCanceled, "Expected IsCanceled to be true");
break;
default:
Assert.False(task.IsCompleted, "Expected IsCompleted to be false");
Assert.False(task.IsCompletedSuccessfully, "Expected IsCompletedSuccessfully to be false");
Assert.False(task.IsFaulted, "Expected IsFaulted to be false");
Assert.False(task.IsCanceled, "Expected IsCanceled to be false");
break;
}
}
}
}

View File

@ -30,10 +30,24 @@ namespace System.Threading.Tasks.Tests
Task<Task> outer = Task.FromResult(inner);
Task unwrappedInner = outer.Unwrap();
Assert.True(unwrappedInner.IsCompleted);
Assert.Same(inner, unwrappedInner);
AssertTasksAreEqual(inner, unwrappedInner);
}
/// <summary>
/// Tests Unwrap when both the outer task and non-generic inner task have completed by the time Unwrap is called.
/// </summary>
/// <param name="inner">Will be run with a RanToCompletion, Faulted, and Canceled task.</param>
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, ".NET Core optimization to return the exact same object")]
[Theory]
[MemberData(nameof(CompletedNonGenericTasks))]
public void NonGeneric_Completed_Completed_OptimizeToUseSameInner(Task inner)
{
Task<Task> outer = Task.FromResult(inner);
Task unwrappedInner = outer.Unwrap();
Assert.True(unwrappedInner.IsCompleted);
Assert.Same(inner, unwrappedInner);
}
/// <summary>
/// Tests Unwrap when both the outer task and generic inner task have completed by the time Unwrap is called.
/// </summary>
@ -45,10 +59,24 @@ namespace System.Threading.Tasks.Tests
Task<Task<string>> outer = Task.FromResult(inner);
Task<string> unwrappedInner = outer.Unwrap();
Assert.True(unwrappedInner.IsCompleted);
Assert.Same(inner, unwrappedInner);
AssertTasksAreEqual(inner, unwrappedInner);
}
/// <summary>
/// Tests Unwrap when both the outer task and generic inner task have completed by the time Unwrap is called.
/// </summary>
/// <param name="inner">The inner task.</param>
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, ".NET Core optimization to return the exact same object")]
[Theory]
[MemberData(nameof(CompletedStringTasks))]
public void Generic_Completed_Completed_OptimizeToUseSameInner(Task<string> inner)
{
Task<Task<string>> outer = Task.FromResult(inner);
Task<string> unwrappedInner = outer.Unwrap();
Assert.True(unwrappedInner.IsCompleted);
Assert.Same(inner, unwrappedInner);
}
/// <summary>
/// Tests Unwrap when the non-generic inner task has completed but the outer task has not completed by the time Unwrap is called.
/// </summary>