Imported Upstream version 5.8.0.22

Former-commit-id: df344e34b07851d296efb3e6604c8db42b6f7aa3
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2017-10-19 20:04:20 +00:00
parent 5f4a27cc8a
commit 7d05485754
5020 changed files with 114082 additions and 186061 deletions

View File

@ -31,14 +31,11 @@ namespace System.Threading.Tasks.Tests
public static void ConstructorInvalidArguments()
{
AggregateException ex = new AggregateException();
Assert.Throws<ArgumentNullException>(
() => ex = new AggregateException("message", (Exception)null));
Assert.Throws<ArgumentNullException>(() => new AggregateException("message", (Exception)null));
Assert.Throws<ArgumentNullException>(
() => ex = new AggregateException("message", (IEnumerable<Exception>)null));
Assert.Throws<ArgumentNullException>(() => new AggregateException("message", (IEnumerable<Exception>)null));
Assert.Throws<ArgumentException>(
() => ex = new AggregateException("message", new[] { new Exception(), null }));
AssertExtensions.Throws<ArgumentException>(null, () => ex = new AggregateException("message", new[] { new Exception(), null }));
}
[Fact]

View File

@ -345,6 +345,7 @@ namespace System.Threading.Tasks.Tests
}
[Fact]
[ActiveIssue("TFS 450361 - Codegen optimization issue", TargetFrameworkMonikers.UapAot)]
public static void TaskMethodBuilder_UsesCompletedCache()
{
var atmb1 = new AsyncTaskMethodBuilder();
@ -357,6 +358,7 @@ namespace System.Threading.Tasks.Tests
[Theory]
[InlineData(true)]
[InlineData(false)]
[ActiveIssue("TFS 450361 - Codegen optimization issue", TargetFrameworkMonikers.UapAot)]
public static void TaskMethodBuilderBoolean_UsesCompletedCache(bool result)
{
TaskMethodBuilderT_UsesCompletedCache(result, true);
@ -367,6 +369,7 @@ namespace System.Threading.Tasks.Tests
[InlineData(5, true)]
[InlineData(-5, false)]
[InlineData(42, false)]
[ActiveIssue("TFS 450361 - Codegen optimization issue", TargetFrameworkMonikers.UapAot)]
public static void TaskMethodBuilderInt32_UsesCompletedCache(int result, bool shouldBeCached)
{
TaskMethodBuilderT_UsesCompletedCache(result, shouldBeCached);
@ -375,6 +378,7 @@ namespace System.Threading.Tasks.Tests
[Theory]
[InlineData((string)null, true)]
[InlineData("test", false)]
[ActiveIssue("TFS 450361 - Codegen optimization issue", TargetFrameworkMonikers.UapAot)]
public static void TaskMethodBuilderRef_UsesCompletedCache(string result, bool shouldBeCached)
{
TaskMethodBuilderT_UsesCompletedCache(result, shouldBeCached);

View File

@ -35,7 +35,7 @@ namespace System.Threading.Tasks.Tests
bool postedInContext = false;
Action callback = () =>
{
postedInContext = ValidateCorrectContextSynchronizationContext.IsPostedInContext;
postedInContext = ValidateCorrectContextSynchronizationContext.t_isPostedInContext;
mres.Set();
};
if (generic)
@ -182,14 +182,14 @@ namespace System.Threading.Tasks.Tests
Task<string> task = Task.FromException<string>(exception);
// Task.GetAwaiter and Task<T>.GetAwaiter
Assert.Same(exception, Assert.Throws<ArgumentException>(() => ((Task)task).GetAwaiter().GetResult()));
Assert.Same(exception, Assert.Throws<ArgumentException>(() => task.GetAwaiter().GetResult()));
Assert.Same(exception, AssertExtensions.Throws<ArgumentException>(null, () => ((Task)task).GetAwaiter().GetResult()));
Assert.Same(exception, AssertExtensions.Throws<ArgumentException>(null, () => task.GetAwaiter().GetResult()));
// w/ ConfigureAwait false and true
Assert.Same(exception, Assert.Throws<ArgumentException>(() => ((Task)task).ConfigureAwait(false).GetAwaiter().GetResult()));
Assert.Same(exception, Assert.Throws<ArgumentException>(() => ((Task)task).ConfigureAwait(true).GetAwaiter().GetResult()));
Assert.Same(exception, Assert.Throws<ArgumentException>(() => task.ConfigureAwait(false).GetAwaiter().GetResult()));
Assert.Same(exception, Assert.Throws<ArgumentException>(() => task.ConfigureAwait(true).GetAwaiter().GetResult()));
Assert.Same(exception, AssertExtensions.Throws<ArgumentException>(null, () => ((Task)task).ConfigureAwait(false).GetAwaiter().GetResult()));
Assert.Same(exception, AssertExtensions.Throws<ArgumentException>(null, () => ((Task)task).ConfigureAwait(true).GetAwaiter().GetResult()));
Assert.Same(exception, AssertExtensions.Throws<ArgumentException>(null, () => task.ConfigureAwait(false).GetAwaiter().GetResult()));
Assert.Same(exception, AssertExtensions.Throws<ArgumentException>(null, () => task.ConfigureAwait(true).GetAwaiter().GetResult()));
}
[Fact]
@ -201,14 +201,14 @@ namespace System.Threading.Tasks.Tests
Task<string> task = tcs.Task;
// Task.GetAwaiter and Task<T>.GetAwaiter
Assert.Same(exception, Assert.Throws<ArgumentException>(() => ((Task)task).GetAwaiter().GetResult()));
Assert.Same(exception, Assert.Throws<ArgumentException>(() => task.GetAwaiter().GetResult()));
Assert.Same(exception, AssertExtensions.Throws<ArgumentException>(null, () => ((Task)task).GetAwaiter().GetResult()));
Assert.Same(exception, AssertExtensions.Throws<ArgumentException>(null, () => task.GetAwaiter().GetResult()));
// w/ ConfigureAwait false and true
Assert.Same(exception, Assert.Throws<ArgumentException>(() => ((Task)task).ConfigureAwait(false).GetAwaiter().GetResult()));
Assert.Same(exception, Assert.Throws<ArgumentException>(() => ((Task)task).ConfigureAwait(true).GetAwaiter().GetResult()));
Assert.Same(exception, Assert.Throws<ArgumentException>(() => task.ConfigureAwait(false).GetAwaiter().GetResult()));
Assert.Same(exception, Assert.Throws<ArgumentException>(() => task.ConfigureAwait(true).GetAwaiter().GetResult()));
Assert.Same(exception, AssertExtensions.Throws<ArgumentException>(null, () => ((Task)task).ConfigureAwait(false).GetAwaiter().GetResult()));
Assert.Same(exception, AssertExtensions.Throws<ArgumentException>(null, () => ((Task)task).ConfigureAwait(true).GetAwaiter().GetResult()));
Assert.Same(exception, AssertExtensions.Throws<ArgumentException>(null, () => task.ConfigureAwait(false).GetAwaiter().GetResult()));
Assert.Same(exception, AssertExtensions.Throws<ArgumentException>(null, () => task.ConfigureAwait(true).GetAwaiter().GetResult()));
}
[Fact]
@ -330,7 +330,7 @@ namespace System.Threading.Tasks.Tests
private class ValidateCorrectContextSynchronizationContext : SynchronizationContext
{
[ThreadStatic]
internal static bool IsPostedInContext;
internal static bool t_isPostedInContext;
internal int PostCount;
internal int SendCount;
@ -342,12 +342,12 @@ namespace System.Threading.Tasks.Tests
{
try
{
IsPostedInContext = true;
t_isPostedInContext = true;
d(state);
}
finally
{
IsPostedInContext = false;
t_isPostedInContext = false;
}
});
}

View File

@ -28,7 +28,7 @@ namespace System.Threading.Tasks.Tests
Assert.False(ya.IsCompleted, "RunAsyncYieldAwaiterTests > FAILURE. YieldAwaiter.IsCompleted should always be false.");
ya.OnCompleted(() =>
{
Assert.True(ValidateCorrectContextSynchronizationContext.IsPostedInContext, "RunAsyncYieldAwaiterTests > FAILURE. Expected to post in target context.");
Assert.True(ValidateCorrectContextSynchronizationContext.t_isPostedInContext, "RunAsyncYieldAwaiterTests > FAILURE. Expected to post in target context.");
mres.Set();
});
mres.Wait();
@ -50,7 +50,7 @@ namespace System.Threading.Tasks.Tests
Assert.False(ya.IsCompleted, "RunAsyncYieldAwaiterTests > FAILURE. YieldAwaiter.IsCompleted should always be false.");
ya.OnCompleted(() =>
{
Assert.True(ValidateCorrectContextSynchronizationContext.IsPostedInContext, " > FAILURE. Expected to post in target context.");
Assert.True(ValidateCorrectContextSynchronizationContext.t_isPostedInContext, " > FAILURE. Expected to post in target context.");
mres.Set();
});
mres.Wait();
@ -126,7 +126,7 @@ namespace System.Threading.Tasks.Tests
Assert.False(ya.IsCompleted, " > FAILURE. YieldAwaiter.IsCompleted should always be false.");
ya.OnCompleted(() =>
{
Assert.True(ValidateCorrectContextSynchronizationContext.IsPostedInContext, " > FAILURE. Expected to post in target context.");
Assert.True(ValidateCorrectContextSynchronizationContext.t_isPostedInContext, " > FAILURE. Expected to post in target context.");
mres.Set();
});
mres.Wait();
@ -150,7 +150,7 @@ namespace System.Threading.Tasks.Tests
private class ValidateCorrectContextSynchronizationContext : SynchronizationContext
{
[ThreadStatic]
internal static bool IsPostedInContext;
internal static bool t_isPostedInContext;
internal int PostCount;
internal int SendCount;
@ -160,9 +160,9 @@ namespace System.Threading.Tasks.Tests
Interlocked.Increment(ref PostCount);
Task.Run(() =>
{
IsPostedInContext = true;
t_isPostedInContext = true;
d(state);
IsPostedInContext = false;
t_isPostedInContext = false;
});
}

View File

@ -677,11 +677,8 @@ namespace System.Threading.Tasks.Tests
smallTaskArray[0] = null;
Assert.Throws<ArgumentException>(
() => { Task.Factory.ContinueWhenAll(smallTaskArray, delegate (Task[] finishedArray) { }); });
Assert.Throws<ArgumentException>(
() => { Task.Factory.ContinueWhenAll(new Task[] { }, delegate (Task[] finishedArray) { }); });
AssertExtensions.Throws<ArgumentException>("tasks", () => Task.Factory.ContinueWhenAll(smallTaskArray, delegate (Task[] finishedArray) { }));
AssertExtensions.Throws<ArgumentException>("tasks", () => Task.Factory.ContinueWhenAll(new Task[0], delegate (Task[] finishedArray) { }));
}
//
@ -713,11 +710,8 @@ namespace System.Threading.Tasks.Tests
smallTaskArray[0] = null;
Assert.Throws<ArgumentException>(
() => { Task.Factory.ContinueWhenAll<int>(smallTaskArray, finishedArray => 10); });
Assert.Throws<ArgumentException>(
() => { Task.Factory.ContinueWhenAll<int>(new Task[] { }, finishedArray => 10); });
AssertExtensions.Throws<ArgumentException>("tasks", () => Task.Factory.ContinueWhenAll(smallTaskArray, finishedArray => 10));
AssertExtensions.Throws<ArgumentException>("tasks", () => Task.Factory.ContinueWhenAll<int>(new Task[] { }, finishedArray => 10));
}
@ -750,11 +744,8 @@ namespace System.Threading.Tasks.Tests
smallTaskArray[0] = null;
Assert.Throws<ArgumentException>(
() => { Task<int>.Factory.ContinueWhenAll(smallTaskArray, finishedArray => 10); });
Assert.Throws<ArgumentException>(
() => { Task<int>.Factory.ContinueWhenAll(new Task[] { }, finishedArray => 10); });
AssertExtensions.Throws<ArgumentException>("tasks", () => Task<int>.Factory.ContinueWhenAll(smallTaskArray, finishedArray => 10));
AssertExtensions.Throws<ArgumentException>("tasks", () => Task<int>.Factory.ContinueWhenAll(new Task[0], finishedArray => 10));
}
//
@ -786,11 +777,8 @@ namespace System.Threading.Tasks.Tests
smallFutureArray[0] = null;
Assert.Throws<ArgumentException>(
() => { Task.Factory.ContinueWhenAll<int>(smallFutureArray, finishedArray => { }); });
Assert.Throws<ArgumentException>(
() => { Task.Factory.ContinueWhenAll<int>(new Task<int>[] { }, finishedArray => { }); });
AssertExtensions.Throws<ArgumentException>("tasks", () => Task.Factory.ContinueWhenAll(smallFutureArray, finishedArray => { }));
AssertExtensions.Throws<ArgumentException>("tasks", () => Task.Factory.ContinueWhenAll(new Task<int>[0], finishedArray => { }));
}
//
@ -822,11 +810,8 @@ namespace System.Threading.Tasks.Tests
smallFutureArray[0] = null;
Assert.Throws<ArgumentException>(
() => { Task.Factory.ContinueWhenAll<int, int>(smallFutureArray, finishedArray => 10); });
Assert.Throws<ArgumentException>(
() => { Task.Factory.ContinueWhenAll<int, int>(new Task<int>[] { }, finishedArray => 10); });
AssertExtensions.Throws<ArgumentException>("tasks", () => Task.Factory.ContinueWhenAll(smallFutureArray, finishedArray => 10));
AssertExtensions.Throws<ArgumentException>("tasks", () => Task.Factory.ContinueWhenAll(new Task<int>[0], finishedArray => 10));
}
//
@ -859,11 +844,8 @@ namespace System.Threading.Tasks.Tests
smallFutureArray[0] = null;
Assert.Throws<ArgumentException>(
() => { Task<int>.Factory.ContinueWhenAll<int>(smallFutureArray, finishedArray => 10); });
Assert.Throws<ArgumentException>(
() => { Task<int>.Factory.ContinueWhenAll<int>(new Task<int>[] { }, finishedArray => 10); });
AssertExtensions.Throws<ArgumentException>("tasks", () => Task<int>.Factory.ContinueWhenAll(smallFutureArray, finishedArray => 10));
AssertExtensions.Throws<ArgumentException>("tasks", () => Task<int>.Factory.ContinueWhenAll(new Task<int>[0], finishedArray => 10));
}
}

View File

@ -257,8 +257,7 @@ namespace Test
() => Task<int>.Factory.ContinueWhenAny<int>((Task<int>[])antecedents, t => 0));
Assert.Throws<ArgumentException>(
() => { Task<int>.Factory.ContinueWhenAny<int>(new Task<int>[] { }, t => 0); });
AssertExtensions.Throws<ArgumentException>("tasks", () => Task<int>.Factory.ContinueWhenAny(new Task<int>[0], t => 0));
//
// Test for exception on null continuation function
@ -300,8 +299,7 @@ namespace Test
() => Task<int>.Factory.ContinueWhenAny(antecedents, (t) => 0));
Assert.Throws<ArgumentException>(
() => { Task<int>.Factory.ContinueWhenAny(new Task[] { }, t => 0); });
AssertExtensions.Throws<ArgumentException>("tasks", () => Task<int>.Factory.ContinueWhenAny(new Task[0], t => 0));
//
// Test for exception on null continuation function
@ -343,8 +341,7 @@ namespace Test
Assert.ThrowsAsync<ArgumentException>(
() => Task.Factory.ContinueWhenAny<int, int>((Task<int>[])antecedents, t => 0));
Assert.Throws<ArgumentException>(
() => { Task.Factory.ContinueWhenAny<int, int>(new Task<int>[] { }, t => 0); });
AssertExtensions.Throws<ArgumentException>("tasks", () => Task.Factory.ContinueWhenAny(new Task<int>[0], t => 0));
//
// Test for exception on null continuation function
@ -381,8 +378,7 @@ namespace Test
() => Task.Factory.ContinueWhenAny<int>(antecedents, t => 0));
Assert.Throws<ArgumentException>(
() => { Task.Factory.ContinueWhenAny<int>(new Task[] { }, t => 0); });
AssertExtensions.Throws<ArgumentException>("tasks", () => Task.Factory.ContinueWhenAny(new Task[0], t => 0));
//
// Test for exception on null continuation function
@ -422,8 +418,7 @@ namespace Test
Assert.ThrowsAsync<ArgumentException>(
() => Task.Factory.ContinueWhenAny<int>((Task<int>[])antecedents, t => { }));
Assert.Throws<ArgumentException>(
() => { Task.Factory.ContinueWhenAny<int>(new Task<int>[] { }, t => { }); });
AssertExtensions.Throws<ArgumentException>("tasks", () => Task.Factory.ContinueWhenAny(new Task<int>[] { }, t => { }));
//
// Test for exception on null continuation action
@ -459,8 +454,7 @@ namespace Test
Assert.ThrowsAsync<ArgumentException>(
() => Task.Factory.ContinueWhenAny(antecedents, t => { }));
Assert.Throws<ArgumentException>(
() => { Task.Factory.ContinueWhenAny(new Task[] { }, t => { }); });
AssertExtensions.Throws<ArgumentException>("tasks",() => Task.Factory.ContinueWhenAny(new Task[0], t => { }));
//
// Test for exception on null continuation action

View File

@ -463,37 +463,42 @@ namespace System.Threading.Tasks.Tests
// Make sure we throw from waiting on a faulted task
Assert.Throws<AggregateException>(() => { var result = Task.FromException<object>(new InvalidOperationException()).Result; });
}
}
// Make sure faulted tasks are actually faulted. We have little choice for this test but to use reflection,
// as the harness will crash by throwing from the unobserved event if a task goes unhandled (everywhere
// other than here it's a bad thing for an exception to go unobserved)
var faultedTask = Task.FromException<object>(new InvalidOperationException("uh oh"));
object holderObject = null;
FieldInfo isHandledField = null;
var contingentPropertiesField = typeof(Task).GetField("m_contingentProperties", BindingFlags.NonPublic | BindingFlags.Instance);
if (contingentPropertiesField != null)
[Fact]
[SkipOnTargetFramework(TargetFrameworkMonikers.UapAot, "Uses reflection to access internal fields of the Task class.")]
public static void RunFromResult_FaultedTask()
{
// Make sure faulted tasks are actually faulted. We have little choice for this test but to use reflection,
// as the harness will crash by throwing from the unobserved event if a task goes unhandled (everywhere
// other than here it's a bad thing for an exception to go unobserved)
var faultedTask = Task.FromException<object>(new InvalidOperationException("uh oh"));
object holderObject = null;
FieldInfo isHandledField = null;
var contingentPropertiesField = typeof(Task).GetField("m_contingentProperties", BindingFlags.NonPublic | BindingFlags.Instance);
if (contingentPropertiesField != null)
{
var contingentProperties = contingentPropertiesField.GetValue(faultedTask);
if (contingentProperties != null)
{
var contingentProperties = contingentPropertiesField.GetValue(faultedTask);
if (contingentProperties != null)
var exceptionsHolderField = contingentProperties.GetType().GetField("m_exceptionsHolder", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
if (exceptionsHolderField != null)
{
var exceptionsHolderField = contingentProperties.GetType().GetField("m_exceptionsHolder", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
if (exceptionsHolderField != null)
holderObject = exceptionsHolderField.GetValue(contingentProperties);
if (holderObject != null)
{
holderObject = exceptionsHolderField.GetValue(contingentProperties);
if (holderObject != null)
{
isHandledField = holderObject.GetType().GetField("m_isHandled", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
}
isHandledField = holderObject.GetType().GetField("m_isHandled", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
}
}
}
Assert.NotNull(holderObject);
Assert.NotNull(isHandledField);
Assert.False((bool)isHandledField.GetValue(holderObject), "Expected FromException task to be unobserved before accessing Exception");
var ignored = faultedTask.Exception;
Assert.True((bool)isHandledField.GetValue(holderObject), "Expected FromException task to be observed after accessing Exception");
}
Assert.NotNull(holderObject);
Assert.NotNull(isHandledField);
Assert.False((bool)isHandledField.GetValue(holderObject), "Expected FromException task to be unobserved before accessing Exception");
var ignored = faultedTask.Exception;
Assert.True((bool)isHandledField.GetValue(holderObject), "Expected FromException task to be observed after accessing Exception");
}
[Fact]

View File

@ -1 +1 @@
a2db51d7b4ab9b4e90c8d7b9d45a8934b54855c5
196cf2f7776d071cea281cf63258174927148d4c

View File

@ -291,6 +291,7 @@ namespace System.Threading.Tasks.Tests
}
[Fact]
[SkipOnTargetFramework(TargetFrameworkMonikers.UapAot, "Uses reflection to access an internal method of the TaskScheduler class.")]
public static void GetTaskSchedulersForDebugger_ReturnsDefaultScheduler()
{
MethodInfo getTaskSchedulersForDebuggerMethod = typeof(TaskScheduler).GetTypeInfo().GetDeclaredMethod("GetTaskSchedulersForDebugger");
@ -300,6 +301,7 @@ namespace System.Threading.Tasks.Tests
}
[ConditionalFact(nameof(DebuggerIsAttached))]
[SkipOnTargetFramework(TargetFrameworkMonikers.UapAot, "Uses reflection to access an internal method of the TaskScheduler class.")]
public static void GetTaskSchedulersForDebugger_DebuggerAttached_ReturnsAllSchedulers()
{
MethodInfo getTaskSchedulersForDebuggerMethod = typeof(TaskScheduler).GetTypeInfo().GetDeclaredMethod("GetTaskSchedulersForDebugger");
@ -315,6 +317,7 @@ namespace System.Threading.Tasks.Tests
}
[ConditionalFact(nameof(DebuggerIsAttached))]
[SkipOnTargetFramework(TargetFrameworkMonikers.UapAot, "Uses reflection to access an internal method of the TaskScheduler class.")]
public static void GetScheduledTasksForDebugger_DebuggerAttached_ReturnsTasksFromCustomSchedulers()
{
var nonExecutingScheduler = new BuggyTaskScheduler(faultQueues: false);