diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems index 2c5f234cc2d163..99a96a18e05294 100644 --- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems +++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems @@ -1287,8 +1287,8 @@ - - + + diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/FutureFactory.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/TaskFactory_T.cs similarity index 100% rename from src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/FutureFactory.cs rename to src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/TaskFactory_T.cs diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Future.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task_T.cs similarity index 99% rename from src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Future.cs rename to src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task_T.cs index e9be1f3d76ba7e..e6a5b6dc565770 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Future.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task_T.cs @@ -54,7 +54,7 @@ namespace System.Threading.Tasks /// and may be used from multiple threads concurrently. /// /// - [DebuggerTypeProxy(typeof(SystemThreadingTasks_FutureDebugView<>))] + [DebuggerTypeProxy(typeof(SystemThreadingTasks_TaskDebugView<>))] [DebuggerDisplay("Id = {Id}, Status = {Status}, Method = {DebuggerDisplayMethodDescription}, Result = {DebuggerDisplayResultDescription}")] public class Task : Task { @@ -1172,16 +1172,16 @@ internal Task ContinueWith(Func, TNewResul out TaskCreationOptions creationOptions, out InternalTaskOptions internalOptions); - Task continuationFuture = new ContinuationResultTaskFromResultTask( + Task continuationTask = new ContinuationResultTaskFromResultTask( this, continuationFunction, null, creationOptions, internalOptions ); // Register the continuation. If synchronous execution is requested, this may // actually invoke the continuation before returning. - ContinueWithCore(continuationFuture, scheduler, cancellationToken, continuationOptions); + ContinueWithCore(continuationTask, scheduler, cancellationToken, continuationOptions); - return continuationFuture; + return continuationTask; } #endregion @@ -1393,16 +1393,16 @@ internal Task ContinueWith(Func, object?, out TaskCreationOptions creationOptions, out InternalTaskOptions internalOptions); - Task continuationFuture = new ContinuationResultTaskFromResultTask( + Task continuationTask = new ContinuationResultTaskFromResultTask( this, continuationFunction, state, creationOptions, internalOptions ); // Register the continuation. If synchronous execution is requested, this may // actually invoke the continuation before returning. - ContinueWithCore(continuationFuture, scheduler, cancellationToken, continuationOptions); + ContinueWithCore(continuationTask, scheduler, cancellationToken, continuationOptions); - return continuationFuture; + return continuationTask; } #endregion @@ -1411,11 +1411,11 @@ internal Task ContinueWith(Func, object?, } // Proxy class for better debugging experience - internal sealed class SystemThreadingTasks_FutureDebugView + internal sealed class SystemThreadingTasks_TaskDebugView { private readonly Task m_task; - public SystemThreadingTasks_FutureDebugView(Task task) + public SystemThreadingTasks_TaskDebugView(Task task) { Debug.Assert(task != null); m_task = task; diff --git a/src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/Task/TaskAPMTest.cs b/src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/Task/TaskAPMTest.cs index 27731c560ddea2..9fe6a65a8b37d0 100644 --- a/src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/Task/TaskAPMTest.cs +++ b/src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/Task/TaskAPMTest.cs @@ -22,7 +22,7 @@ namespace System.Threading.Tasks.Tests public sealed class TaskAPMTests : IDisposable { /// - /// Used to indicate whether to test TPL's Task or Future functionality for the APM pattern + /// Used to indicate whether to test TPL's Task or Task functionality for the APM pattern /// private bool _hasReturnType; @@ -234,7 +234,7 @@ public void EndDoTask(IAsyncResult asyncResult) } /// - /// A dummy class that simulates a long running Future that implements IAsyncResult methods + /// A dummy class that simulates a long running Task that implements IAsyncResult methods /// public sealed class LongTask : LongTask { diff --git a/src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/Task/TaskContinueWhenAllTests.cs b/src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/Task/TaskContinueWhenAllTests.cs index 6a8d9ee5e9a1d9..7f0523765f0596 100644 --- a/src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/Task/TaskContinueWhenAllTests.cs +++ b/src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/Task/TaskContinueWhenAllTests.cs @@ -22,80 +22,80 @@ public static void TestContinueWhenAll_bare() int largeSize = 3; Task[] smallTaskArray = null; Task[] largeTaskArray = null; - Task[] smallFutureArray = null; - Task[] largeFutureArray = null; + Task[] smallTaskWithResultArray = null; + Task[] largeTaskWithResultArray = null; Task tSmall; Task tLarge; for (int i = 0; i < 2; i++) { - bool antecedentsAreFutures = (i == 0); + bool antecedentsHaveResult = (i == 0); for (int j = 0; j < 2; j++) { - bool continuationsAreFutures = (j == 0); + bool continuationsHaveResult = (j == 0); for (int x = 0; x < 2; x++) { - bool useFutureFactory = (x == 0); + bool useResultTaskFactory = (x == 0); // This would be a nonsensical combination - if (useFutureFactory && !continuationsAreFutures) continue; + if (useResultTaskFactory && !continuationsHaveResult) continue; Debug.WriteLine(" Testing {0} = {3}.Factory.CWAll({1}, {2})", - continuationsAreFutures ? "Future" : "Task", - antecedentsAreFutures ? "Future[]" : "Task[]", - continuationsAreFutures ? "func" : "action", - useFutureFactory ? "Task" : "Task"); + continuationsHaveResult ? "Task" : "Task", + antecedentsHaveResult ? "Task[]" : "Task[]", + continuationsHaveResult ? "func" : "action", + useResultTaskFactory ? "Task" : "Task"); // Set up our antecedents - if (antecedentsAreFutures) + if (antecedentsHaveResult) { - makeCWAllFutureArrays(smallSize, largeSize, out smallFutureArray, out largeFutureArray); - if (continuationsAreFutures) + makeCWAllTaskWithResultArrays(smallSize, largeSize, out smallTaskWithResultArray, out largeTaskWithResultArray); + if (continuationsHaveResult) { - if (useFutureFactory) + if (useResultTaskFactory) { - // antecedentsAreFutures=true, continuationsAreFutures=true, useFutureFactory = true - tSmall = Task.Factory.ContinueWhenAll(smallFutureArray, (Task[] finishedArray) => 10); - tLarge = Task.Factory.ContinueWhenAll(largeFutureArray, (Task[] finishedArray) => 20); + // antecedentsHaveResult=true, continuationsHaveResult=true, useResultTaskFactory = true + tSmall = Task.Factory.ContinueWhenAll(smallTaskWithResultArray, (Task[] finishedArray) => 10); + tLarge = Task.Factory.ContinueWhenAll(largeTaskWithResultArray, (Task[] finishedArray) => 20); } - else // useFutureFactory = false (use Task factory) + else // useResultTaskFactory = false (use Task factory) { - // antecedentsAreFutures=true, continuationsAreFutures=true, useFutureFactory = false - tSmall = Task.Factory.ContinueWhenAll(smallFutureArray, (Task[] finishedArray) => 10); - tLarge = Task.Factory.ContinueWhenAll(largeFutureArray, (Task[] finishedArray) => 20); + // antecedentsHaveResult=true, continuationsHaveResult=true, useResultTaskFactory = false + tSmall = Task.Factory.ContinueWhenAll(smallTaskWithResultArray, (Task[] finishedArray) => 10); + tLarge = Task.Factory.ContinueWhenAll(largeTaskWithResultArray, (Task[] finishedArray) => 20); } } - else // continuationsAreFutures = false (continuations are Tasks) + else // continuationsHaveResult = false (continuations are Tasks) { - // antecedentsAreFutures=true, continuationsAreFutures=false, useFutureFactory = false - tSmall = Task.Factory.ContinueWhenAll(smallFutureArray, (Task[] finishedArray) => { }); - tLarge = Task.Factory.ContinueWhenAll(largeFutureArray, (Task[] finishedArray) => { }); + // antecedentsHaveResult=true, continuationsHaveResult=false, useResultTaskFactory = false + tSmall = Task.Factory.ContinueWhenAll(smallTaskWithResultArray, (Task[] finishedArray) => { }); + tLarge = Task.Factory.ContinueWhenAll(largeTaskWithResultArray, (Task[] finishedArray) => { }); } - // Kick off the smallFutureArray - startTaskArray(smallFutureArray); + // Kick off the smallTaskWithResultArray + startTaskArray(smallTaskWithResultArray); } - else // antecedentsAreFutures = false (antecedents are Tasks) + else // antecedentsHaveResult = false (antecedents are Tasks) { makeCWAllTaskArrays(smallSize, largeSize, out smallTaskArray, out largeTaskArray); - if (continuationsAreFutures) + if (continuationsHaveResult) { - if (useFutureFactory) + if (useResultTaskFactory) { - // antecedentsAreFutures=false, continuationsAreFutures=true, useFutureFactory = true + // antecedentsHaveResult=false, continuationsHaveResult=true, useResultTaskFactory = true tSmall = Task.Factory.ContinueWhenAll(smallTaskArray, (Task[] finishedArray) => 10); tLarge = Task.Factory.ContinueWhenAll(largeTaskArray, (Task[] finishedArray) => 20); } - else // useFutureFactory = false (use TaskFactory) + else // useResultTaskFactory = false (use TaskFactory) { - // antecedentsAreFutures=false, continuationsAreFutures=true, useFutureFactory = false + // antecedentsHaveResult=false, continuationsHaveResult=true, useResultTaskFactory = false tSmall = Task.Factory.ContinueWhenAll(smallTaskArray, (Task[] finishedArray) => 10); tLarge = Task.Factory.ContinueWhenAll(largeTaskArray, (Task[] finishedArray) => 20); } } - else // continuationsAreFutures = false (continuations are Tasks) + else // continuationsHaveResult = false (continuations are Tasks) { - // antecedentsAreFutures=false, continuationsAreFutures=false, useFutureFactory = false + // antecedentsHaveResult=false, continuationsHaveResult=false, useResultTaskFactory = false tSmall = Task.Factory.ContinueWhenAll(smallTaskArray, (Task[] finishedArray) => { }); tLarge = Task.Factory.ContinueWhenAll(largeTaskArray, (Task[] finishedArray) => { }); } @@ -109,7 +109,7 @@ public static void TestContinueWhenAll_bare() Exception ex = null; try { - if (continuationsAreFutures) result = ((Task)tSmall).Result; + if (continuationsHaveResult) result = ((Task)tSmall).Result; else tSmall.Wait(); } catch (Exception e) @@ -118,19 +118,19 @@ public static void TestContinueWhenAll_bare() } Assert.Null(ex); // , "Did not expect exception from tSmall.Wait()") - Assert.True((result == 10) || (!continuationsAreFutures), "Expected valid result from tSmall"); + Assert.True((result == 10) || (!continuationsHaveResult), "Expected valid result from tSmall"); Assert.False(tLarge.IsCompleted, "tLarge completed before its time"); // // Now start the large array // - if (antecedentsAreFutures) startTaskArray(largeFutureArray); + if (antecedentsHaveResult) startTaskArray(largeTaskWithResultArray); else startTaskArray(largeTaskArray); result = 0; try { - if (continuationsAreFutures) result = ((Task)tLarge).Result; + if (continuationsHaveResult) result = ((Task)tLarge).Result; else tLarge.Wait(); } catch (Exception e) @@ -139,10 +139,10 @@ public static void TestContinueWhenAll_bare() } Assert.Null(ex); // , "Did not expect exception from tLarge.Wait()") - Assert.True((result == 20) || (!continuationsAreFutures), "Expected valid result from tLarge"); - } // end x-loop (FutureFactory or TaskFactory) - } // end j-loop (continuations are futures or tasks) - }// end i-loop (antecedents are futures or tasks) + Assert.True((result == 20) || (!continuationsHaveResult), "Expected valid result from tLarge"); + } // end x-loop (ResultTaskFactory or TaskFactory) + } // end j-loop (continuations are Task or Task) + }// end i-loop (antecedents are Task or Task) } // Test functionality of ContinueWhenAll overloads w/ CancellationToken @@ -153,16 +153,16 @@ public static void TestContinueWhenAll_CancellationToken() int largeSize = 3; Task[] smallTaskArray = null; Task[] largeTaskArray = null; - Task[] smallFutureArray = null; - Task[] largeFutureArray = null; + Task[] smallTaskWithResultArray = null; + Task[] largeTaskWithResultArray = null; Task tSmall; Task tLarge; for (int i = 0; i < 2; i++) { - bool antecedentsAreFutures = (i == 0); + bool antecedentsHaveResult = (i == 0); for (int j = 0; j < 2; j++) { - bool continuationsAreFutures = (j == 0); + bool continuationsHaveResult = (j == 0); for (int k = 0; k < 2; k++) { bool preCanceledToken = (k == 0); @@ -172,68 +172,68 @@ public static void TestContinueWhenAll_CancellationToken() for (int x = 0; x < 2; x++) { - bool useFutureFactory = (x == 0); + bool useResultTaskFactory = (x == 0); // This would be a nonsensical combination - if (useFutureFactory && !continuationsAreFutures) continue; + if (useResultTaskFactory && !continuationsHaveResult) continue; Debug.WriteLine(" Testing {0} = {4}.Factory.CWAll({1}, {3}, ct({2}))", - continuationsAreFutures ? "Future" : "Task", - antecedentsAreFutures ? "Future[]" : "Task[]", + continuationsHaveResult ? "Task" : "Task", + antecedentsHaveResult ? "Task[]" : "Task[]", preCanceledToken ? "signaled" : "unsignaled", - continuationsAreFutures ? "func" : "action", - useFutureFactory ? "Task" : "Task"); + continuationsHaveResult ? "func" : "action", + useResultTaskFactory ? "Task" : "Task"); // Set up our antecedents - if (antecedentsAreFutures) + if (antecedentsHaveResult) { - makeCWAllFutureArrays(smallSize, largeSize, out smallFutureArray, out largeFutureArray); - if (continuationsAreFutures) + makeCWAllTaskWithResultArrays(smallSize, largeSize, out smallTaskWithResultArray, out largeTaskWithResultArray); + if (continuationsHaveResult) { - if (useFutureFactory) + if (useResultTaskFactory) { - // antecedentsAreFutures=true, continuationsAreFutures=true, useFutureFactory = true - tSmall = Task.Factory.ContinueWhenAll(smallFutureArray, (Task[] finishedArray) => 10, ct); - tLarge = Task.Factory.ContinueWhenAll(largeFutureArray, (Task[] finishedArray) => 20, ct); + // antecedentsHaveResult=true, continuationsHaveResult=true, useResultTaskFactory = true + tSmall = Task.Factory.ContinueWhenAll(smallTaskWithResultArray, (Task[] finishedArray) => 10, ct); + tLarge = Task.Factory.ContinueWhenAll(largeTaskWithResultArray, (Task[] finishedArray) => 20, ct); } - else // useFutureFactory = false (use Task factory) + else // useResultTaskFactory = false (use Task factory) { - // antecedentsAreFutures=true, continuationsAreFutures=true, useFutureFactory = false - tSmall = Task.Factory.ContinueWhenAll(smallFutureArray, (Task[] finishedArray) => 10, ct); - tLarge = Task.Factory.ContinueWhenAll(largeFutureArray, (Task[] finishedArray) => 20, ct); + // antecedentsHaveResult=true, continuationsHaveResult=true, useResultTaskFactory = false + tSmall = Task.Factory.ContinueWhenAll(smallTaskWithResultArray, (Task[] finishedArray) => 10, ct); + tLarge = Task.Factory.ContinueWhenAll(largeTaskWithResultArray, (Task[] finishedArray) => 20, ct); } } - else // continuationsAreFutures = false (continuations are Tasks) + else // continuationsHaveResult = false (continuations are Tasks) { - // antecedentsAreFutures=true, continuationsAreFutures=false, useFutureFactory = false - tSmall = Task.Factory.ContinueWhenAll(smallFutureArray, (Task[] finishedArray) => { }, ct); - tLarge = Task.Factory.ContinueWhenAll(largeFutureArray, (Task[] finishedArray) => { }, ct); + // antecedentsHaveResult=true, continuationsHaveResult=false, useResultTaskFactory = false + tSmall = Task.Factory.ContinueWhenAll(smallTaskWithResultArray, (Task[] finishedArray) => { }, ct); + tLarge = Task.Factory.ContinueWhenAll(largeTaskWithResultArray, (Task[] finishedArray) => { }, ct); } - // Kick off the smallFutureArray - startTaskArray(smallFutureArray); + // Kick off the smallTaskWithResultArray + startTaskArray(smallTaskWithResultArray); } - else // antecedentsAreFutures = false (antecedents are Tasks) + else // antecedentsHaveResult = false (antecedents are Tasks) { makeCWAllTaskArrays(smallSize, largeSize, out smallTaskArray, out largeTaskArray); - if (continuationsAreFutures) + if (continuationsHaveResult) { - if (useFutureFactory) + if (useResultTaskFactory) { - // antecedentsAreFutures=false, continuationsAreFutures=true, useFutureFactory = true + // antecedentsHaveResult=false, continuationsHaveResult=true, useResultTaskFactory = true tSmall = Task.Factory.ContinueWhenAll(smallTaskArray, (Task[] finishedArray) => 10, ct); tLarge = Task.Factory.ContinueWhenAll(largeTaskArray, (Task[] finishedArray) => 20, ct); } - else // useFutureFactory = false (use TaskFactory) + else // useResultTaskFactory = false (use TaskFactory) { - // antecedentsAreFutures=false, continuationsAreFutures=true, useFutureFactory = false + // antecedentsHaveResult=false, continuationsHaveResult=true, useResultTaskFactory = false tSmall = Task.Factory.ContinueWhenAll(smallTaskArray, (Task[] finishedArray) => 10, ct); tLarge = Task.Factory.ContinueWhenAll(largeTaskArray, (Task[] finishedArray) => 20, ct); } } - else // continuationsAreFutures = false (continuations are Tasks) + else // continuationsHaveResult = false (continuations are Tasks) { - // antecedentsAreFutures=false, continuationsAreFutures=false, useFutureFactory = false + // antecedentsHaveResult=false, continuationsHaveResult=false, useResultTaskFactory = false tSmall = Task.Factory.ContinueWhenAll(smallTaskArray, (Task[] finishedArray) => { }, ct); tLarge = Task.Factory.ContinueWhenAll(largeTaskArray, (Task[] finishedArray) => { }, ct); } @@ -247,7 +247,7 @@ public static void TestContinueWhenAll_CancellationToken() Exception ex = null; try { - if (continuationsAreFutures) result = ((Task)tSmall).Result; + if (continuationsHaveResult) result = ((Task)tSmall).Result; else tSmall.Wait(); } catch (Exception e) @@ -270,20 +270,20 @@ public static void TestContinueWhenAll_CancellationToken() } else // !preCanceledToken { - Assert.True((result == 10) || (!continuationsAreFutures), "Expected valid result from tSmall"); + Assert.True((result == 10) || (!continuationsHaveResult), "Expected valid result from tSmall"); Assert.False(tLarge.IsCompleted, "tLarge completed before its time"); } // // Now start the large array // - if (antecedentsAreFutures) startTaskArray(largeFutureArray); + if (antecedentsHaveResult) startTaskArray(largeTaskWithResultArray); else startTaskArray(largeTaskArray); result = 0; try { - if (continuationsAreFutures) result = ((Task)tLarge).Result; + if (continuationsHaveResult) result = ((Task)tLarge).Result; else tLarge.Wait(); } catch (Exception e) @@ -306,12 +306,12 @@ public static void TestContinueWhenAll_CancellationToken() } else // !preCanceledToken { - Assert.True((result == 20) || (!continuationsAreFutures), "Expected valid result from tLarge"); + Assert.True((result == 20) || (!continuationsHaveResult), "Expected valid result from tLarge"); } - } // end x-loop (FutureFactory or TaskFactory) + } // end x-loop (ResultTaskFactory or TaskFactory) } // end k-loop (preCanceled or not) - } // end j-loop (continuations are futures or tasks) - }// end i-loop (antecedents are futures or tasks) + } // end j-loop (continuations are Task or Task) + }// end i-loop (antecedents are Task or Task) } // Test functionality of ContinueWhenAll overloads w/ TaskContinuationOptions @@ -322,16 +322,16 @@ public static void TestContinueWhenAll_TaskContinuationOptions() int largeSize = 3; Task[] smallTaskArray = null; Task[] largeTaskArray = null; - Task[] smallFutureArray = null; - Task[] largeFutureArray = null; + Task[] smallTaskWithResultArray = null; + Task[] largeTaskWithResultArray = null; Task tSmall; Task tLarge; for (int i = 0; i < 2; i++) { - bool antecedentsAreFutures = (i == 0); + bool antecedentsHaveResult = (i == 0); for (int j = 0; j < 2; j++) { - bool continuationsAreFutures = (j == 0); + bool continuationsHaveResult = (j == 0); for (int k = 0; k < 2; k++) { bool longRunning = (k == 0); @@ -339,68 +339,68 @@ public static void TestContinueWhenAll_TaskContinuationOptions() for (int x = 0; x < 2; x++) { - bool useFutureFactory = (x == 0); + bool useResultTaskFactory = (x == 0); // This would be a nonsensical combination - if (useFutureFactory && !continuationsAreFutures) continue; + if (useResultTaskFactory && !continuationsHaveResult) continue; Debug.WriteLine(" Testing {0} = {3}.Factory.CWAll({1}, {2}, {4})", - continuationsAreFutures ? "Future" : "Task", - antecedentsAreFutures ? "Future[]" : "Task[]", - continuationsAreFutures ? "func" : "action", - useFutureFactory ? "Task" : "Task", + continuationsHaveResult ? "Task" : "Task", + antecedentsHaveResult ? "Task[]" : "Task[]", + continuationsHaveResult ? "func" : "action", + useResultTaskFactory ? "Task" : "Task", tco); // Set up our antecedents - if (antecedentsAreFutures) + if (antecedentsHaveResult) { - makeCWAllFutureArrays(smallSize, largeSize, out smallFutureArray, out largeFutureArray); - if (continuationsAreFutures) + makeCWAllTaskWithResultArrays(smallSize, largeSize, out smallTaskWithResultArray, out largeTaskWithResultArray); + if (continuationsHaveResult) { - if (useFutureFactory) + if (useResultTaskFactory) { - // antecedentsAreFutures=true, continuationsAreFutures=true, useFutureFactory = true - tSmall = Task.Factory.ContinueWhenAll(smallFutureArray, (Task[] finishedArray) => 10, tco); - tLarge = Task.Factory.ContinueWhenAll(largeFutureArray, (Task[] finishedArray) => 20, tco); + // antecedentsHaveResult=true, continuationsHaveResult=true, useResultTaskFactory = true + tSmall = Task.Factory.ContinueWhenAll(smallTaskWithResultArray, (Task[] finishedArray) => 10, tco); + tLarge = Task.Factory.ContinueWhenAll(largeTaskWithResultArray, (Task[] finishedArray) => 20, tco); } - else // useFutureFactory = false (use Task factory) + else // useResultTaskFactory = false (use Task factory) { - // antecedentsAreFutures=true, continuationsAreFutures=true, useFutureFactory = false - tSmall = Task.Factory.ContinueWhenAll(smallFutureArray, (Task[] finishedArray) => 10, tco); - tLarge = Task.Factory.ContinueWhenAll(largeFutureArray, (Task[] finishedArray) => 20, tco); + // antecedentsHaveResult=true, continuationsHaveResult=true, useResultTaskFactory = false + tSmall = Task.Factory.ContinueWhenAll(smallTaskWithResultArray, (Task[] finishedArray) => 10, tco); + tLarge = Task.Factory.ContinueWhenAll(largeTaskWithResultArray, (Task[] finishedArray) => 20, tco); } } - else // continuationsAreFutures = false (continuations are Tasks) + else // continuationsHaveResult = false (continuations are Tasks) { - // antecedentsAreFutures=true, continuationsAreFutures=false, useFutureFactory = false - tSmall = Task.Factory.ContinueWhenAll(smallFutureArray, (Task[] finishedArray) => { }, tco); - tLarge = Task.Factory.ContinueWhenAll(largeFutureArray, (Task[] finishedArray) => { }, tco); + // antecedentsHaveResult=true, continuationsHaveResult=false, useResultTaskFactory = false + tSmall = Task.Factory.ContinueWhenAll(smallTaskWithResultArray, (Task[] finishedArray) => { }, tco); + tLarge = Task.Factory.ContinueWhenAll(largeTaskWithResultArray, (Task[] finishedArray) => { }, tco); } - // Kick off the smallFutureArray - startTaskArray(smallFutureArray); + // Kick off the smallTaskWithResultArray + startTaskArray(smallTaskWithResultArray); } - else // antecedentsAreFutures = false (antecedents are Tasks) + else // antecedentsHaveResult = false (antecedents are Tasks) { makeCWAllTaskArrays(smallSize, largeSize, out smallTaskArray, out largeTaskArray); - if (continuationsAreFutures) + if (continuationsHaveResult) { - if (useFutureFactory) + if (useResultTaskFactory) { - // antecedentsAreFutures=false, continuationsAreFutures=true, useFutureFactory = true + // antecedentsHaveResult=false, continuationsHaveResult=true, useResultTaskFactory = true tSmall = Task.Factory.ContinueWhenAll(smallTaskArray, (Task[] finishedArray) => 10, tco); tLarge = Task.Factory.ContinueWhenAll(largeTaskArray, (Task[] finishedArray) => 20, tco); } - else // useFutureFactory = false (use TaskFactory) + else // useResultTaskFactory = false (use TaskFactory) { - // antecedentsAreFutures=false, continuationsAreFutures=true, useFutureFactory = false + // antecedentsHaveResult=false, continuationsHaveResult=true, useResultTaskFactory = false tSmall = Task.Factory.ContinueWhenAll(smallTaskArray, (Task[] finishedArray) => 10, tco); tLarge = Task.Factory.ContinueWhenAll(largeTaskArray, (Task[] finishedArray) => 20, tco); } } - else // continuationsAreFutures = false (continuations are Tasks) + else // continuationsHaveResult = false (continuations are Tasks) { - // antecedentsAreFutures=false, continuationsAreFutures=false, useFutureFactory = false + // antecedentsHaveResult=false, continuationsHaveResult=false, useResultTaskFactory = false tSmall = Task.Factory.ContinueWhenAll(smallTaskArray, (Task[] finishedArray) => { }, tco); tLarge = Task.Factory.ContinueWhenAll(largeTaskArray, (Task[] finishedArray) => { }, tco); } @@ -414,7 +414,7 @@ public static void TestContinueWhenAll_TaskContinuationOptions() Exception ex = null; try { - if (continuationsAreFutures) result = ((Task)tSmall).Result; + if (continuationsHaveResult) result = ((Task)tSmall).Result; else tSmall.Wait(); } catch (Exception e) @@ -423,7 +423,7 @@ public static void TestContinueWhenAll_TaskContinuationOptions() } Assert.Null(ex); // , "Did not expect exception from tSmall.Wait()") - Assert.True((result == 10) || (!continuationsAreFutures), "Expected valid result from tSmall"); + Assert.True((result == 10) || (!continuationsHaveResult), "Expected valid result from tSmall"); Assert.False(tLarge.IsCompleted, "tLarge completed before its time"); Assert.Equal((tSmall.CreationOptions & TaskCreationOptions.LongRunning) != 0, longRunning); Assert.True((tSmall.CreationOptions == TaskCreationOptions.None) || longRunning, "tSmall CreationOptions should be None unless longRunning is true"); @@ -431,13 +431,13 @@ public static void TestContinueWhenAll_TaskContinuationOptions() // // Now start the large array // - if (antecedentsAreFutures) startTaskArray(largeFutureArray); + if (antecedentsHaveResult) startTaskArray(largeTaskWithResultArray); else startTaskArray(largeTaskArray); result = 0; try { - if (continuationsAreFutures) result = ((Task)tLarge).Result; + if (continuationsHaveResult) result = ((Task)tLarge).Result; else tLarge.Wait(); } catch (Exception e) @@ -446,13 +446,13 @@ public static void TestContinueWhenAll_TaskContinuationOptions() } Assert.Null(ex); // , "Did not expect exception from tLarge.Wait()") - Assert.True((result == 20) || (!continuationsAreFutures), "Expected valid result from tLarge"); + Assert.True((result == 20) || (!continuationsHaveResult), "Expected valid result from tLarge"); Assert.Equal((tLarge.CreationOptions & TaskCreationOptions.LongRunning) != 0, longRunning); Assert.True((tLarge.CreationOptions == TaskCreationOptions.None) || longRunning, "tLarge CreationOptions should be None unless longRunning is true"); - } // end x-loop (FutureFactory or TaskFactory) + } // end x-loop (ResultTaskFactory or TaskFactory) } // end k-loop (TaskContinuationOptions are LongRunning or None) - } // end j-loop (continuations are futures or tasks) - }// end i-loop (antecedents are futures or tasks) + } // end j-loop (continuations are Task or Task) + }// end i-loop (antecedents are Task or Task) } // Test functionality of "full up" ContinueWhenAll overloads @@ -463,16 +463,16 @@ public static void TestCWAll_CancellationToken_TaskContinuation_TaskScheduler() int largeSize = 3; Task[] smallTaskArray = null; Task[] largeTaskArray = null; - Task[] smallFutureArray = null; - Task[] largeFutureArray = null; + Task[] smallTaskWithResultArray = null; + Task[] largeTaskWithResultArray = null; Task tSmall; Task tLarge; for (int i = 0; i < 2; i++) { - bool antecedentsAreFutures = (i == 0); + bool antecedentsHaveResult = (i == 0); for (int j = 0; j < 2; j++) { - bool continuationsAreFutures = (j == 0); + bool continuationsHaveResult = (j == 0); for (int k = 0; k < 2; k++) { bool preCanceledToken = (k == 0); @@ -482,71 +482,71 @@ public static void TestCWAll_CancellationToken_TaskContinuation_TaskScheduler() for (int x = 0; x < 2; x++) { - bool useFutureFactory = (x == 0); + bool useResultTaskFactory = (x == 0); // This would be a nonsensical combination - if (useFutureFactory && !continuationsAreFutures) continue; + if (useResultTaskFactory && !continuationsHaveResult) continue; TaskContinuationOptions tco = TaskContinuationOptions.None; // for now TaskScheduler ts = TaskScheduler.Default; Debug.WriteLine(" Testing {0} = {4}.Factory.CWAll({1}, {3}, ct({2}), tco.None, ts.Default)", - continuationsAreFutures ? "Future" : "Task", - antecedentsAreFutures ? "Future[]" : "Task[]", + continuationsHaveResult ? "Task" : "Task", + antecedentsHaveResult ? "Task[]" : "Task[]", preCanceledToken ? "signaled" : "unsignaled", - continuationsAreFutures ? "func" : "action", - useFutureFactory ? "Task" : "Task"); + continuationsHaveResult ? "func" : "action", + useResultTaskFactory ? "Task" : "Task"); // Set up our antecedents - if (antecedentsAreFutures) + if (antecedentsHaveResult) { - makeCWAllFutureArrays(smallSize, largeSize, out smallFutureArray, out largeFutureArray); - if (continuationsAreFutures) + makeCWAllTaskWithResultArrays(smallSize, largeSize, out smallTaskWithResultArray, out largeTaskWithResultArray); + if (continuationsHaveResult) { - if (useFutureFactory) + if (useResultTaskFactory) { - // antecedentsAreFutures=true, continuationsAreFutures=true, useFutureFactory = true - tSmall = Task.Factory.ContinueWhenAll(smallFutureArray, (Task[] finishedArray) => 10, ct, tco, ts); - tLarge = Task.Factory.ContinueWhenAll(largeFutureArray, (Task[] finishedArray) => 20, ct, tco, ts); + // antecedentsHaveResult=true, continuationsHaveResult=true, useResultTaskFactory = true + tSmall = Task.Factory.ContinueWhenAll(smallTaskWithResultArray, (Task[] finishedArray) => 10, ct, tco, ts); + tLarge = Task.Factory.ContinueWhenAll(largeTaskWithResultArray, (Task[] finishedArray) => 20, ct, tco, ts); } - else // useFutureFactory = false (use Task factory) + else // useResultTaskFactory = false (use Task factory) { - // antecedentsAreFutures=true, continuationsAreFutures=true, useFutureFactory = false - tSmall = Task.Factory.ContinueWhenAll(smallFutureArray, (Task[] finishedArray) => 10, ct, tco, ts); - tLarge = Task.Factory.ContinueWhenAll(largeFutureArray, (Task[] finishedArray) => 20, ct, tco, ts); + // antecedentsHaveResult=true, continuationsHaveResult=true, useResultTaskFactory = false + tSmall = Task.Factory.ContinueWhenAll(smallTaskWithResultArray, (Task[] finishedArray) => 10, ct, tco, ts); + tLarge = Task.Factory.ContinueWhenAll(largeTaskWithResultArray, (Task[] finishedArray) => 20, ct, tco, ts); } } - else // continuationsAreFutures = false (continuations are Tasks) + else // continuationsHaveResult = false (continuations are Tasks) { - // antecedentsAreFutures=true, continuationsAreFutures=false, useFutureFactory = false - tSmall = Task.Factory.ContinueWhenAll(smallFutureArray, (Task[] finishedArray) => { }, ct, tco, ts); - tLarge = Task.Factory.ContinueWhenAll(largeFutureArray, (Task[] finishedArray) => { }, ct, tco, ts); + // antecedentsHaveResult=true, continuationsHaveResult=false, useResultTaskFactory = false + tSmall = Task.Factory.ContinueWhenAll(smallTaskWithResultArray, (Task[] finishedArray) => { }, ct, tco, ts); + tLarge = Task.Factory.ContinueWhenAll(largeTaskWithResultArray, (Task[] finishedArray) => { }, ct, tco, ts); } - // Kick off the smallFutureArray - startTaskArray(smallFutureArray); + // Kick off the smallTaskWithResultArray + startTaskArray(smallTaskWithResultArray); } - else // antecedentsAreFutures = false (antecedents are Tasks) + else // antecedentsHaveResult = false (antecedents are Tasks) { makeCWAllTaskArrays(smallSize, largeSize, out smallTaskArray, out largeTaskArray); - if (continuationsAreFutures) + if (continuationsHaveResult) { - if (useFutureFactory) + if (useResultTaskFactory) { - // antecedentsAreFutures=false, continuationsAreFutures=true, useFutureFactory = true + // antecedentsHaveResult=false, continuationsHaveResult=true, useResultTaskFactory = true tSmall = Task.Factory.ContinueWhenAll(smallTaskArray, (Task[] finishedArray) => 10, ct, tco, ts); tLarge = Task.Factory.ContinueWhenAll(largeTaskArray, (Task[] finishedArray) => 20, ct, tco, ts); } - else // useFutureFactory = false (use TaskFactory) + else // useResultTaskFactory = false (use TaskFactory) { - // antecedentsAreFutures=false, continuationsAreFutures=true, useFutureFactory = false + // antecedentsHaveResult=false, continuationsHaveResult=true, useResultTaskFactory = false tSmall = Task.Factory.ContinueWhenAll(smallTaskArray, (Task[] finishedArray) => 10, ct, tco, ts); tLarge = Task.Factory.ContinueWhenAll(largeTaskArray, (Task[] finishedArray) => 20, ct, tco, ts); } } - else // continuationsAreFutures = false (continuations are Tasks) + else // continuationsHaveResult = false (continuations are Tasks) { - // antecedentsAreFutures=false, continuationsAreFutures=false, useFutureFactory = false + // antecedentsHaveResult=false, continuationsHaveResult=false, useResultTaskFactory = false tSmall = Task.Factory.ContinueWhenAll(smallTaskArray, (Task[] finishedArray) => { }, ct, tco, ts); tLarge = Task.Factory.ContinueWhenAll(largeTaskArray, (Task[] finishedArray) => { }, ct, tco, ts); } @@ -560,7 +560,7 @@ public static void TestCWAll_CancellationToken_TaskContinuation_TaskScheduler() Exception ex = null; try { - if (continuationsAreFutures) result = ((Task)tSmall).Result; + if (continuationsHaveResult) result = ((Task)tSmall).Result; else tSmall.Wait(); } catch (Exception e) @@ -583,20 +583,20 @@ public static void TestCWAll_CancellationToken_TaskContinuation_TaskScheduler() } else // !preCanceledToken { - Assert.True((result == 10) || (!continuationsAreFutures), "Expected valid result from tSmall"); + Assert.True((result == 10) || (!continuationsHaveResult), "Expected valid result from tSmall"); Assert.False(tLarge.IsCompleted, "tLarge completed before its time"); } // // Now start the large array // - if (antecedentsAreFutures) startTaskArray(largeFutureArray); + if (antecedentsHaveResult) startTaskArray(largeTaskWithResultArray); else startTaskArray(largeTaskArray); result = 0; try { - if (continuationsAreFutures) result = ((Task)tLarge).Result; + if (continuationsHaveResult) result = ((Task)tLarge).Result; else tLarge.Wait(); } catch (Exception e) @@ -619,12 +619,12 @@ public static void TestCWAll_CancellationToken_TaskContinuation_TaskScheduler() } else // !preCanceledToken { - Assert.True((result == 20) || (!continuationsAreFutures), "Expected valid result from tLarge"); + Assert.True((result == 20) || (!continuationsHaveResult), "Expected valid result from tLarge"); } - } // end x-loop (FutureFactory or TaskFactory) + } // end x-loop (ResultTaskFactory or TaskFactory) } // end k-loop (preCanceled or not) - } // end j-loop (continuations are futures or tasks) - }// end i-loop (antecedents are futures or tasks) + } // end j-loop (continuations are Task or Task) + }// end i-loop (antecedents are Task or Task) } [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] @@ -634,8 +634,8 @@ public static void RunContinueWhenAllTests_Exceptions() int largeSize = 3; Task[] largeTaskArray = null; Task[] smallTaskArray; - Task[] largeFutureArray = null; - Task[] smallFutureArray; + Task[] largeTaskWithResultArray = null; + Task[] smallTaskWithResultArray; // The remainder of this method will verify exceptional conditions @@ -715,7 +715,7 @@ public static void RunContinueWhenAllTests_Exceptions() // - // Test exceptions from continuing from Task[] => Task using FutureFactory + // Test exceptions from continuing from Task[] => Task using ResultTaskFactory // { makeCWAllTaskArrays(smallSize, largeSize, out smallTaskArray, out largeTaskArray); @@ -751,32 +751,32 @@ public static void RunContinueWhenAllTests_Exceptions() // Test exceptions from continuing from Task[] => Task // { - makeCWAllFutureArrays(smallSize, largeSize, out smallFutureArray, out largeFutureArray); + makeCWAllTaskWithResultArrays(smallSize, largeSize, out smallTaskWithResultArray, out largeTaskWithResultArray); Assert.Throws( - () => { Task.Factory.ContinueWhenAll(smallFutureArray, finishedArray => { }, CancellationToken.None, TaskContinuationOptions.None, (TaskScheduler)null); }); + () => { Task.Factory.ContinueWhenAll(smallTaskWithResultArray, finishedArray => { }, CancellationToken.None, TaskContinuationOptions.None, (TaskScheduler)null); }); Assert.Throws( - () => { Task.Factory.ContinueWhenAll(smallFutureArray, finishedArray => { }, TaskContinuationOptions.NotOnFaulted); }); + () => { Task.Factory.ContinueWhenAll(smallTaskWithResultArray, finishedArray => { }, TaskContinuationOptions.NotOnFaulted); }); Assert.Throws( - () => { Task.Factory.ContinueWhenAll(smallFutureArray, (Action[]>)null); }); + () => { Task.Factory.ContinueWhenAll(smallTaskWithResultArray, (Action[]>)null); }); Assert.Throws( - () => { Task.Factory.ContinueWhenAll(smallFutureArray, (Action[]>)null, CancellationToken.None); }); + () => { Task.Factory.ContinueWhenAll(smallTaskWithResultArray, (Action[]>)null, CancellationToken.None); }); Assert.Throws( - () => { Task.Factory.ContinueWhenAll(smallFutureArray, (Action[]>)null, TaskContinuationOptions.None); }); + () => { Task.Factory.ContinueWhenAll(smallTaskWithResultArray, (Action[]>)null, TaskContinuationOptions.None); }); Assert.Throws( - () => { Task.Factory.ContinueWhenAll(smallFutureArray, (Action[]>)null, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.Default); }); + () => { Task.Factory.ContinueWhenAll(smallTaskWithResultArray, (Action[]>)null, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.Default); }); Assert.Throws( () => { Task.Factory.ContinueWhenAll((Task[])null, finishedArray => { }); }); - smallFutureArray[0] = null; + smallTaskWithResultArray[0] = null; - AssertExtensions.Throws("tasks", () => Task.Factory.ContinueWhenAll(smallFutureArray, finishedArray => { })); + AssertExtensions.Throws("tasks", () => Task.Factory.ContinueWhenAll(smallTaskWithResultArray, finishedArray => { })); AssertExtensions.Throws("tasks", () => Task.Factory.ContinueWhenAll(new Task[0], finishedArray => { })); } @@ -784,66 +784,66 @@ public static void RunContinueWhenAllTests_Exceptions() // Test exceptions from continuing from Task[] => Task using TaskFactory // { - makeCWAllFutureArrays(smallSize, largeSize, out smallFutureArray, out largeFutureArray); + makeCWAllTaskWithResultArrays(smallSize, largeSize, out smallTaskWithResultArray, out largeTaskWithResultArray); Assert.Throws( - () => { Task.Factory.ContinueWhenAll(smallFutureArray, finishedArray => 10, CancellationToken.None, TaskContinuationOptions.None, (TaskScheduler)null); }); + () => { Task.Factory.ContinueWhenAll(smallTaskWithResultArray, finishedArray => 10, CancellationToken.None, TaskContinuationOptions.None, (TaskScheduler)null); }); Assert.Throws( - () => { Task.Factory.ContinueWhenAll(smallFutureArray, finishedArray => 10, TaskContinuationOptions.NotOnFaulted); }); + () => { Task.Factory.ContinueWhenAll(smallTaskWithResultArray, finishedArray => 10, TaskContinuationOptions.NotOnFaulted); }); Assert.Throws( - () => { Task.Factory.ContinueWhenAll(smallFutureArray, (Func)null); }); + () => { Task.Factory.ContinueWhenAll(smallTaskWithResultArray, (Func)null); }); Assert.Throws( - () => { Task.Factory.ContinueWhenAll(smallFutureArray, (Func)null, CancellationToken.None); }); + () => { Task.Factory.ContinueWhenAll(smallTaskWithResultArray, (Func)null, CancellationToken.None); }); Assert.Throws( - () => { Task.Factory.ContinueWhenAll(smallFutureArray, (Func)null, TaskContinuationOptions.None); }); + () => { Task.Factory.ContinueWhenAll(smallTaskWithResultArray, (Func)null, TaskContinuationOptions.None); }); Assert.Throws( - () => { Task.Factory.ContinueWhenAll(smallFutureArray, (Func)null, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.Default); }); + () => { Task.Factory.ContinueWhenAll(smallTaskWithResultArray, (Func)null, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.Default); }); Assert.Throws( () => { Task.Factory.ContinueWhenAll((Task[])null, finishedArray => 10); }); - smallFutureArray[0] = null; + smallTaskWithResultArray[0] = null; - AssertExtensions.Throws("tasks", () => Task.Factory.ContinueWhenAll(smallFutureArray, finishedArray => 10)); + AssertExtensions.Throws("tasks", () => Task.Factory.ContinueWhenAll(smallTaskWithResultArray, finishedArray => 10)); AssertExtensions.Throws("tasks", () => Task.Factory.ContinueWhenAll(new Task[0], finishedArray => 10)); } // - // Test exceptions from continuing from Task[] => Task using FutureFactory + // Test exceptions from continuing from Task[] => Task using ResultTaskFactory // { - makeCWAllFutureArrays(smallSize, largeSize, out smallFutureArray, out largeFutureArray); + makeCWAllTaskWithResultArrays(smallSize, largeSize, out smallTaskWithResultArray, out largeTaskWithResultArray); Assert.Throws( - () => { Task.Factory.ContinueWhenAll(smallFutureArray, finishedArray => 10, CancellationToken.None, TaskContinuationOptions.None, (TaskScheduler)null); }); + () => { Task.Factory.ContinueWhenAll(smallTaskWithResultArray, finishedArray => 10, CancellationToken.None, TaskContinuationOptions.None, (TaskScheduler)null); }); Assert.Throws( - () => { Task.Factory.ContinueWhenAll(smallFutureArray, finishedArray => 10, TaskContinuationOptions.NotOnFaulted); }); + () => { Task.Factory.ContinueWhenAll(smallTaskWithResultArray, finishedArray => 10, TaskContinuationOptions.NotOnFaulted); }); Assert.Throws( - () => { Task.Factory.ContinueWhenAll(smallFutureArray, (Func)null); }); + () => { Task.Factory.ContinueWhenAll(smallTaskWithResultArray, (Func)null); }); Assert.Throws( - () => { Task.Factory.ContinueWhenAll(smallFutureArray, (Func)null, CancellationToken.None); }); + () => { Task.Factory.ContinueWhenAll(smallTaskWithResultArray, (Func)null, CancellationToken.None); }); Assert.Throws( - () => { Task.Factory.ContinueWhenAll(smallFutureArray, (Func)null, TaskContinuationOptions.None); }); + () => { Task.Factory.ContinueWhenAll(smallTaskWithResultArray, (Func)null, TaskContinuationOptions.None); }); Assert.Throws( - () => { Task.Factory.ContinueWhenAll(smallFutureArray, (Func)null, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.Default); }); + () => { Task.Factory.ContinueWhenAll(smallTaskWithResultArray, (Func)null, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.Default); }); Assert.Throws( () => { Task.Factory.ContinueWhenAll((Task[])null, finishedArray => 10); }); - smallFutureArray[0] = null; + smallTaskWithResultArray[0] = null; - AssertExtensions.Throws("tasks", () => Task.Factory.ContinueWhenAll(smallFutureArray, finishedArray => 10)); + AssertExtensions.Throws("tasks", () => Task.Factory.ContinueWhenAll(smallTaskWithResultArray, finishedArray => 10)); AssertExtensions.Throws("tasks", () => Task.Factory.ContinueWhenAll(new Task[0], finishedArray => 10)); } } @@ -878,7 +878,7 @@ private static void CheckForCorrectCT(Task canceledTask, CancellationToken corre } } - private static void makeCWAllFutureArrays(int smallSize, int largeSize, out Task[] aSmall, out Task[] aLarge) + private static void makeCWAllTaskWithResultArrays(int smallSize, int largeSize, out Task[] aSmall, out Task[] aLarge) { aLarge = new Task[largeSize]; aSmall = new Task[smallSize]; diff --git a/src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/Task/TaskContinueWhenAnyTests.cs b/src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/Task/TaskContinueWhenAnyTests.cs index 6df5ba4c8b8fad..1cf816cbb616ae 100644 --- a/src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/Task/TaskContinueWhenAnyTests.cs +++ b/src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/Task/TaskContinueWhenAnyTests.cs @@ -21,10 +21,10 @@ public static void RunContinueWhenAnyTests() for (int i = 0; i < 2; i++) { - bool antecedentsAreFutures = (i == 0); + bool antecedentsHaveResult = (i == 0); for (int j = 0; j < 2; j++) { - bool continuationIsFuture = (j == 0); + bool continuationHasResult = (j == 0); for (int k = 0; k < 2; k++) { bool preCanceledToken = (k == 0); @@ -44,23 +44,23 @@ public static void RunContinueWhenAnyTests() for (int z = 0; z < 2; z++) { - bool useFutureFactory = (z == 0); + bool useResultTaskFactory = (z == 0); // This would be a nonsensical combination - if (useFutureFactory && !continuationIsFuture) + if (useResultTaskFactory && !continuationHasResult) continue; //Assert.Fail(string.Format(" - Test Task{5}.Factory.ContinueWhenAny(Task{0}[]({1} completed), {2}, ct({3}), {4}, ts.Default)", - // antecedentsAreFutures ? "" : "", + // antecedentsHaveResult ? "" : "", // preCompletedTask ? 1 : 0, - // continuationIsFuture ? "func" : "action", + // continuationHasResult ? "func" : "action", // preCanceledToken ? "signaled" : "unsignaled", // tco, - // useFutureFactory ? "" : "")); + // useResultTaskFactory ? "" : "")); TaskScheduler ts = TaskScheduler.Default; - if (antecedentsAreFutures) + if (antecedentsHaveResult) antecedents = new Task[3]; else antecedents = new Task[3]; @@ -73,7 +73,7 @@ public static void RunContinueWhenAnyTests() - if (antecedentsAreFutures) + if (antecedentsHaveResult) { antecedents[0] = new Task(() => { mre2.WaitOne(); return 0; }); antecedents[1] = new Task(() => { mre1.WaitOne(); return 1; }); @@ -93,11 +93,11 @@ public static void RunContinueWhenAnyTests() antecedents[1].Wait(); } - if (continuationIsFuture) + if (continuationHasResult) { - if (antecedentsAreFutures) + if (antecedentsHaveResult) { - if (useFutureFactory) + if (useResultTaskFactory) { continuation = Task.Factory.ContinueWhenAny((Task[])antecedents, t => { tcs.TrySetResult(t.Result); return 10; }, ct, tco, ts); } @@ -108,7 +108,7 @@ public static void RunContinueWhenAnyTests() } else // antecedents are tasks { - if (useFutureFactory) + if (useResultTaskFactory) { continuation = Task.Factory.ContinueWhenAny(antecedents, _ => 10, ct, tco, ts); } @@ -120,7 +120,7 @@ public static void RunContinueWhenAnyTests() } else // continuation is task { - if (antecedentsAreFutures) + if (antecedentsHaveResult) { continuation = Task.Factory.ContinueWhenAny((Task[])antecedents, t => tcs.TrySetResult(t.Result), ct, tco, ts); } @@ -153,7 +153,7 @@ public static void RunContinueWhenAnyTests() try { - if (continuationIsFuture) + if (continuationHasResult) result = ((Task)continuation).Result; else continuation.Wait(); @@ -185,7 +185,7 @@ public static void RunContinueWhenAnyTests() Assert.True(preCanceledToken || (tcs.Task.Result == 1), "RunContinueWhenAnyTests: > FAILED! Wrong task was recorded as completed."); - Assert.True((result == 10) || !continuationIsFuture || preCanceledToken, + Assert.True((result == 10) || !continuationHasResult || preCanceledToken, "RunContinueWhenAnyTests:> FAILED! continuation yielded wrong result"); Assert.Equal((continuation.CreationOptions & TaskCreationOptions.LongRunning) != 0, longRunning); @@ -204,24 +204,24 @@ public static void RunContinueWhenAnyTests() // call under these conditions. if (preCanceledToken && longRunning && preCompletedTask) { - TestContinueWhenAnyException(antecedents, useFutureFactory, continuationIsFuture); + TestContinueWhenAnyException(antecedents, useResultTaskFactory, continuationHasResult); } - } //end z-loop (useFutureFactory) + } //end z-loop (useResultTaskFactory) } // end y-loop (preCompletedTask) } // end x-loop (longRunning) } // end k-loop (preCanceledToken) - } // end j-loop (continuationIsFuture) - } // end i-loop (antecedentsAreFutures) + } // end j-loop (continuationHasResult) + } // end i-loop (antecedentsHaveResult) } - private static void TestContinueWhenAnyException(Task[] antecedents, bool FutureFactory, bool continuationIsFuture) + private static void TestContinueWhenAnyException(Task[] antecedents, bool ResultTaskFactory, bool continuationHasResult) { - bool antecedentsAreFutures = (antecedents as Task[]) != null; + bool antecedentsHaveResult = (antecedents as Task[]) != null; Debug.WriteLine(" * Test Exceptions in TaskFactory{0}.ContinueWhenAny(Task{1}[],Task{2})", - FutureFactory ? "" : "", - antecedentsAreFutures ? "" : "", - continuationIsFuture ? "" : ""); + ResultTaskFactory ? "" : "", + antecedentsHaveResult ? "" : "", + continuationHasResult ? "" : ""); CancellationTokenSource cts = new CancellationTokenSource(); CancellationToken ct = cts.Token; @@ -230,11 +230,11 @@ private static void TestContinueWhenAnyException(Task[] antecedents, bool Future Task t1 = Task.Factory.StartNew(() => { }); Task f1 = Task.Factory.StartNew(() => 10); Task[] dummyTasks = new Task[] { t1 }; - Task[] dummyFutures = new Task[] { f1 }; + Task[] dummyTasksWithResult = new Task[] { f1 }; - if (FutureFactory) //TaskFactory methods + if (ResultTaskFactory) //TaskFactory methods { - if (antecedentsAreFutures) + if (antecedentsHaveResult) { Assert.Throws( () => { Task.Factory.ContinueWhenAny((Task[])antecedents, t => 0, CancellationToken.None, TaskContinuationOptions.None, (TaskScheduler)null); }); @@ -245,8 +245,8 @@ private static void TestContinueWhenAnyException(Task[] antecedents, bool Future Assert.Throws( () => { Task.Factory.ContinueWhenAny(null, t => 0); }); - var cFuture = Task.Factory.ContinueWhenAny((Task[])antecedents, t => 0, ct); - CheckForCorrectCT(cFuture, ct); + var cTaskWithResult = Task.Factory.ContinueWhenAny((Task[])antecedents, t => 0, ct); + CheckForCorrectCT(cTaskWithResult, ct); antecedents[0] = null; Assert.Throws( @@ -259,16 +259,16 @@ private static void TestContinueWhenAnyException(Task[] antecedents, bool Future // Test for exception on null continuation function // Assert.Throws( - () => { Task.Factory.ContinueWhenAny(dummyFutures, (Func, int>)null); }); + () => { Task.Factory.ContinueWhenAny(dummyTasksWithResult, (Func, int>)null); }); Assert.Throws( - () => { Task.Factory.ContinueWhenAny(dummyFutures, (Func, int>)null, CancellationToken.None); }); + () => { Task.Factory.ContinueWhenAny(dummyTasksWithResult, (Func, int>)null, CancellationToken.None); }); Assert.Throws( - () => { Task.Factory.ContinueWhenAny(dummyFutures, (Func, int>)null, TaskContinuationOptions.None); }); + () => { Task.Factory.ContinueWhenAny(dummyTasksWithResult, (Func, int>)null, TaskContinuationOptions.None); }); Assert.Throws( - () => { Task.Factory.ContinueWhenAny(dummyFutures, (Func, int>)null, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.Default); }); + () => { Task.Factory.ContinueWhenAny(dummyTasksWithResult, (Func, int>)null, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.Default); }); } else //antecedents are tasks { @@ -316,9 +316,9 @@ private static void TestContinueWhenAnyException(Task[] antecedents, bool Future else //TaskFactory methods { //test exceptions - if (continuationIsFuture) + if (continuationHasResult) { - if (antecedentsAreFutures) + if (antecedentsHaveResult) { Assert.Throws( () => { Task.Factory.ContinueWhenAny((Task[])antecedents, t => 0, CancellationToken.None, TaskContinuationOptions.None, (TaskScheduler)null); }); @@ -343,16 +343,16 @@ private static void TestContinueWhenAnyException(Task[] antecedents, bool Future // Test for exception on null continuation function // Assert.Throws( - () => { Task.Factory.ContinueWhenAny(dummyFutures, (Func, int>)null); }); + () => { Task.Factory.ContinueWhenAny(dummyTasksWithResult, (Func, int>)null); }); Assert.Throws( - () => { Task.Factory.ContinueWhenAny(dummyFutures, (Func, int>)null, CancellationToken.None); }); + () => { Task.Factory.ContinueWhenAny(dummyTasksWithResult, (Func, int>)null, CancellationToken.None); }); Assert.Throws( - () => { Task.Factory.ContinueWhenAny(dummyFutures, (Func, int>)null, TaskContinuationOptions.None); }); + () => { Task.Factory.ContinueWhenAny(dummyTasksWithResult, (Func, int>)null, TaskContinuationOptions.None); }); Assert.Throws( - () => { Task.Factory.ContinueWhenAny(dummyFutures, (Func, int>)null, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.Default); }); + () => { Task.Factory.ContinueWhenAny(dummyTasksWithResult, (Func, int>)null, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.Default); }); } else // antecedents are tasks @@ -395,7 +395,7 @@ private static void TestContinueWhenAnyException(Task[] antecedents, bool Future else //Continuation is task { - if (antecedentsAreFutures) + if (antecedentsHaveResult) { Assert.Throws( () => { Task.Factory.ContinueWhenAny((Task[])antecedents, t => { }, CancellationToken.None, TaskContinuationOptions.None, (TaskScheduler)null); }); @@ -420,16 +420,16 @@ private static void TestContinueWhenAnyException(Task[] antecedents, bool Future // Test for exception on null continuation action // Assert.Throws( - () => { Task.Factory.ContinueWhenAny(dummyFutures, (Action>)null); }); + () => { Task.Factory.ContinueWhenAny(dummyTasksWithResult, (Action>)null); }); Assert.Throws( - () => { Task.Factory.ContinueWhenAny(dummyFutures, (Action>)null, CancellationToken.None); }); + () => { Task.Factory.ContinueWhenAny(dummyTasksWithResult, (Action>)null, CancellationToken.None); }); Assert.Throws( - () => { Task.Factory.ContinueWhenAny(dummyFutures, (Action>)null, TaskContinuationOptions.None); }); + () => { Task.Factory.ContinueWhenAny(dummyTasksWithResult, (Action>)null, TaskContinuationOptions.None); }); Assert.Throws( - () => { Task.Factory.ContinueWhenAny(dummyFutures, (Action>)null, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.Default); }); + () => { Task.Factory.ContinueWhenAny(dummyTasksWithResult, (Action>)null, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.Default); }); } else // antecedents are tasks { diff --git a/src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/Task/TaskContinueWithTests.cs b/src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/Task/TaskContinueWithTests.cs index 940d1164a80864..5378301afeb7c5 100644 --- a/src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/Task/TaskContinueWithTests.cs +++ b/src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/Task/TaskContinueWithTests.cs @@ -33,10 +33,10 @@ public static void RunContinueWithAsyncStateCheckTests() Task.WaitAll(c1, c2, c3, c4); - Assert.True(c1.AsyncState == null, "RunContinueWithAsyncStateCheckTests: task=>task continuation leaks state"); - Assert.True(c2.AsyncState == null, "RunContinueWithAsyncStateCheckTests: task=>future continuation leaks state"); - Assert.True(c3.AsyncState == null, "RunContinueWithAsyncStateCheckTests: future=>task continuation leaks state"); - Assert.True(c4.AsyncState == null, "RunContinueWithAsyncStateCheckTests: future=>future continuation leaks state"); + Assert.True(c1.AsyncState == null, "RunContinueWithAsyncStateCheckTests: Task=>Task continuation leaks state"); + Assert.True(c2.AsyncState == null, "RunContinueWithAsyncStateCheckTests: Task=>Task continuation leaks state"); + Assert.True(c3.AsyncState == null, "RunContinueWithAsyncStateCheckTests: Task=>Task continuation leaks state"); + Assert.True(c4.AsyncState == null, "RunContinueWithAsyncStateCheckTests: Task=>Task continuation leaks state"); } // Stresses on multiple continuations from a single antecedent @@ -374,7 +374,7 @@ public static void RunContinueWithAllParamsTestsNoState() for (int k = 0; k < 2; k++) { - bool antecedentIsFuture = (k == 0); + bool antecedentHasResult = (k == 0); Task antecedent = null; for (int z = 0; z < 2; z++) @@ -382,7 +382,7 @@ public static void RunContinueWithAllParamsTestsNoState() bool preCompletedTask = (z == 0); if (preCompletedTask) { - if (antecedentIsFuture) antecedent = Task.Factory.StartNew(() => 5); + if (antecedentHasResult) antecedent = Task.Factory.StartNew(() => 5); else antecedent = Task.Factory.StartNew(() => { }); antecedent.Wait(); } @@ -390,7 +390,7 @@ public static void RunContinueWithAllParamsTestsNoState() for (int x = 0; x < 2; x++) { - bool continuationIsFuture = (x == 0); + bool continuationHasResult = (x == 0); // // Test ContinueWith() overloads that take all parameters @@ -400,28 +400,28 @@ public static void RunContinueWithAllParamsTestsNoState() if (!preCompletedTask) { - if (antecedentIsFuture) antecedent = new Task(() => 5); + if (antecedentHasResult) antecedent = new Task(() => 5); else antecedent = new Task(() => { }); } - if (continuationIsFuture) + if (continuationHasResult) { - if (antecedentIsFuture) + if (antecedentHasResult) { - //Debug.WriteLine(" - Future = {2}Future.CW(func, ct({0}), tco({1}), TS.Default)", preCanceled ? "signaled" : "unsignaled", tco, preCompletedTask ? "C" : "U"); + //Debug.WriteLine(" - Task = {2}Task.CW(func, ct({0}), tco({1}), TS.Default)", preCanceled ? "signaled" : "unsignaled", tco, preCompletedTask ? "C" : "U"); continuation = ((Task)antecedent).ContinueWith(_ => 5, ct, tco, TaskScheduler.Default); } else { - //Debug.WriteLine(" - Future = {2}Task.CW(func, ct({0}), tco({1}), TS.Default)", preCanceled ? "signaled" : "unsignaled", tco, preCompletedTask ? "C" : "U"); + //Debug.WriteLine(" - Task = {2}Task.CW(func, ct({0}), tco({1}), TS.Default)", preCanceled ? "signaled" : "unsignaled", tco, preCompletedTask ? "C" : "U"); continuation = antecedent.ContinueWith(_ => 5, ct, tco, TaskScheduler.Default); } } else { - if (antecedentIsFuture) + if (antecedentHasResult) { - //Debug.WriteLine(" - Task = {2}Future.CW(action, ct({0}), tco({1}), TS.Default)", preCanceled ? "signaled" : "unsignaled", tco, preCompletedTask ? "C" : "U"); + //Debug.WriteLine(" - Task = {2}Task.CW(action, ct({0}), tco({1}), TS.Default)", preCanceled ? "signaled" : "unsignaled", tco, preCompletedTask ? "C" : "U"); continuation = ((Task)antecedent).ContinueWith(_ => { }, ct, tco, TaskScheduler.Default); } else @@ -440,7 +440,7 @@ public static void RunContinueWithAllParamsTestsNoState() try { continuation.Wait(); - if (continuationIsFuture) result = ((Task)continuation).Result; + if (continuationHasResult) result = ((Task)continuation).Result; } catch (Exception e) { @@ -455,8 +455,8 @@ public static void RunContinueWithAllParamsTestsNoState() "RunContinueWithAllParamsTestsNoState: Got Wait() exception w/o pre-cancellation"); Assert.True(continuation.CreationOptions == (TaskCreationOptions)tco, "RunContinueWithAllParamsTestsNoState: mis-matched CreationOptions"); - Assert.True((result == 5) || (!continuationIsFuture || preCanceled), - "RunContinueWithAllParamsTestsNoState: Expected valid result from non-canceled Future continuation"); + Assert.True((result == 5) || (!continuationHasResult || preCanceled), + "RunContinueWithAllParamsTestsNoState: Expected valid result from non-canceled Task continuation"); if (preCanceled) { Assert.True( @@ -474,29 +474,29 @@ public static void RunContinueWithAllParamsTestsNoState() Task continuation = null; if (!preCompletedTask) { - if (antecedentIsFuture) antecedent = new Task(() => 5); + if (antecedentHasResult) antecedent = new Task(() => 5); else antecedent = new Task(() => { }); } - if (continuationIsFuture) + if (continuationHasResult) { - if (antecedentIsFuture) + if (antecedentHasResult) { - //Debug.WriteLine(" - Future = {1}Future.CW(func, ct({0}))", preCanceled ? "signaled" : "unsignaled", preCompletedTask ? "C" : "U"); + //Debug.WriteLine(" - Task = {1}Task.CW(func, ct({0}))", preCanceled ? "signaled" : "unsignaled", preCompletedTask ? "C" : "U"); continuation = ((Task)antecedent).ContinueWith(_ => 5, ct); } else { - //Debug.WriteLine(" - Future = {1}Task.CW(func, ct({0}))", preCanceled ? "signaled" : "unsignaled", preCompletedTask ? "C" : "U"); + //Debug.WriteLine(" - Task = {1}Task.CW(func, ct({0}))", preCanceled ? "signaled" : "unsignaled", preCompletedTask ? "C" : "U"); continuation = antecedent.ContinueWith(_ => 5, ct); } } else { - if (antecedentIsFuture) + if (antecedentHasResult) { - //Debug.WriteLine(" - Task = {1}Future.CW(action, ct({0}))", preCanceled ? "signaled" : "unsignaled", preCompletedTask ? "C" : "U"); + //Debug.WriteLine(" - Task = {1}Task.CW(action, ct({0}))", preCanceled ? "signaled" : "unsignaled", preCompletedTask ? "C" : "U"); continuation = ((Task)antecedent).ContinueWith(_ => { }, ct); } else @@ -515,7 +515,7 @@ public static void RunContinueWithAllParamsTestsNoState() try { continuation.Wait(); - if (continuationIsFuture) result = ((Task)continuation).Result; + if (continuationHasResult) result = ((Task)continuation).Result; } catch (Exception e) { @@ -528,8 +528,8 @@ public static void RunContinueWithAllParamsTestsNoState() "RunContinueWithAllParamsTestsNoState overloads: Expected continuation to end as Canceled when pre-canceled"); Assert.True((ex == null) || preCanceled, "RunContinueWithAllParamsTestsNoState overloads: Got Wait() exception w/o pre-cancellation"); - Assert.True((result == 5) || (!continuationIsFuture || preCanceled), - "RunContinueWithAllParamsTestsNoState overloads: Expected valid result from non-canceled Future continuation"); + Assert.True((result == 5) || (!continuationHasResult || preCanceled), + "RunContinueWithAllParamsTestsNoState overloads: Expected valid result from non-canceled Task continuation"); if (preCanceled) { Assert.True( @@ -547,14 +547,14 @@ public static void RunContinueWithAllParamsTestsNoState() Task continuation = null; if (!preCompletedTask) { - if (antecedentIsFuture) antecedent = new Task(() => 5); + if (antecedentHasResult) antecedent = new Task(() => 5); else antecedent = new Task(() => { }); } - if (continuationIsFuture) + if (continuationHasResult) { - if (antecedentIsFuture) + if (antecedentHasResult) { continuation = ((Task)antecedent).ContinueWith(_ => 5, tco); } @@ -565,7 +565,7 @@ public static void RunContinueWithAllParamsTestsNoState() } else { - if (antecedentIsFuture) + if (antecedentHasResult) { continuation = ((Task)antecedent).ContinueWith(_ => { }, tco); } @@ -584,7 +584,7 @@ public static void RunContinueWithAllParamsTestsNoState() try { continuation.Wait(); - if (continuationIsFuture) result = ((Task)continuation).Result; + if (continuationHasResult) result = ((Task)continuation).Result; } catch (Exception e) { @@ -597,8 +597,8 @@ public static void RunContinueWithAllParamsTestsNoState() "RunContinueWithAllParamsTestsNoState: Got Wait() exception"); Assert.True(continuation.CreationOptions == (TaskCreationOptions)tco, "RunContinueWithAllParamsTestsNoState: Mis-matched CreationOptions"); - Assert.True((result == 5) || (!continuationIsFuture), - "RunContinueWithAllParamsTestsNoState: Expected valid result from Future continuation"); + Assert.True((result == 5) || (!continuationHasResult), + "RunContinueWithAllParamsTestsNoState: Expected valid result from Task continuation"); } // @@ -617,7 +617,7 @@ public static void RunContinueWithAllParamsTestsNoState() public static void RunUnwrapTests() { Task taskRoot = null; - Task futureRoot = null; + Task taskWithResultRoot = null; Task c1 = null; Task c2 = null; @@ -632,7 +632,7 @@ public static void RunUnwrapTests() // Basic functionality tests // taskRoot = new Task(delegate { }); - futureRoot = new Task(delegate { return 10; }); + taskWithResultRoot = new Task(delegate { return 10; }); ManualResetEvent mres = new ManualResetEvent(false); Action checkCompletionState = delegate (Task ctask, bool shouldBeCompleted, string scenario) { @@ -643,10 +643,10 @@ public static void RunUnwrapTests() }; c1 = taskRoot.ContinueWith((antecedent) => { return Task.Factory.StartNew(delegate { mres.WaitOne(); return 1; }); }).Unwrap(); - c2 = futureRoot.ContinueWith((antecedent) => { return Task.Factory.StartNew(delegate { mres.WaitOne(); return 2; }); }).Unwrap(); + c2 = taskWithResultRoot.ContinueWith((antecedent) => { return Task.Factory.StartNew(delegate { mres.WaitOne(); return 2; }); }).Unwrap(); var v3 = new Task>(delegate { return Task.Factory.StartNew(delegate { mres.WaitOne(); return 3; }); }); c3 = v3.Unwrap(); - c4 = Task.Factory.ContinueWhenAll(new Task[] { taskRoot, futureRoot }, completedTasks => + c4 = Task.Factory.ContinueWhenAll(new Task[] { taskRoot, taskWithResultRoot }, completedTasks => { int sum = 0; for (int i = 0; i < completedTasks.Length; i++) @@ -657,10 +657,10 @@ public static void RunUnwrapTests() return Task.Factory.StartNew(delegate { mres.WaitOne(); return sum; }); }).Unwrap(); c5 = taskRoot.ContinueWith((antecedent) => { return Task.Factory.StartNew(delegate { mres.WaitOne(); }); }).Unwrap(); - c6 = futureRoot.ContinueWith((antecedent) => { return Task.Factory.StartNew(delegate { mres.WaitOne(); }); }).Unwrap(); + c6 = taskWithResultRoot.ContinueWith((antecedent) => { return Task.Factory.StartNew(delegate { mres.WaitOne(); }); }).Unwrap(); var v7 = new Task(delegate { return Task.Factory.StartNew(delegate { mres.WaitOne(); }); }); c7 = v7.Unwrap(); - c8 = Task.Factory.ContinueWhenAny(new Task[] { taskRoot, futureRoot }, winner => + c8 = Task.Factory.ContinueWhenAny(new Task[] { taskRoot, taskWithResultRoot }, winner => { return Task.Factory.StartNew(delegate { mres.WaitOne(); }); }).Unwrap(); @@ -676,7 +676,7 @@ public static void RunUnwrapTests() checkCompletionState(c8, false, "ContinueWhenAny => Task, antecedent unstarted"); taskRoot.Start(); - futureRoot.Start(); + taskWithResultRoot.Start(); v3.Start(); v7.Start(); @@ -788,7 +788,7 @@ public static void RunUnwrapTests() public static void RunUnwrapTests_ExceptionTests() { Task taskRoot = null; - Task futureRoot = null; + Task taskWithResultRoot = null; Task c1 = null; Task c2 = null; @@ -804,17 +804,17 @@ public static void RunUnwrapTests_ExceptionTests() // Exception tests // taskRoot = new Task(delegate { }); - futureRoot = new Task(delegate { return 10; }); + taskWithResultRoot = new Task(delegate { return 10; }); c1 = taskRoot.ContinueWith(delegate (Task t) { doExc(); return Task.Factory.StartNew(delegate { return 1; }); }).Unwrap(); - c2 = futureRoot.ContinueWith(delegate (Task t) { doExc(); return Task.Factory.StartNew(delegate { return 2; }); }).Unwrap(); + c2 = taskWithResultRoot.ContinueWith(delegate (Task t) { doExc(); return Task.Factory.StartNew(delegate { return 2; }); }).Unwrap(); c3 = taskRoot.ContinueWith(delegate (Task t) { return Task.Factory.StartNew(delegate { doExc(); return 3; }); }).Unwrap(); - c4 = futureRoot.ContinueWith(delegate (Task t) { return Task.Factory.StartNew(delegate { doExc(); return 4; }); }).Unwrap(); + c4 = taskWithResultRoot.ContinueWith(delegate (Task t) { return Task.Factory.StartNew(delegate { doExc(); return 4; }); }).Unwrap(); c5 = taskRoot.ContinueWith(delegate (Task t) { doExc(); return Task.Factory.StartNew(delegate { }); }).Unwrap(); - c6 = futureRoot.ContinueWith(delegate (Task t) { doExc(); return Task.Factory.StartNew(delegate { }); }).Unwrap(); + c6 = taskWithResultRoot.ContinueWith(delegate (Task t) { doExc(); return Task.Factory.StartNew(delegate { }); }).Unwrap(); c7 = taskRoot.ContinueWith(delegate (Task t) { return Task.Factory.StartNew(delegate { doExc(); }); }).Unwrap(); - c8 = futureRoot.ContinueWith(delegate (Task t) { return Task.Factory.StartNew(delegate { doExc(); }); }).Unwrap(); + c8 = taskWithResultRoot.ContinueWith(delegate (Task t) { return Task.Factory.StartNew(delegate { doExc(); }); }).Unwrap(); taskRoot.Start(); - futureRoot.Start(); + taskWithResultRoot.Start(); Action excTest = delegate (Task ctask, string scenario) { @@ -846,11 +846,11 @@ public static void RunUnwrapTests_ExceptionTests() try { taskRoot.Wait(); - futureRoot.Wait(); + taskWithResultRoot.Wait(); } catch (Exception e) { - Assert.Fail(string.Format("RunUnwrapTests: > FAILED. Exception thrown while waiting for task/futureRoots used for exception testing: {0}", e)); + Assert.Fail(string.Format("RunUnwrapTests: > FAILED. Exception thrown while waiting for task/taskWithResultRoots used for exception testing: {0}", e)); } @@ -887,7 +887,7 @@ public static void RunUnwrapTests_ExceptionTests() public static void RunUnwrapTests_CancellationTests() { Task taskRoot = null; - Task futureRoot = null; + Task taskWithResultRoot = null; Task c1 = null; Task c2 = null; @@ -910,7 +910,7 @@ public static void RunUnwrapTests_CancellationTests() ManualResetEvent mres = new ManualResetEvent(false); taskRoot = new Task(delegate { }); - futureRoot = new Task(delegate { return 20; }); + taskWithResultRoot = new Task(delegate { return 20; }); Task container = Task.Factory.StartNew(delegate { c1 = taskRoot.ContinueWith(delegate (Task antecedent) @@ -919,7 +919,7 @@ public static void RunUnwrapTests_CancellationTests() return rval; }, ctsForC1.Token).Unwrap(); - c2 = futureRoot.ContinueWith(delegate (Task antecedent) + c2 = taskWithResultRoot.ContinueWith(delegate (Task antecedent) { Task rval = new Task(delegate { c2val = 1; return 10; }); return rval; @@ -931,7 +931,7 @@ public static void RunUnwrapTests_CancellationTests() return rval; }, ctsForC5.Token).Unwrap(); - c6 = futureRoot.ContinueWith(delegate (Task antecedent) + c6 = taskWithResultRoot.ContinueWith(delegate (Task antecedent) { Task rval = new Task(delegate { c6val = 1; }); return rval; @@ -1001,12 +1001,12 @@ public static void RunUnwrapTests_CancellationTests() container.Wait(); taskRoot.Start(); - futureRoot.Start(); + taskWithResultRoot.Start(); try { taskRoot.Wait(); - futureRoot.Wait(); + taskWithResultRoot.Wait(); } catch (Exception e) { diff --git a/src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/Task/TaskContinueWith_ContFuncAndActionTests.cs b/src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/Task/TaskContinueWith_ContFuncAndActionTests.cs index 37a7738b23154b..3a8f2168962b12 100644 --- a/src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/Task/TaskContinueWith_ContFuncAndActionTests.cs +++ b/src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/Task/TaskContinueWith_ContFuncAndActionTests.cs @@ -32,33 +32,33 @@ public static void RunContinueWithTestsNoState_NoneCompleted() } [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] - public static void RunContinueWithTaskFuture_NoneCompleted() + public static void RunContinueWithTaskToTaskWithResult_NoneCompleted() { - RunContinueWithTaskFuture(TaskContinuationOptions.None); - RunContinueWithTaskFuture(s_onlyOnRanToCompletion); + RunContinueWithTaskToTaskWithResult(TaskContinuationOptions.None); + RunContinueWithTaskToTaskWithResult(s_onlyOnRanToCompletion); - RunContinueWithTaskFuture(TaskContinuationOptions.ExecuteSynchronously); - RunContinueWithTaskFuture(s_onlyOnRanToCompletion | TaskContinuationOptions.ExecuteSynchronously); + RunContinueWithTaskToTaskWithResult(TaskContinuationOptions.ExecuteSynchronously); + RunContinueWithTaskToTaskWithResult(s_onlyOnRanToCompletion | TaskContinuationOptions.ExecuteSynchronously); } [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] - public static void RunContinueWithFutureTask_NoneCompleted() + public static void RunContinueWithTaskWithResultToTask_NoneCompleted() { - RunContinueWithFutureTask(TaskContinuationOptions.None); - RunContinueWithFutureTask(s_onlyOnRanToCompletion); + RunContinueWithTaskWithResultToTask(TaskContinuationOptions.None); + RunContinueWithTaskWithResultToTask(s_onlyOnRanToCompletion); - RunContinueWithFutureTask(TaskContinuationOptions.ExecuteSynchronously); - RunContinueWithFutureTask(s_onlyOnRanToCompletion | TaskContinuationOptions.ExecuteSynchronously); + RunContinueWithTaskWithResultToTask(TaskContinuationOptions.ExecuteSynchronously); + RunContinueWithTaskWithResultToTask(s_onlyOnRanToCompletion | TaskContinuationOptions.ExecuteSynchronously); } [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] - public static void RunContinueWithFutureFuture_NoneCompleted() + public static void RunContinueWithTaskWithResultToTaskWithResult_NoneCompleted() { - RunContinueWithFutureFuture(TaskContinuationOptions.None); - RunContinueWithFutureFuture(s_onlyOnRanToCompletion); + RunContinueWithTaskWithResultToTaskWithResult(TaskContinuationOptions.None); + RunContinueWithTaskWithResultToTaskWithResult(s_onlyOnRanToCompletion); - RunContinueWithFutureFuture(TaskContinuationOptions.ExecuteSynchronously); - RunContinueWithFutureFuture(s_onlyOnRanToCompletion | TaskContinuationOptions.ExecuteSynchronously); + RunContinueWithTaskWithResultToTaskWithResult(TaskContinuationOptions.ExecuteSynchronously); + RunContinueWithTaskWithResultToTaskWithResult(s_onlyOnRanToCompletion | TaskContinuationOptions.ExecuteSynchronously); } [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] @@ -72,33 +72,33 @@ public static void RunContinueWithTestsNoState_FaultedCanceled() } [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] - public static void RunContinueWithTaskFuture_FaultedCanceled() + public static void RunContinueWithTaskToTaskWithResult_FaultedCanceled() { - RunContinueWithTaskFuture(s_onlyOnCanceled); - RunContinueWithTaskFuture(s_onlyOnFaulted); + RunContinueWithTaskToTaskWithResult(s_onlyOnCanceled); + RunContinueWithTaskToTaskWithResult(s_onlyOnFaulted); - RunContinueWithTaskFuture(s_onlyOnCanceled | TaskContinuationOptions.ExecuteSynchronously); - RunContinueWithTaskFuture(s_onlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously); + RunContinueWithTaskToTaskWithResult(s_onlyOnCanceled | TaskContinuationOptions.ExecuteSynchronously); + RunContinueWithTaskToTaskWithResult(s_onlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously); } [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] - public static void RunContinueWithFutureTask_FaultedCanceled() + public static void RunContinueWithTaskWithResultToTask_FaultedCanceled() { - RunContinueWithFutureTask(s_onlyOnCanceled); - RunContinueWithFutureTask(s_onlyOnFaulted); + RunContinueWithTaskWithResultToTask(s_onlyOnCanceled); + RunContinueWithTaskWithResultToTask(s_onlyOnFaulted); - RunContinueWithFutureTask(s_onlyOnCanceled | TaskContinuationOptions.ExecuteSynchronously); - RunContinueWithFutureTask(s_onlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously); + RunContinueWithTaskWithResultToTask(s_onlyOnCanceled | TaskContinuationOptions.ExecuteSynchronously); + RunContinueWithTaskWithResultToTask(s_onlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously); } [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] - public static void RunContinueWithFutureFuture_FaultedCanceled() + public static void RunContinueWithTaskWithResultToTaskWithResult_FaultedCanceled() { - RunContinueWithFutureFuture(s_onlyOnCanceled); - RunContinueWithFutureFuture(s_onlyOnFaulted); + RunContinueWithTaskWithResultToTaskWithResult(s_onlyOnCanceled); + RunContinueWithTaskWithResultToTaskWithResult(s_onlyOnFaulted); - RunContinueWithFutureFuture(s_onlyOnCanceled | TaskContinuationOptions.ExecuteSynchronously); - RunContinueWithFutureFuture(s_onlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously); + RunContinueWithTaskWithResultToTaskWithResult(s_onlyOnCanceled | TaskContinuationOptions.ExecuteSynchronously); + RunContinueWithTaskWithResultToTaskWithResult(s_onlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously); } // Exception tests. @@ -113,33 +113,33 @@ public static void RunContinueWithTestsNoState_NoneCompleted_OnException() } [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] - public static void RunContinueWithTaskFuture_NoneCompleted_OnException() + public static void RunContinueWithTaskToTaskWithResult_NoneCompleted_OnException() { - RunContinueWithTaskFuture(TaskContinuationOptions.None, true); - RunContinueWithTaskFuture(s_onlyOnRanToCompletion, true); + RunContinueWithTaskToTaskWithResult(TaskContinuationOptions.None, true); + RunContinueWithTaskToTaskWithResult(s_onlyOnRanToCompletion, true); - RunContinueWithTaskFuture(TaskContinuationOptions.ExecuteSynchronously, true); - RunContinueWithTaskFuture(s_onlyOnRanToCompletion | TaskContinuationOptions.ExecuteSynchronously, true); + RunContinueWithTaskToTaskWithResult(TaskContinuationOptions.ExecuteSynchronously, true); + RunContinueWithTaskToTaskWithResult(s_onlyOnRanToCompletion | TaskContinuationOptions.ExecuteSynchronously, true); } [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] - public static void RunContinueWithFutureTask_NoneCompleted_OnException() + public static void RunContinueWithTaskWithResultToTask_NoneCompleted_OnException() { - RunContinueWithFutureTask(TaskContinuationOptions.None, true); - RunContinueWithFutureTask(s_onlyOnRanToCompletion, true); + RunContinueWithTaskWithResultToTask(TaskContinuationOptions.None, true); + RunContinueWithTaskWithResultToTask(s_onlyOnRanToCompletion, true); - RunContinueWithFutureTask(TaskContinuationOptions.ExecuteSynchronously, true); - RunContinueWithFutureTask(s_onlyOnRanToCompletion | TaskContinuationOptions.ExecuteSynchronously, true); + RunContinueWithTaskWithResultToTask(TaskContinuationOptions.ExecuteSynchronously, true); + RunContinueWithTaskWithResultToTask(s_onlyOnRanToCompletion | TaskContinuationOptions.ExecuteSynchronously, true); } [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] - public static void RunContinueWithFutureFuture_NoneCompleted_OnException() + public static void RunContinueWithTaskWithResultToTaskWithResult_NoneCompleted_OnException() { - RunContinueWithFutureFuture(TaskContinuationOptions.None, true); - RunContinueWithFutureFuture(s_onlyOnRanToCompletion, true); + RunContinueWithTaskWithResultToTaskWithResult(TaskContinuationOptions.None, true); + RunContinueWithTaskWithResultToTaskWithResult(s_onlyOnRanToCompletion, true); - RunContinueWithFutureFuture(TaskContinuationOptions.ExecuteSynchronously, true); - RunContinueWithFutureFuture(s_onlyOnRanToCompletion | TaskContinuationOptions.ExecuteSynchronously, true); + RunContinueWithTaskWithResultToTaskWithResult(TaskContinuationOptions.ExecuteSynchronously, true); + RunContinueWithTaskWithResultToTaskWithResult(s_onlyOnRanToCompletion | TaskContinuationOptions.ExecuteSynchronously, true); } [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] @@ -152,33 +152,33 @@ public static void RunContinueWithTestsNoState_FaultedCanceled_OnException() RunContinueWithTaskTask(s_onlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously, true); } [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] - public static void RunContinueWithTaskFuture_FaultedCanceled_OnException() + public static void RunContinueWithTaskToTaskWithResult_FaultedCanceled_OnException() { - RunContinueWithTaskFuture(s_onlyOnCanceled, true); - RunContinueWithTaskFuture(s_onlyOnFaulted, true); + RunContinueWithTaskToTaskWithResult(s_onlyOnCanceled, true); + RunContinueWithTaskToTaskWithResult(s_onlyOnFaulted, true); - RunContinueWithTaskFuture(s_onlyOnCanceled | TaskContinuationOptions.ExecuteSynchronously, true); - RunContinueWithTaskFuture(s_onlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously, true); + RunContinueWithTaskToTaskWithResult(s_onlyOnCanceled | TaskContinuationOptions.ExecuteSynchronously, true); + RunContinueWithTaskToTaskWithResult(s_onlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously, true); } [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] - public static void RunContinueWithFutureTask_FaultedCanceled_OnException() + public static void RunContinueWithTaskWithResultToTask_FaultedCanceled_OnException() { - RunContinueWithFutureTask(s_onlyOnCanceled, true); - RunContinueWithFutureTask(s_onlyOnFaulted, true); + RunContinueWithTaskWithResultToTask(s_onlyOnCanceled, true); + RunContinueWithTaskWithResultToTask(s_onlyOnFaulted, true); - RunContinueWithFutureTask(s_onlyOnCanceled | TaskContinuationOptions.ExecuteSynchronously, true); - RunContinueWithFutureTask(s_onlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously, true); + RunContinueWithTaskWithResultToTask(s_onlyOnCanceled | TaskContinuationOptions.ExecuteSynchronously, true); + RunContinueWithTaskWithResultToTask(s_onlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously, true); } [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] - public static void RunContinueWithFutureFuture_FaultedCanceled_OnException() + public static void RunContinueWithTaskWithResultToTaskWithResult_FaultedCanceled_OnException() { - RunContinueWithFutureFuture(s_onlyOnCanceled, true); - RunContinueWithFutureFuture(s_onlyOnFaulted, true); + RunContinueWithTaskWithResultToTaskWithResult(s_onlyOnCanceled, true); + RunContinueWithTaskWithResultToTaskWithResult(s_onlyOnFaulted, true); - RunContinueWithFutureFuture(s_onlyOnCanceled | TaskContinuationOptions.ExecuteSynchronously, true); - RunContinueWithFutureFuture(s_onlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously, true); + RunContinueWithTaskWithResultToTaskWithResult(s_onlyOnCanceled | TaskContinuationOptions.ExecuteSynchronously, true); + RunContinueWithTaskWithResultToTaskWithResult(s_onlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously, true); } #endregion @@ -216,7 +216,7 @@ private static void RunContinueWithTaskTask(TaskContinuationOptions options, boo } // Chains a Task continuation to a Task, with a Func. - private static void RunContinueWithTaskFuture(TaskContinuationOptions options, bool runNegativeCases = false) + private static void RunContinueWithTaskToTaskWithResult(TaskContinuationOptions options, bool runNegativeCases = false) { bool ran = false; if (runNegativeCases) @@ -246,7 +246,7 @@ private static void RunContinueWithTaskFuture(TaskContinuationOptions options, b } // Chains a Task continuation to a Task. - private static void RunContinueWithFutureTask(TaskContinuationOptions options, bool runNegativeCases = false) + private static void RunContinueWithTaskWithResultToTask(TaskContinuationOptions options, bool runNegativeCases = false) { bool ran = false; if (runNegativeCases) @@ -276,7 +276,7 @@ private static void RunContinueWithFutureTask(TaskContinuationOptions options, b } // Chains a Task continuation to a Task, with a Func, U>. - private static void RunContinueWithFutureFuture(TaskContinuationOptions options, bool runNegativeCases = false) + private static void RunContinueWithTaskWithResultToTaskWithResult(TaskContinuationOptions options, bool runNegativeCases = false) { bool ran = false; if (runNegativeCases) @@ -311,13 +311,13 @@ private static void RunContinueWithBase( Action initRan, Func continuationMaker, Func ranValue, - bool taskIsFuture) + bool taskHasResult) { Debug.WriteLine(" >> (1) ContinueWith after task finishes Successfully."); { bool expect = (options & TaskContinuationOptions.NotOnRanToCompletion) == 0; Task task; - if (taskIsFuture) task = Task.Factory.StartNew(() => ""); + if (taskHasResult) task = Task.Factory.StartNew(() => ""); else task = Task.Factory.StartNew(delegate { }); task.Wait(); @@ -338,7 +338,7 @@ private static void RunContinueWithBase( bool expect = (options & TaskContinuationOptions.NotOnRanToCompletion) == 0; ManualResetEvent mre = new ManualResetEvent(false); Task task; - if (taskIsFuture) task = Task.Factory.StartNew(() => { mre.WaitOne(); return ""; }); + if (taskHasResult) task = Task.Factory.StartNew(() => { mre.WaitOne(); return ""; }); else task = Task.Factory.StartNew(delegate { mre.WaitOne(); }); initRan(); @@ -364,13 +364,13 @@ private static void RunContinueWithBase_NegativeCases( Action initRan, Func continuationMaker, Func ranValue, - bool taskIsFuture) + bool taskHasResult) { Debug.WriteLine(" >> (3) ContinueWith after task finishes Exceptionally."); { bool expect = (options & TaskContinuationOptions.NotOnFaulted) == 0; Task task; - if (taskIsFuture) task = Task.Factory.StartNew(delegate { throw new Exception("Boom"); }); + if (taskHasResult) task = Task.Factory.StartNew(delegate { throw new Exception("Boom"); }); else task = Task.Factory.StartNew(delegate { throw new Exception("Boom"); }); try { task.Wait(); } catch (AggregateException) { /*swallow(ouch)*/ } @@ -392,7 +392,7 @@ private static void RunContinueWithBase_NegativeCases( bool expect = (options & TaskContinuationOptions.NotOnFaulted) == 0; ManualResetEvent mre = new ManualResetEvent(false); Task task; - if (taskIsFuture) task = Task.Factory.StartNew(delegate { mre.WaitOne(); throw new Exception("Boom"); }); + if (taskHasResult) task = Task.Factory.StartNew(delegate { mre.WaitOne(); throw new Exception("Boom"); }); else task = Task.Factory.StartNew(delegate { mre.WaitOne(); throw new Exception("Boom"); }); initRan(); @@ -419,7 +419,7 @@ private static void RunContinueWithBase_NegativeCases( CancellationTokenSource cts = new CancellationTokenSource(); Task task; ManualResetEvent cancellationMRE = new ManualResetEvent(false); - if (taskIsFuture) task = Task.Factory.StartNew(() => { cancellationMRE.WaitOne(); throw new OperationCanceledException(cts.Token); }, cts.Token); + if (taskHasResult) task = Task.Factory.StartNew(() => { cancellationMRE.WaitOne(); throw new OperationCanceledException(cts.Token); }, cts.Token); else task = Task.Factory.StartNew(delegate { cancellationMRE.WaitOne(); throw new OperationCanceledException(cts.Token); }, cts.Token); cts.Cancel(); cancellationMRE.Set(); @@ -446,7 +446,7 @@ private static void RunContinueWithBase_NegativeCases( CancellationToken ct = cts.Token; ManualResetEvent cancellationMRE = new ManualResetEvent(false); - if (taskIsFuture) + if (taskHasResult) task = Task.Factory.StartNew(() => { cancellationMRE.WaitOne(); throw new OperationCanceledException(ct); }, ct); else task = Task.Factory.StartNew(delegate { cancellationMRE.WaitOne(); throw new OperationCanceledException(ct); }, ct); diff --git a/src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/Task/TaskContinueWith_ContFuncAndActionWithArgsTests.cs b/src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/Task/TaskContinueWith_ContFuncAndActionWithArgsTests.cs index b24259d52c847b..a0aa3a13b45af7 100644 --- a/src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/Task/TaskContinueWith_ContFuncAndActionWithArgsTests.cs +++ b/src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/Task/TaskContinueWith_ContFuncAndActionWithArgsTests.cs @@ -32,33 +32,33 @@ public static void RunContinueWithTaskTask_State() } [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] - public static void RunContinueWithTaskFuture_State() + public static void RunContinueWithTaskToTaskWithResult_State() { - RunContinueWithTaskFuture_State_Helper(TaskContinuationOptions.None); - RunContinueWithTaskFuture_State_Helper(s_onlyOnRanToCompletion); + RunContinueWithTaskToTaskWithResult_State_Helper(TaskContinuationOptions.None); + RunContinueWithTaskToTaskWithResult_State_Helper(s_onlyOnRanToCompletion); - RunContinueWithTaskFuture_State_Helper(TaskContinuationOptions.ExecuteSynchronously); - RunContinueWithTaskFuture_State_Helper(s_onlyOnRanToCompletion | TaskContinuationOptions.ExecuteSynchronously); + RunContinueWithTaskToTaskWithResult_State_Helper(TaskContinuationOptions.ExecuteSynchronously); + RunContinueWithTaskToTaskWithResult_State_Helper(s_onlyOnRanToCompletion | TaskContinuationOptions.ExecuteSynchronously); } [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] - public static void RunContinueWithFutureTask_State() + public static void RunContinueWithTaskWithResultToTask_State() { - RunContinueWithFutureTask_State_Helper(TaskContinuationOptions.None); - RunContinueWithFutureTask_State_Helper(s_onlyOnRanToCompletion); + RunContinueWithTaskWithResultToTask_State_Helper(TaskContinuationOptions.None); + RunContinueWithTaskWithResultToTask_State_Helper(s_onlyOnRanToCompletion); - RunContinueWithFutureTask_State_Helper(TaskContinuationOptions.ExecuteSynchronously); - RunContinueWithFutureTask_State_Helper(s_onlyOnRanToCompletion | TaskContinuationOptions.ExecuteSynchronously); + RunContinueWithTaskWithResultToTask_State_Helper(TaskContinuationOptions.ExecuteSynchronously); + RunContinueWithTaskWithResultToTask_State_Helper(s_onlyOnRanToCompletion | TaskContinuationOptions.ExecuteSynchronously); } [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] - public static void RunContinueWithFutureFuture_State() + public static void RunContinueWithTaskWithResultToTaskWithResult_State() { - RunContinueWithFutureFuture_State_Helper(TaskContinuationOptions.None); - RunContinueWithFutureFuture_State_Helper(s_onlyOnRanToCompletion); + RunContinueWithTaskWithResultToTaskWithResult_State_Helper(TaskContinuationOptions.None); + RunContinueWithTaskWithResultToTaskWithResult_State_Helper(s_onlyOnRanToCompletion); - RunContinueWithFutureFuture_State_Helper(TaskContinuationOptions.ExecuteSynchronously); - RunContinueWithFutureFuture_State_Helper(s_onlyOnRanToCompletion | TaskContinuationOptions.ExecuteSynchronously); + RunContinueWithTaskWithResultToTaskWithResult_State_Helper(TaskContinuationOptions.ExecuteSynchronously); + RunContinueWithTaskWithResultToTaskWithResult_State_Helper(s_onlyOnRanToCompletion | TaskContinuationOptions.ExecuteSynchronously); } [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] @@ -72,33 +72,33 @@ public static void RunContinueWithTaskTask_State_FaultedCanceled() } [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] - public static void RunContinueWithTaskFuture_State_FaultedCanceled() + public static void RunContinueWithTaskToTaskWithResult_State_FaultedCanceled() { - RunContinueWithTaskFuture_State_Helper(s_onlyOnCanceled); - RunContinueWithTaskFuture_State_Helper(s_onlyOnFaulted); + RunContinueWithTaskToTaskWithResult_State_Helper(s_onlyOnCanceled); + RunContinueWithTaskToTaskWithResult_State_Helper(s_onlyOnFaulted); - RunContinueWithTaskFuture_State_Helper(s_onlyOnCanceled | TaskContinuationOptions.ExecuteSynchronously); - RunContinueWithTaskFuture_State_Helper(s_onlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously); + RunContinueWithTaskToTaskWithResult_State_Helper(s_onlyOnCanceled | TaskContinuationOptions.ExecuteSynchronously); + RunContinueWithTaskToTaskWithResult_State_Helper(s_onlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously); } [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] - public static void RunContinueWithFutureTask_State_FaultedCanceled() + public static void RunContinueWithTaskWithResultToTask_State_FaultedCanceled() { - RunContinueWithFutureTask_State_Helper(s_onlyOnCanceled); - RunContinueWithFutureTask_State_Helper(s_onlyOnFaulted); + RunContinueWithTaskWithResultToTask_State_Helper(s_onlyOnCanceled); + RunContinueWithTaskWithResultToTask_State_Helper(s_onlyOnFaulted); - RunContinueWithFutureTask_State_Helper(s_onlyOnCanceled | TaskContinuationOptions.ExecuteSynchronously); - RunContinueWithFutureTask_State_Helper(s_onlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously); + RunContinueWithTaskWithResultToTask_State_Helper(s_onlyOnCanceled | TaskContinuationOptions.ExecuteSynchronously); + RunContinueWithTaskWithResultToTask_State_Helper(s_onlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously); } [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] - public static void RunContinueWithFutureFuture_State_FaultedCanceled() + public static void RunContinueWithTaskWithResultToTaskWithResult_State_FaultedCanceled() { - RunContinueWithFutureFuture_State_Helper(s_onlyOnCanceled); - RunContinueWithFutureFuture_State_Helper(s_onlyOnFaulted); + RunContinueWithTaskWithResultToTaskWithResult_State_Helper(s_onlyOnCanceled); + RunContinueWithTaskWithResultToTaskWithResult_State_Helper(s_onlyOnFaulted); - RunContinueWithFutureFuture_State_Helper(s_onlyOnCanceled | TaskContinuationOptions.ExecuteSynchronously); - RunContinueWithFutureFuture_State_Helper(s_onlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously); + RunContinueWithTaskWithResultToTaskWithResult_State_Helper(s_onlyOnCanceled | TaskContinuationOptions.ExecuteSynchronously); + RunContinueWithTaskWithResultToTaskWithResult_State_Helper(s_onlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously); } [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] @@ -112,33 +112,33 @@ public static void RunContinueWithTaskTask_State_OnException() } [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] - public static void RunContinueWithTaskFuture_State_OnException() + public static void RunContinueWithTaskToTaskWithResult_State_OnException() { - RunContinueWithTaskFuture_State_Helper(TaskContinuationOptions.None, true); - RunContinueWithTaskFuture_State_Helper(s_onlyOnRanToCompletion, true); + RunContinueWithTaskToTaskWithResult_State_Helper(TaskContinuationOptions.None, true); + RunContinueWithTaskToTaskWithResult_State_Helper(s_onlyOnRanToCompletion, true); - RunContinueWithTaskFuture_State_Helper(TaskContinuationOptions.ExecuteSynchronously, true); - RunContinueWithTaskFuture_State_Helper(s_onlyOnRanToCompletion | TaskContinuationOptions.ExecuteSynchronously, true); + RunContinueWithTaskToTaskWithResult_State_Helper(TaskContinuationOptions.ExecuteSynchronously, true); + RunContinueWithTaskToTaskWithResult_State_Helper(s_onlyOnRanToCompletion | TaskContinuationOptions.ExecuteSynchronously, true); } [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] - public static void RunContinueWithFutureTask_State_OnException() + public static void RunContinueWithTaskWithResultToTask_State_OnException() { - RunContinueWithFutureTask_State_Helper(TaskContinuationOptions.None, true); - RunContinueWithFutureTask_State_Helper(s_onlyOnRanToCompletion, true); + RunContinueWithTaskWithResultToTask_State_Helper(TaskContinuationOptions.None, true); + RunContinueWithTaskWithResultToTask_State_Helper(s_onlyOnRanToCompletion, true); - RunContinueWithFutureTask_State_Helper(TaskContinuationOptions.ExecuteSynchronously, true); - RunContinueWithFutureTask_State_Helper(s_onlyOnRanToCompletion | TaskContinuationOptions.ExecuteSynchronously, true); + RunContinueWithTaskWithResultToTask_State_Helper(TaskContinuationOptions.ExecuteSynchronously, true); + RunContinueWithTaskWithResultToTask_State_Helper(s_onlyOnRanToCompletion | TaskContinuationOptions.ExecuteSynchronously, true); } [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] - public static void RunContinueWithFutureFuture_State_OnException() + public static void RunContinueWithTaskWithResultToTaskWithResult_State_OnException() { - RunContinueWithFutureFuture_State_Helper(TaskContinuationOptions.None, true); - RunContinueWithFutureFuture_State_Helper(s_onlyOnRanToCompletion, true); + RunContinueWithTaskWithResultToTaskWithResult_State_Helper(TaskContinuationOptions.None, true); + RunContinueWithTaskWithResultToTaskWithResult_State_Helper(s_onlyOnRanToCompletion, true); - RunContinueWithFutureFuture_State_Helper(TaskContinuationOptions.ExecuteSynchronously, true); - RunContinueWithFutureFuture_State_Helper(s_onlyOnRanToCompletion | TaskContinuationOptions.ExecuteSynchronously, true); + RunContinueWithTaskWithResultToTaskWithResult_State_Helper(TaskContinuationOptions.ExecuteSynchronously, true); + RunContinueWithTaskWithResultToTaskWithResult_State_Helper(s_onlyOnRanToCompletion | TaskContinuationOptions.ExecuteSynchronously, true); } [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] @@ -152,33 +152,33 @@ public static void RunContinueWithTaskTask_State_FaultedCanceled_OnException() } [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] - public static void RunContinueWithTaskFuture_State_FaultedCanceled_OnException() + public static void RunContinueWithTaskToTaskWithResult_State_FaultedCanceled_OnException() { - RunContinueWithTaskFuture_State_Helper(s_onlyOnCanceled, true); - RunContinueWithTaskFuture_State_Helper(s_onlyOnFaulted, true); + RunContinueWithTaskToTaskWithResult_State_Helper(s_onlyOnCanceled, true); + RunContinueWithTaskToTaskWithResult_State_Helper(s_onlyOnFaulted, true); - RunContinueWithTaskFuture_State_Helper(s_onlyOnCanceled | TaskContinuationOptions.ExecuteSynchronously, true); - RunContinueWithTaskFuture_State_Helper(s_onlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously, true); + RunContinueWithTaskToTaskWithResult_State_Helper(s_onlyOnCanceled | TaskContinuationOptions.ExecuteSynchronously, true); + RunContinueWithTaskToTaskWithResult_State_Helper(s_onlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously, true); } [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] - public static void RunContinueWithFutureTask_State_FaultedCanceled_OnException() + public static void RunContinueWithTaskWithResultToTask_State_FaultedCanceled_OnException() { - RunContinueWithFutureTask_State_Helper(s_onlyOnCanceled, true); - RunContinueWithFutureTask_State_Helper(s_onlyOnFaulted, true); + RunContinueWithTaskWithResultToTask_State_Helper(s_onlyOnCanceled, true); + RunContinueWithTaskWithResultToTask_State_Helper(s_onlyOnFaulted, true); - RunContinueWithFutureTask_State_Helper(s_onlyOnCanceled | TaskContinuationOptions.ExecuteSynchronously, true); - RunContinueWithFutureTask_State_Helper(s_onlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously, true); + RunContinueWithTaskWithResultToTask_State_Helper(s_onlyOnCanceled | TaskContinuationOptions.ExecuteSynchronously, true); + RunContinueWithTaskWithResultToTask_State_Helper(s_onlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously, true); } [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] - public static void RunContinueWithFutureFuture_State_FaultedCanceled_OnException() + public static void RunContinueWithTaskWithResultToTaskWithResult_State_FaultedCanceled_OnException() { - RunContinueWithFutureFuture_State_Helper(s_onlyOnCanceled, true); - RunContinueWithFutureFuture_State_Helper(s_onlyOnFaulted, true); + RunContinueWithTaskWithResultToTaskWithResult_State_Helper(s_onlyOnCanceled, true); + RunContinueWithTaskWithResultToTaskWithResult_State_Helper(s_onlyOnFaulted, true); - RunContinueWithFutureFuture_State_Helper(s_onlyOnCanceled | TaskContinuationOptions.ExecuteSynchronously, true); - RunContinueWithFutureFuture_State_Helper(s_onlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously, true); + RunContinueWithTaskWithResultToTaskWithResult_State_Helper(s_onlyOnCanceled | TaskContinuationOptions.ExecuteSynchronously, true); + RunContinueWithTaskWithResultToTaskWithResult_State_Helper(s_onlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously, true); } [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] @@ -446,11 +446,11 @@ private static void RunContinueWithTaskTask_State_Helper(TaskContinuationOptions } // Chains a Task continuation to a Task, with a Func. - private static void RunContinueWithTaskFuture_State_Helper(TaskContinuationOptions options, bool runNegativeCases = false) + private static void RunContinueWithTaskToTaskWithResult_State_Helper(TaskContinuationOptions options, bool runNegativeCases = false) { bool ran = false; - Debug.WriteLine("* RunContinueWithTaskFuture_StateA(Object, options={0})", options); + Debug.WriteLine("* RunContinueWithTaskToTaskWithResult_StateA(Object, options={0})", options); string stateParam = "test"; //used as a state parameter for the continuation if the useStateParam is true if (runNegativeCases) @@ -480,11 +480,11 @@ private static void RunContinueWithTaskFuture_State_Helper(TaskContinuationOptio } // Chains a Task continuation to a Task. - private static void RunContinueWithFutureTask_State_Helper(TaskContinuationOptions options, bool runNegativeCases = false) + private static void RunContinueWithTaskWithResultToTask_State_Helper(TaskContinuationOptions options, bool runNegativeCases = false) { bool ran = false; - Debug.WriteLine("* RunContinueWithFutureTask_State(Object, options={0})", options); + Debug.WriteLine("* RunContinueWithTaskWithResultToTask_State(Object, options={0})", options); string stateParam = "test"; //used as a state parameter for the continuation if the useStateParam is true if (runNegativeCases) @@ -514,11 +514,11 @@ private static void RunContinueWithFutureTask_State_Helper(TaskContinuationOptio } // Chains a Task continuation to a Task, with a Func, U>. - private static void RunContinueWithFutureFuture_State_Helper(TaskContinuationOptions options, bool runNegativeCases = false) + private static void RunContinueWithTaskWithResultToTaskWithResult_State_Helper(TaskContinuationOptions options, bool runNegativeCases = false) { bool ran = false; - Debug.WriteLine("* RunContinueWithFutureFuture_StateA(Object, options={0})", options); + Debug.WriteLine("* RunContinueWithTaskWithResultToTaskWithResult_StateA(Object, options={0})", options); string stateParam = "test"; //used as a state parameter for the continuation if the useStateParam is true if (runNegativeCases) { @@ -552,13 +552,13 @@ private static void RunContinueWithBase( Action initRan, Func continuationMaker, Func ranValue, - bool taskIsFuture) + bool taskHasResult) { Debug.WriteLine(" >> (1) ContinueWith after task finishes Successfully."); { bool expect = (options & TaskContinuationOptions.NotOnRanToCompletion) == 0; Task task; - if (taskIsFuture) task = Task.Factory.StartNew(() => ""); + if (taskHasResult) task = Task.Factory.StartNew(() => ""); else task = Task.Factory.StartNew(delegate { }); task.Wait(); @@ -579,7 +579,7 @@ private static void RunContinueWithBase( bool expect = (options & TaskContinuationOptions.NotOnRanToCompletion) == 0; ManualResetEvent mre = new ManualResetEvent(false); Task task; - if (taskIsFuture) task = Task.Factory.StartNew(() => { mre.WaitOne(); return ""; }); + if (taskHasResult) task = Task.Factory.StartNew(() => { mre.WaitOne(); return ""; }); else task = Task.Factory.StartNew(delegate { mre.WaitOne(); }); initRan(); @@ -605,13 +605,13 @@ private static void RunContinueWithBase_ExceptionCases( Action initRan, Func continuationMaker, Func ranValue, - bool taskIsFuture) + bool taskHasResult) { Debug.WriteLine(" >> (3) ContinueWith after task finishes Exceptionally."); { bool expect = (options & TaskContinuationOptions.NotOnFaulted) == 0; Task task; - if (taskIsFuture) task = Task.Factory.StartNew(delegate { throw new Exception("Boom"); }); + if (taskHasResult) task = Task.Factory.StartNew(delegate { throw new Exception("Boom"); }); else task = Task.Factory.StartNew(delegate { throw new Exception("Boom"); }); try { task.Wait(); } catch (AggregateException) { /*swallow(ouch)*/ } @@ -632,7 +632,7 @@ private static void RunContinueWithBase_ExceptionCases( bool expect = (options & TaskContinuationOptions.NotOnFaulted) == 0; ManualResetEvent mre = new ManualResetEvent(false); Task task; - if (taskIsFuture) task = Task.Factory.StartNew(delegate { mre.WaitOne(); throw new Exception("Boom"); }); + if (taskHasResult) task = Task.Factory.StartNew(delegate { mre.WaitOne(); throw new Exception("Boom"); }); else task = Task.Factory.StartNew(delegate { mre.WaitOne(); throw new Exception("Boom"); }); initRan(); @@ -658,7 +658,7 @@ private static void RunContinueWithBase_ExceptionCases( CancellationTokenSource cts = new CancellationTokenSource(); Task task; ManualResetEvent cancellationMRE = new ManualResetEvent(false); - if (taskIsFuture) task = Task.Factory.StartNew(() => { cancellationMRE.WaitOne(); throw new OperationCanceledException(cts.Token); }, cts.Token); + if (taskHasResult) task = Task.Factory.StartNew(() => { cancellationMRE.WaitOne(); throw new OperationCanceledException(cts.Token); }, cts.Token); else task = Task.Factory.StartNew(delegate { cancellationMRE.WaitOne(); throw new OperationCanceledException(cts.Token); }, cts.Token); cts.Cancel(); cancellationMRE.Set(); @@ -684,7 +684,7 @@ private static void RunContinueWithBase_ExceptionCases( CancellationToken ct = cts.Token; ManualResetEvent cancellationMRE = new ManualResetEvent(false); - if (taskIsFuture) + if (taskHasResult) task = Task.Factory.StartNew(() => { cancellationMRE.WaitOne(); throw new OperationCanceledException(ct); }, ct); else task = Task.Factory.StartNew(delegate { cancellationMRE.WaitOne(); throw new OperationCanceledException(ct); }, ct); diff --git a/src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/Task/TaskCreateTest.cs b/src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/Task/TaskCreateTest.cs index 1b18aa70827f7e..0963604a92da9e 100644 --- a/src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/Task/TaskCreateTest.cs +++ b/src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/Task/TaskCreateTest.cs @@ -3,7 +3,7 @@ // =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ // -// Test class using UnitTestDriver that ensures all the public ctor of Task, Future and +// Test class using UnitTestDriver that ensures all the public ctor of Task, Task and // promise are properly working // // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- @@ -23,7 +23,7 @@ public sealed class TaskCreateTests [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] public static void TaskCreateTest0() { - TestParameters parameters = new TestParameters(TaskType.FutureT) + TestParameters parameters = new TestParameters(TaskType.TaskWithResultT) { HasCancellationToken = true, HasActionState = false, @@ -38,7 +38,7 @@ public static void TaskCreateTest0() [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] public static void TaskCreateTest1() { - TestParameters parameters = new TestParameters(TaskType.FutureT) + TestParameters parameters = new TestParameters(TaskType.TaskWithResultT) { HasCancellationToken = false, HasActionState = false, @@ -53,7 +53,7 @@ public static void TaskCreateTest1() [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] public static void TaskCreateTest2() { - TestParameters parameters = new TestParameters(TaskType.FutureT) + TestParameters parameters = new TestParameters(TaskType.TaskWithResultT) { HasCancellationToken = true, HasActionState = false, @@ -68,7 +68,7 @@ public static void TaskCreateTest2() [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] public static void TaskCreateTest3() { - TestParameters parameters = new TestParameters(TaskType.FutureT) + TestParameters parameters = new TestParameters(TaskType.TaskWithResultT) { HasCancellationToken = true, HasActionState = true, @@ -83,7 +83,7 @@ public static void TaskCreateTest3() [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] public static void TaskCreateTest4() { - TestParameters parameters = new TestParameters(TaskType.FutureT) + TestParameters parameters = new TestParameters(TaskType.TaskWithResultT) { HasCancellationToken = false, HasActionState = true, @@ -97,7 +97,7 @@ public static void TaskCreateTest4() [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] public static void TaskCreateTest5() { - TestParameters parameters = new TestParameters(TaskType.FutureT) + TestParameters parameters = new TestParameters(TaskType.TaskWithResultT) { HasCancellationToken = true, HasActionState = false, @@ -111,7 +111,7 @@ public static void TaskCreateTest5() [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] public static void TaskCreateTest6() { - TestParameters parameters = new TestParameters(TaskType.FutureT) + TestParameters parameters = new TestParameters(TaskType.TaskWithResultT) { HasCancellationToken = true, HasActionState = false, @@ -125,7 +125,7 @@ public static void TaskCreateTest6() [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] public static void TaskCreateTest7() { - TestParameters parameters = new TestParameters(TaskType.FutureT) + TestParameters parameters = new TestParameters(TaskType.TaskWithResultT) { HasCancellationToken = true, HasActionState = false, @@ -140,7 +140,7 @@ public static void TaskCreateTest7() [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] public static void TaskCreateTest8() { - TestParameters parameters = new TestParameters(TaskType.FutureT) + TestParameters parameters = new TestParameters(TaskType.TaskWithResultT) { HasCancellationToken = true, HasActionState = false, @@ -155,7 +155,7 @@ public static void TaskCreateTest8() [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] public static void TaskCreateTest9() { - TestParameters parameters = new TestParameters(TaskType.FutureT) + TestParameters parameters = new TestParameters(TaskType.TaskWithResultT) { HasCancellationToken = false, HasActionState = false, @@ -170,7 +170,7 @@ public static void TaskCreateTest9() [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] public static void TaskCreateTest10() { - TestParameters parameters = new TestParameters(TaskType.FutureT) + TestParameters parameters = new TestParameters(TaskType.TaskWithResultT) { HasCancellationToken = true, HasActionState = false, @@ -185,7 +185,7 @@ public static void TaskCreateTest10() [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] public static void TaskCreateTest11() { - TestParameters parameters = new TestParameters(TaskType.FutureT) + TestParameters parameters = new TestParameters(TaskType.TaskWithResultT) { HasCancellationToken = true, HasActionState = true, @@ -200,7 +200,7 @@ public static void TaskCreateTest11() [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] public static void TaskCreateTest12() { - TestParameters parameters = new TestParameters(TaskType.FutureT) + TestParameters parameters = new TestParameters(TaskType.TaskWithResultT) { HasCancellationToken = false, HasActionState = true, @@ -215,7 +215,7 @@ public static void TaskCreateTest12() [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] public static void TaskCreateTest13() { - TestParameters parameters = new TestParameters(TaskType.FutureT) + TestParameters parameters = new TestParameters(TaskType.TaskWithResultT) { HasCancellationToken = true, HasActionState = true, @@ -230,7 +230,7 @@ public static void TaskCreateTest13() [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] public static void TaskCreateTest14() { - TestParameters parameters = new TestParameters(TaskType.FutureT) + TestParameters parameters = new TestParameters(TaskType.TaskWithResultT) { HasCancellationToken = true, HasActionState = false, @@ -245,7 +245,7 @@ public static void TaskCreateTest14() [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] public static void TaskCreateTest15() { - TestParameters parameters = new TestParameters(TaskType.FutureT) + TestParameters parameters = new TestParameters(TaskType.TaskWithResultT) { HasCancellationToken = false, HasActionState = false, @@ -260,7 +260,7 @@ public static void TaskCreateTest15() [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] public static void TaskCreateTest16() { - TestParameters parameters = new TestParameters(TaskType.FutureT) + TestParameters parameters = new TestParameters(TaskType.TaskWithResultT) { HasCancellationToken = true, HasActionState = false, @@ -275,7 +275,7 @@ public static void TaskCreateTest16() [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] public static void TaskCreateTest17() { - TestParameters parameters = new TestParameters(TaskType.FutureT) + TestParameters parameters = new TestParameters(TaskType.TaskWithResultT) { HasCancellationToken = true, HasActionState = true, @@ -290,7 +290,7 @@ public static void TaskCreateTest17() [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] public static void TaskCreateTest18() { - TestParameters parameters = new TestParameters(TaskType.FutureT) + TestParameters parameters = new TestParameters(TaskType.TaskWithResultT) { HasCancellationToken = false, HasActionState = true, @@ -305,7 +305,7 @@ public static void TaskCreateTest18() [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] public static void TaskCreateTest19() { - TestParameters parameters = new TestParameters(TaskType.FutureT) + TestParameters parameters = new TestParameters(TaskType.TaskWithResultT) { HasCancellationToken = true, HasActionState = true, @@ -320,7 +320,7 @@ public static void TaskCreateTest19() [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] public static void TaskCreateTest20() { - TestParameters parameters = new TestParameters(TaskType.FutureT) + TestParameters parameters = new TestParameters(TaskType.TaskWithResultT) { HasCancellationToken = true, HasActionState = true, @@ -334,7 +334,7 @@ public static void TaskCreateTest20() [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] public static void TaskCreateTest21() { - TestParameters parameters = new TestParameters(TaskType.Future) + TestParameters parameters = new TestParameters(TaskType.TaskWithResult) { HasCancellationToken = true, HasActionState = false, @@ -348,7 +348,7 @@ public static void TaskCreateTest21() [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] public static void TaskCreateTest22() { - TestParameters parameters = new TestParameters(TaskType.Future) + TestParameters parameters = new TestParameters(TaskType.TaskWithResult) { HasCancellationToken = true, HasActionState = false, @@ -362,7 +362,7 @@ public static void TaskCreateTest22() [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] public static void TaskCreateTest23() { - TestParameters parameters = new TestParameters(TaskType.Future) + TestParameters parameters = new TestParameters(TaskType.TaskWithResult) { HasCancellationToken = true, HasActionState = false, @@ -377,7 +377,7 @@ public static void TaskCreateTest23() [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] public static void TaskCreateTest24() { - TestParameters parameters = new TestParameters(TaskType.Future) + TestParameters parameters = new TestParameters(TaskType.TaskWithResult) { HasCancellationToken = true, HasActionState = false, @@ -392,7 +392,7 @@ public static void TaskCreateTest24() [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] public static void TaskCreateTest25() { - TestParameters parameters = new TestParameters(TaskType.Future) + TestParameters parameters = new TestParameters(TaskType.TaskWithResult) { HasCancellationToken = false, HasActionState = false, @@ -407,7 +407,7 @@ public static void TaskCreateTest25() [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] public static void TaskCreateTest26() { - TestParameters parameters = new TestParameters(TaskType.Future) + TestParameters parameters = new TestParameters(TaskType.TaskWithResult) { HasCancellationToken = true, HasActionState = false, @@ -422,7 +422,7 @@ public static void TaskCreateTest26() [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] public static void TaskCreateTest27() { - TestParameters parameters = new TestParameters(TaskType.Future) + TestParameters parameters = new TestParameters(TaskType.TaskWithResult) { HasCancellationToken = true, HasActionState = true, @@ -437,7 +437,7 @@ public static void TaskCreateTest27() [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] public static void TaskCreateTest28() { - TestParameters parameters = new TestParameters(TaskType.Future) + TestParameters parameters = new TestParameters(TaskType.TaskWithResult) { HasCancellationToken = false, HasActionState = true, @@ -452,7 +452,7 @@ public static void TaskCreateTest28() [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] public static void TaskCreateTest29() { - TestParameters parameters = new TestParameters(TaskType.Future) + TestParameters parameters = new TestParameters(TaskType.TaskWithResult) { HasCancellationToken = true, HasActionState = true, @@ -856,8 +856,8 @@ internal TestParameters(TaskType taskType) } /// - /// Class that verifies that all the public constructors of Task, future, promise and futureT are working correctly - /// The test creates the test object (Task, Future, promise) using various ctor and ensures that they were + /// Class that verifies that all the public constructors of Task, Task{TResult}, promise, and Task{TResult} are working correctly. + /// The test creates the test object (Task, Task{TResult}, promise) using various ctor and ensures that they were /// created and can be started. All the negative cases (exceptional cases are also covered in this test set). /// internal sealed class TaskCreateTest @@ -918,12 +918,12 @@ public TaskCreateTest(TestParameters parameters) #region Test Methods (These are the ones that are actually invoked) /// - /// Test that creates a Task, Future and Promise using various Ctor and ensures that the task was created successfully + /// Test that creates a Task, Task, and Promise using various Ctor and ensures that the task was created successfully /// /// indicates whether test passed or failed (invoking ctor was success or not) internal void CreateTask() { - //Using the parameters specified in the XML input file create a Task, Future or promise + //Using the parameters specified in the XML input file create a Task, Task, or Promise _task = CreateTaskHelper(); // Checks whether the task was created, initialized with specified action @@ -981,11 +981,11 @@ internal void StartNewTask() case TaskType.Task: _task = Task.Factory.StartNew(Work, cts.Token, TaskCreationOptions.None, TaskScheduler.Default); break; - case TaskType.FutureT: - _task = Task.Factory.StartNew(FutureWork, cts.Token, TaskCreationOptions.None, TaskScheduler.Default); + case TaskType.TaskWithResultT: + _task = Task.Factory.StartNew(TaskWithResultWork, cts.Token, TaskCreationOptions.None, TaskScheduler.Default); break; - case TaskType.Future: - _task = Task.Factory.StartNew(FutureWork, cts.Token, TaskCreationOptions.None, TaskScheduler.Default); + case TaskType.TaskWithResult: + _task = Task.Factory.StartNew(TaskWithResultWork, cts.Token, TaskCreationOptions.None, TaskScheduler.Default); break; default: throw new NotSupportedException("DOes not support this type: " + _taskType); @@ -998,11 +998,11 @@ internal void StartNewTask() case TaskType.Task: _task = Task.Factory.StartNew(Work, TaskCreationOptions.None); break; - case TaskType.FutureT: - _task = Task.Factory.StartNew(FutureWork, TaskCreationOptions.None); + case TaskType.TaskWithResultT: + _task = Task.Factory.StartNew(TaskWithResultWork, TaskCreationOptions.None); break; - case TaskType.Future: - _task = Task.Factory.StartNew(FutureWork, TaskCreationOptions.None); + case TaskType.TaskWithResult: + _task = Task.Factory.StartNew(TaskWithResultWork, TaskCreationOptions.None); break; default: throw new NotSupportedException("DOes not support this type: " + _taskType); @@ -1015,11 +1015,11 @@ internal void StartNewTask() case TaskType.Task: _task = Task.Factory.StartNew(Work, cts.Token); break; - case TaskType.FutureT: - _task = (Task)Task.Factory.StartNew(FutureWork, cts.Token); + case TaskType.TaskWithResultT: + _task = (Task)Task.Factory.StartNew(TaskWithResultWork, cts.Token); break; - case TaskType.Future: - _task = Task.Factory.StartNew(FutureWork, cts.Token); + case TaskType.TaskWithResult: + _task = Task.Factory.StartNew(TaskWithResultWork, cts.Token); break; default: throw new NotSupportedException("DOes not support this type: " + _taskType); @@ -1032,11 +1032,11 @@ internal void StartNewTask() case TaskType.Task: _task = Task.Factory.StartNew(Work); break; - case TaskType.FutureT: - _task = (Task)Task.Factory.StartNew(FutureWork); + case TaskType.TaskWithResultT: + _task = (Task)Task.Factory.StartNew(TaskWithResultWork); break; - case TaskType.Future: - _task = Task.Factory.StartNew(FutureWork); + case TaskType.TaskWithResult: + _task = Task.Factory.StartNew(TaskWithResultWork); break; default: throw new NotSupportedException("DOes not support this type: " + _taskType); @@ -1052,11 +1052,11 @@ internal void StartNewTask() case TaskType.Task: _task = Task.Factory.StartNew(WorkWithState, ZETA_SEED, cts.Token, TaskCreationOptions.None, TaskScheduler.Default); break; - case TaskType.FutureT: - _task = Task.Factory.StartNew(FutureWorkWithState, ZETA_SEED, cts.Token, TaskCreationOptions.None, TaskScheduler.Default); + case TaskType.TaskWithResultT: + _task = Task.Factory.StartNew(TaskWithResultWorkWithState, ZETA_SEED, cts.Token, TaskCreationOptions.None, TaskScheduler.Default); break; - case TaskType.Future: - _task = Task.Factory.StartNew(FutureWorkWithState, ZETA_SEED, cts.Token, TaskCreationOptions.None, TaskScheduler.Default); + case TaskType.TaskWithResult: + _task = Task.Factory.StartNew(TaskWithResultWorkWithState, ZETA_SEED, cts.Token, TaskCreationOptions.None, TaskScheduler.Default); break; default: throw new NotSupportedException("DOes not support this type: " + _taskType); @@ -1069,11 +1069,11 @@ internal void StartNewTask() case TaskType.Task: _task = Task.Factory.StartNew(WorkWithState, ZETA_SEED, TaskCreationOptions.None); break; - case TaskType.FutureT: - _task = Task.Factory.StartNew(FutureWorkWithState, ZETA_SEED, TaskCreationOptions.None); + case TaskType.TaskWithResultT: + _task = Task.Factory.StartNew(TaskWithResultWorkWithState, ZETA_SEED, TaskCreationOptions.None); break; - case TaskType.Future: - _task = Task.Factory.StartNew(FutureWorkWithState, ZETA_SEED, TaskCreationOptions.None); + case TaskType.TaskWithResult: + _task = Task.Factory.StartNew(TaskWithResultWorkWithState, ZETA_SEED, TaskCreationOptions.None); break; default: throw new NotSupportedException("DOes not support this type: " + _taskType); @@ -1086,11 +1086,11 @@ internal void StartNewTask() case TaskType.Task: _task = Task.Factory.StartNew(Work, cts.Token); break; - case TaskType.FutureT: - _task = Task.Factory.StartNew(FutureWorkWithState, ZETA_SEED, cts.Token); + case TaskType.TaskWithResultT: + _task = Task.Factory.StartNew(TaskWithResultWorkWithState, ZETA_SEED, cts.Token); break; - case TaskType.Future: - _task = Task.Factory.StartNew(FutureWorkWithState, ZETA_SEED, cts.Token); + case TaskType.TaskWithResult: + _task = Task.Factory.StartNew(TaskWithResultWorkWithState, ZETA_SEED, cts.Token); break; default: throw new NotSupportedException("DOes not support this type: " + _taskType); @@ -1103,11 +1103,11 @@ internal void StartNewTask() case TaskType.Task: _task = Task.Factory.StartNew(WorkWithState, ZETA_SEED); break; - case TaskType.FutureT: - _task = Task.Factory.StartNew(FutureWorkWithState, ZETA_SEED); + case TaskType.TaskWithResultT: + _task = Task.Factory.StartNew(TaskWithResultWorkWithState, ZETA_SEED); break; - case TaskType.Future: - _task = Task.Factory.StartNew(FutureWorkWithState, ZETA_SEED); + case TaskType.TaskWithResult: + _task = Task.Factory.StartNew(TaskWithResultWorkWithState, ZETA_SEED); break; default: throw new NotSupportedException("DOes not support this type: " + _taskType); @@ -1134,13 +1134,13 @@ internal void ExceptionTests() // // For Constructor // - if (_taskType != TaskType.Future) + if (_taskType != TaskType.TaskWithResult) { try { if (_taskType == TaskType.Task) _task = new Task(null); - else if (_taskType == TaskType.FutureT) + else if (_taskType == TaskType.TaskWithResultT) _task = new Task(null); Assert.Fail(string.Format("Able to pass null Action/Func to Constructor of {0}, when expecting exception", _taskType)); @@ -1160,9 +1160,9 @@ internal void ExceptionTests() if (_taskType == TaskType.Task) _task = Task.Factory.StartNew(o); - else if (_taskType == TaskType.FutureT) + else if (_taskType == TaskType.TaskWithResultT) _task = Task.Factory.StartNew(o2); - else if (_taskType == TaskType.Future) + else if (_taskType == TaskType.TaskWithResult) _task = Task.Factory.StartNew(o2); Assert.Fail(string.Format("Able to pass null Action/Func to StartNew() of {0}, when expecting exception", _taskType)); @@ -1183,14 +1183,14 @@ internal void ExceptionTests() // // For Constructor // - if (_taskType != TaskType.Future) + if (_taskType != TaskType.TaskWithResult) { try { if (_taskType == TaskType.Task) _task = new Task(Work, (TaskCreationOptions)invalidOption); - else if (_taskType == TaskType.FutureT) - _task = new Task(FutureWork, (TaskCreationOptions)invalidOption); + else if (_taskType == TaskType.TaskWithResultT) + _task = new Task(TaskWithResultWork, (TaskCreationOptions)invalidOption); Assert.Fail(string.Format("Able to pass invalid TaskCreationOptions to Constructor of {0}, when expecting exception", _taskType)); } @@ -1206,10 +1206,10 @@ internal void ExceptionTests() { if (_taskType == TaskType.Task) _task = Task.Factory.StartNew(Work, (TaskCreationOptions)invalidOption); - else if (_taskType == TaskType.FutureT) - _task = Task.Factory.StartNew(FutureWork, (TaskCreationOptions)invalidOption); - else if (_taskType == TaskType.Future) - _task = Task.Factory.StartNew(FutureWork, (TaskCreationOptions)invalidOption); + else if (_taskType == TaskType.TaskWithResultT) + _task = Task.Factory.StartNew(TaskWithResultWork, (TaskCreationOptions)invalidOption); + else if (_taskType == TaskType.TaskWithResult) + _task = Task.Factory.StartNew(TaskWithResultWork, (TaskCreationOptions)invalidOption); Assert.Fail(string.Format("Able to pass invalid TaskCreationOptions to StartNew() of {0}, when expecting exception", _taskType)); } @@ -1284,7 +1284,7 @@ private void TMExceptionTestHelper(TaskScheduler tm, string tmInvalidMessage) // // For Start() // - if (_taskType != TaskType.Future) + if (_taskType != TaskType.TaskWithResult) { try { @@ -1318,10 +1318,10 @@ private void TMExceptionTestHelper(TaskScheduler tm, string tmInvalidMessage) if (_taskType == TaskType.Task) _task = Task.Factory.StartNew(Work, token, TaskCreationOptions.None, tm); - else if (_taskType == TaskType.FutureT) - _task = Task.Factory.StartNew(FutureWork, token, TaskCreationOptions.None, tm); - else if (_taskType == TaskType.Future) - _task = Task.Factory.StartNew(FutureWork, token, TaskCreationOptions.None, tm); + else if (_taskType == TaskType.TaskWithResultT) + _task = Task.Factory.StartNew(TaskWithResultWork, token, TaskCreationOptions.None, tm); + else if (_taskType == TaskType.TaskWithResult) + _task = Task.Factory.StartNew(TaskWithResultWork, token, TaskCreationOptions.None, tm); Assert.Fail(string.Format("Able to pass {0} TaskManager to StartNew() on {1}, when expecting exception", tmInvalidMessage, _taskType)); } @@ -1343,7 +1343,7 @@ private void TMExceptionTestHelper(TaskScheduler tm, string tmInvalidMessage) } /// - /// Helper function that creates Task/Future based on test parameters + /// Helper function that creates Task/Task based on test parameters /// /// private Task CreateTaskHelper() @@ -1377,8 +1377,8 @@ private Task CreateTaskHelper() case TaskType.Task: newTask = new Task(Work, token, TaskCreationOptions.None); break; - case TaskType.FutureT: - newTask = new Task(FutureWork, token, TaskCreationOptions.None); + case TaskType.TaskWithResultT: + newTask = new Task(TaskWithResultWork, token, TaskCreationOptions.None); break; default: throw new ArgumentException("Cannot create an instance of static type: " + _taskType); @@ -1391,8 +1391,8 @@ private Task CreateTaskHelper() case TaskType.Task: newTask = new Task(Work, TaskCreationOptions.None); break; - case TaskType.FutureT: - newTask = new Task(FutureWork, TaskCreationOptions.None); + case TaskType.TaskWithResultT: + newTask = new Task(TaskWithResultWork, TaskCreationOptions.None); break; default: throw new ArgumentException("Cannot create an instance of static type: " + _taskType); @@ -1407,8 +1407,8 @@ private Task CreateTaskHelper() case TaskType.Task: newTask = new Task(Work, token); break; - case TaskType.FutureT: - newTask = new Task(FutureWork, token); + case TaskType.TaskWithResultT: + newTask = new Task(TaskWithResultWork, token); break; default: throw new ArgumentException("Cannot create an instance of static type: " + _taskType); @@ -1421,8 +1421,8 @@ private Task CreateTaskHelper() case TaskType.Task: newTask = new Task(Work); break; - case TaskType.FutureT: - newTask = new Task(FutureWork); + case TaskType.TaskWithResultT: + newTask = new Task(TaskWithResultWork); break; default: throw new ArgumentException("Cannot create an instance of static type: " + _taskType); @@ -1440,8 +1440,8 @@ private Task CreateTaskHelper() case TaskType.Task: newTask = new Task(WorkWithState, ZETA_SEED, token, TaskCreationOptions.None); break; - case TaskType.FutureT: - newTask = new Task(FutureWorkWithState, ZETA_SEED, token, TaskCreationOptions.None); + case TaskType.TaskWithResultT: + newTask = new Task(TaskWithResultWorkWithState, ZETA_SEED, token, TaskCreationOptions.None); break; default: throw new ArgumentException("Cannot create an instance of static type: " + _taskType); @@ -1454,8 +1454,8 @@ private Task CreateTaskHelper() case TaskType.Task: newTask = new Task(WorkWithState, ZETA_SEED, TaskCreationOptions.None); break; - case TaskType.FutureT: - newTask = new Task(FutureWorkWithState, ZETA_SEED, TaskCreationOptions.None); + case TaskType.TaskWithResultT: + newTask = new Task(TaskWithResultWorkWithState, ZETA_SEED, TaskCreationOptions.None); break; default: throw new ArgumentException("Cannot create an instance of static type: " + _taskType); @@ -1470,8 +1470,8 @@ private Task CreateTaskHelper() case TaskType.Task: newTask = new Task(WorkWithState, ZETA_SEED, token); break; - case TaskType.FutureT: - newTask = new Task(FutureWorkWithState, ZETA_SEED, token); + case TaskType.TaskWithResultT: + newTask = new Task(TaskWithResultWorkWithState, ZETA_SEED, token); break; default: throw new ArgumentException("Cannot create an instance of static type: " + _taskType); @@ -1484,8 +1484,8 @@ private Task CreateTaskHelper() case TaskType.Task: newTask = new Task(WorkWithState, ZETA_SEED); break; - case TaskType.FutureT: - newTask = new Task(FutureWorkWithState, ZETA_SEED); + case TaskType.TaskWithResultT: + newTask = new Task(TaskWithResultWorkWithState, ZETA_SEED); break; default: throw new ArgumentException("Cannot create an instance of static type: " + _taskType); @@ -1519,12 +1519,12 @@ private void WorkWithState(object o) } } - private double FutureWork() + private double TaskWithResultWork() { - return FutureWorkWithState(ZETA_SEED); + return TaskWithResultWorkWithState(ZETA_SEED); } - private double FutureWorkWithState(object o) + private double TaskWithResultWorkWithState(object o) { // Waiting until the task is assigned on StartNew scenario while (_task == null) @@ -1576,8 +1576,8 @@ private void CheckResult() case TaskType.Task: actualResult = _result; break; - case TaskType.FutureT: - case TaskType.Future: + case TaskType.TaskWithResultT: + case TaskType.TaskWithResult: actualResult = ((Task)_task).Result; break; default: @@ -1605,8 +1605,8 @@ private void CheckResult() internal enum TaskType { Task, - Future, - FutureT, + TaskWithResult, + TaskWithResultT, Promise } diff --git a/src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/Task/TaskRtTests.cs b/src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/Task/TaskRtTests.cs index 2219c58c6b795c..931850512d61a5 100644 --- a/src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/Task/TaskRtTests.cs +++ b/src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/Task/TaskRtTests.cs @@ -59,7 +59,7 @@ public static void RunRunTests() // Test Run(Func>) Task f2 = Task.Run(() => { - // Make sure AttachedToParent is ignored for futures as well as tasks + // Make sure AttachedToParent is ignored for tasks fInner = new Task(() => { return 42; }, TaskCreationOptions.AttachedToParent); Task returnTask = Task.Factory.StartNew(() => 11); return returnTask; @@ -80,11 +80,11 @@ public static void RunRunTests() Assert.True(count == 1, " > FAILED. Task completed but did not run."); Assert.True(task1.Status == TaskStatus.RanToCompletion, " > FAILED. Task did not end in RanToCompletion state."); - Task future1 = Task.Run(() => { return 7; }); - Debug.WriteLine("RunRunTests - Basic w/o CT: waiting for a future. If we hang, something went wrong."); - future1.Wait(); - Assert.True(future1.Result == 7, " > FAILED. Future completed but did not run."); - Assert.True(future1.Status == TaskStatus.RanToCompletion, " > FAILED. Future did not end in RanToCompletion state."); + Task taskWithResult1 = Task.Run(() => { return 7; }); + Debug.WriteLine("RunRunTests - Basic w/o CT: waiting for a Task. If we hang, something went wrong."); + taskWithResult1.Wait(); + Assert.True(taskWithResult1.Result == 7, " > FAILED. Task completed but did not run."); + Assert.True(taskWithResult1.Status == TaskStatus.RanToCompletion, " > FAILED. Task did not end in RanToCompletion state."); task1 = Task.Run(() => { return Task.Run(() => { count = 11; }); }); Debug.WriteLine("RunRunTests - Basic w/o CT: waiting for a task(unwrapped). If we hang, something went wrong."); @@ -92,11 +92,11 @@ public static void RunRunTests() Assert.True(count == 11, " > FAILED. Task(unwrapped) completed but did not run."); Assert.True(task1.Status == TaskStatus.RanToCompletion, " > FAILED. Task(unwrapped) did not end in RanToCompletion state."); - future1 = Task.Run(() => { return Task.Run(() => 17); }); - Debug.WriteLine("RunRunTests - Basic w/o CT: waiting for a future(unwrapped). If we hang, something went wrong."); - future1.Wait(); - Assert.True(future1.Result == 17, " > FAILED. Future(unwrapped) completed but did not run."); - Assert.True(future1.Status == TaskStatus.RanToCompletion, " > FAILED. Future(unwrapped) did not end in RanToCompletion state."); + taskWithResult1 = Task.Run(() => { return Task.Run(() => 17); }); + Debug.WriteLine("RunRunTests - Basic w/o CT: waiting for a Task(unwrapped). If we hang, something went wrong."); + taskWithResult1.Wait(); + Assert.True(taskWithResult1.Result == 17, " > FAILED. Task(unwrapped) completed but did not run."); + Assert.True(taskWithResult1.Status == TaskStatus.RanToCompletion, " > FAILED. Task(unwrapped) did not end in RanToCompletion state."); // // Test basic functionality w/ uncancelled cancellation token @@ -109,11 +109,11 @@ public static void RunRunTests() Assert.True(count == 21, " > FAILED. Task w/ uncanceled token completed but did not run."); Assert.True(task2.Status == TaskStatus.RanToCompletion, " > FAILED. Task w/ uncanceled token did not end in RanToCompletion state."); - Task future2 = Task.Run(() => 27, token); - Debug.WriteLine("RunRunTests: waiting for a future w/ uncanceled token. If we hang, something went wrong."); - future2.Wait(); - Assert.True(future2.Result == 27, " > FAILED. Future w/ uncanceled token completed but did not run."); - Assert.True(future2.Status == TaskStatus.RanToCompletion, " > FAILED. Future w/ uncanceled token did not end in RanToCompletion state."); + Task taskWithResult2 = Task.Run(() => 27, token); + Debug.WriteLine("RunRunTests: waiting for a Task w/ uncanceled token. If we hang, something went wrong."); + taskWithResult2.Wait(); + Assert.True(taskWithResult2.Result == 27, " > FAILED. Task w/ uncanceled token completed but did not run."); + Assert.True(taskWithResult2.Status == TaskStatus.RanToCompletion, " > FAILED. Task w/ uncanceled token did not end in RanToCompletion state."); task2 = Task.Run(() => { return Task.Run(() => { count = 31; }); }, token); Debug.WriteLine("RunRunTests: waiting for a task(unwrapped) w/ uncanceled token. If we hang, something went wrong."); @@ -121,11 +121,11 @@ public static void RunRunTests() Assert.True(count == 31, " > FAILED. Task(unwrapped) w/ uncanceled token completed but did not run."); Assert.True(task2.Status == TaskStatus.RanToCompletion, " > FAILED. Task(unwrapped) w/ uncanceled token did not end in RanToCompletion state."); - future2 = Task.Run(() => Task.Run(() => 37), token); - Debug.WriteLine("RunRunTests: waiting for a future(unwrapped) w/ uncanceled token. If we hang, something went wrong."); - future2.Wait(); - Assert.True(future2.Result == 37, " > FAILED. Future(unwrapped) w/ uncanceled token completed but did not run."); - Assert.True(future2.Status == TaskStatus.RanToCompletion, " > FAILED. Future(unwrapped) w/ uncanceled token did not end in RanToCompletion state."); + taskWithResult2 = Task.Run(() => Task.Run(() => 37), token); + Debug.WriteLine("RunRunTests: waiting for a Task(unwrapped) w/ uncanceled token. If we hang, something went wrong."); + taskWithResult2.Wait(); + Assert.True(taskWithResult2.Result == 37, " > FAILED. Task(unwrapped) w/ uncanceled token completed but did not run."); + Assert.True(taskWithResult2.Status == TaskStatus.RanToCompletion, " > FAILED. Task(unwrapped) w/ uncanceled token did not end in RanToCompletion state."); } [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] @@ -146,12 +146,12 @@ public static void RunRunTests_Cancellation_Negative() Assert.False(count == 41, " > FAILED. Task w/ canceled token ran when it should not have."); Assert.True(task3.IsCanceled, " > FAILED. Task w/ canceled token should have ended in Canceled state"); - Task future3 = Task.Run(() => { count = 47; return count; }, token); - Debug.WriteLine("RunRunTests: waiting for a future w/ canceled token. If we hang, something went wrong."); + Task taskWithResult3 = Task.Run(() => { count = 47; return count; }, token); + Debug.WriteLine("RunRunTests: waiting for a Task w/ canceled token. If we hang, something went wrong."); Assert.Throws( - () => { future3.Wait(); }); - Assert.False(count == 47, " > FAILED. Future w/ canceled token ran when it should not have."); - Assert.True(future3.IsCanceled, " > FAILED. Future w/ canceled token should have ended in Canceled state"); + () => { taskWithResult3.Wait(); }); + Assert.False(count == 47, " > FAILED. Task w/ canceled token ran when it should not have."); + Assert.True(taskWithResult3.IsCanceled, " > FAILED. Task w/ canceled token should have ended in Canceled state"); task3 = Task.Run(() => { return Task.Run(() => { count = 51; }); }, token); Debug.WriteLine("RunRunTests: waiting for a task(unwrapped) w/ canceled token. If we hang, something went wrong."); @@ -160,12 +160,12 @@ public static void RunRunTests_Cancellation_Negative() Assert.False(count == 51, " > FAILED. Task(unwrapped) w/ canceled token ran when it should not have."); Assert.True(task3.IsCanceled, " > FAILED. Task(unwrapped) w/ canceled token should have ended in Canceled state"); - future3 = Task.Run(() => { return Task.Run(() => { count = 57; return count; }); }, token); - Debug.WriteLine("RunRunTests: waiting for a future(unwrapped) w/ canceled token. If we hang, something went wrong."); + taskWithResult3 = Task.Run(() => { return Task.Run(() => { count = 57; return count; }); }, token); + Debug.WriteLine("RunRunTests: waiting for a Task(unwrapped) w/ canceled token. If we hang, something went wrong."); Assert.Throws( - () => { future3.Wait(); }); - Assert.False(count == 57, " > FAILED. Future(unwrapped) w/ canceled token ran when it should not have."); - Assert.True(future3.IsCanceled, " > FAILED. Future(unwrapped) w/ canceled token should have ended in Canceled state"); + () => { taskWithResult3.Wait(); }); + Assert.False(count == 57, " > FAILED. Task(unwrapped) w/ canceled token ran when it should not have."); + Assert.True(taskWithResult3.IsCanceled, " > FAILED. Task(unwrapped) w/ canceled token should have ended in Canceled state"); } [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] @@ -232,25 +232,25 @@ public static void RunRunTests_FastPathTests() // Now run them through Task.Run Task fastPath1 = Task.Run(() => alreadyCompletedTask); fastPath1.Wait(); - Assert.True(fastPath1.Status == TaskStatus.RanToCompletion, "RunRunTests: Expected proxy for already-ran-to-completion future to be in RanToCompletion status"); + Assert.True(fastPath1.Status == TaskStatus.RanToCompletion, "RunRunTests: Expected proxy for already-ran-to-completion Task to be in RanToCompletion status"); fastPath1 = Task.Run(() => alreadyFaultedTask); try { fastPath1.Wait(); - Assert.Fail("RunRunTests: > FAILURE: Expected proxy for already-faulted future to throw on Wait()"); + Assert.Fail("RunRunTests: > FAILURE: Expected proxy for already-faulted Task to throw on Wait()"); } catch { } - Assert.True(fastPath1.Status == TaskStatus.Faulted, "Expected proxy for already-faulted future to be in Faulted status"); + Assert.True(fastPath1.Status == TaskStatus.Faulted, "Expected proxy for already-faulted Task to be in Faulted status"); fastPath1 = Task.Run(() => alreadyCanceledTask); try { fastPath1.Wait(); - Assert.Fail("RunRunTests: > FAILURE: Expected proxy for already-canceled future to throw on Wait()"); + Assert.Fail("RunRunTests: > FAILURE: Expected proxy for already-canceled Task to throw on Wait()"); } catch { } - Assert.True(fastPath1.Status == TaskStatus.Canceled, "RunRunTests: Expected proxy for already-canceled future to be in Canceled status"); + Assert.True(fastPath1.Status == TaskStatus.Canceled, "RunRunTests: Expected proxy for already-canceled Task to be in Canceled status"); } } @@ -732,7 +732,7 @@ public static void RunExceptionWrappingTest() // Test mcw off of Task Task t = Task.Factory.StartNew(delegate { }); - // Throw in the returned future + // Throw in the returned Task Task mcw1 = t.ContinueWith(delegate (Task antecedent) { Task inner = Task.Factory.StartNew(delegate @@ -757,12 +757,12 @@ public static void RunExceptionWrappingTest() return inner; }).Unwrap(); - mcwExceptionChecker(mcw2, "Task antecedent, throw in returned Future"); + mcwExceptionChecker(mcw2, "Task antecedent, throw in returned Task"); - // Test mcw off of future + // Test mcw off of Task Task f = Task.Factory.StartNew(delegate { return 0; }); - // Throw in the returned future + // Throw in the returned Task mcw1 = f.ContinueWith(delegate (Task antecedent) { Task inner = Task.Factory.StartNew(delegate @@ -773,7 +773,7 @@ public static void RunExceptionWrappingTest() return inner; }).Unwrap(); - mcwExceptionChecker(mcw1, "Future antecedent, throw in ContinuationFunction"); + mcwExceptionChecker(mcw1, "Task antecedent, throw in ContinuationFunction"); // Throw in the continuationFunction mcw2 = f.ContinueWith(delegate (Task antecedent) @@ -787,7 +787,7 @@ public static void RunExceptionWrappingTest() return inner; }).Unwrap(); - mcwExceptionChecker(mcw2, "Future antecedent, throw in returned Future"); + mcwExceptionChecker(mcw2, "Task antecedent, throw in returned Task"); // // @@ -833,21 +833,21 @@ public static void RunExceptionWrappingTest() AsyncExceptionChecker(asyncTask, "Task-based FromAsync(beginMethod, ...)"); // Try Task.Factory.FromAsync(iar,...) - Task asyncFuture = Task.Factory.FromAsync(fac.StartRead(10, null, null), delegate (IAsyncResult iar) + Task asyncTaskWithResult = Task.Factory.FromAsync(fac.StartRead(10, null, null), delegate (IAsyncResult iar) { throwException(); return fac.EndRead(iar); }); - AsyncExceptionChecker(asyncFuture, "Future-based FromAsync(iar, ...)"); + AsyncExceptionChecker(asyncTaskWithResult, "Task-based FromAsync(iar, ...)"); - asyncFuture = Task.Factory.FromAsync(fac.StartRead, delegate (IAsyncResult iar) + asyncTaskWithResult = Task.Factory.FromAsync(fac.StartRead, delegate (IAsyncResult iar) { throwException(); return fac.EndRead(iar); }, 10, null); - AsyncExceptionChecker(asyncFuture, "Future-based FromAsync(beginMethod, ...)"); + AsyncExceptionChecker(asyncTaskWithResult, "Task-based FromAsync(beginMethod, ...)"); } [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] @@ -923,7 +923,7 @@ public static void RunHideSchedulerTests_Negative() [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] public static void RunDenyChildAttachTests() { - // StartNew, Task and Future + // StartNew, Task and Task Task i1 = null; Task t1 = Task.Factory.StartNew(() => { @@ -937,7 +937,7 @@ public static void RunDenyChildAttachTests() return 42; }, TaskCreationOptions.DenyChildAttach); - // ctor/Start, Task and Future + // ctor/Start, Task and Task Task i3 = null; Task t3 = new Task(() => { @@ -953,7 +953,7 @@ public static void RunDenyChildAttachTests() }, TaskCreationOptions.DenyChildAttach); t4.Start(); - // continuations, Task and Future + // continuations, Task and Task Task i5 = null; Task t5 = t3.ContinueWith(_ => { @@ -982,26 +982,26 @@ public static void RunDenyChildAttachTests() } [Fact] - public static void RunBasicFutureTest_Negative() + public static void RunBasicTaskWithResultTest_Negative() { - Task future = new Task(() => 1); + Task taskWithResult = new Task(() => 1); Assert.Throws( - () => { future.ContinueWith((Action, object>)null, null, CancellationToken.None); }); + () => { taskWithResult.ContinueWith((Action, object>)null, null, CancellationToken.None); }); Assert.Throws( - () => { future.ContinueWith((Action, object>)null, null, TaskContinuationOptions.None); }); + () => { taskWithResult.ContinueWith((Action, object>)null, null, TaskContinuationOptions.None); }); Assert.Throws( - () => { future.ContinueWith((Action, object>)null, null, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.Default); }); + () => { taskWithResult.ContinueWith((Action, object>)null, null, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.Default); }); Assert.Throws( - () => { future.ContinueWith((t, s) => { }, null, CancellationToken.None, TaskContinuationOptions.None, null); }); + () => { taskWithResult.ContinueWith((t, s) => { }, null, CancellationToken.None, TaskContinuationOptions.None, null); }); Assert.Throws( - () => { future.ContinueWith((Func, object, int>)null, null, CancellationToken.None); }); + () => { taskWithResult.ContinueWith((Func, object, int>)null, null, CancellationToken.None); }); Assert.Throws( - () => { future.ContinueWith((Func, object, int>)null, null, TaskContinuationOptions.None); }); + () => { taskWithResult.ContinueWith((Func, object, int>)null, null, TaskContinuationOptions.None); }); Assert.Throws( - () => { future.ContinueWith((Func, object, int>)null, null, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.Default); }); + () => { taskWithResult.ContinueWith((Func, object, int>)null, null, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.Default); }); Assert.Throws( - () => { future.ContinueWith((t, s) => 2, null, CancellationToken.None, TaskContinuationOptions.None, null); }); + () => { taskWithResult.ContinueWith((t, s) => 2, null, CancellationToken.None, TaskContinuationOptions.None, null); }); } #region Helper Methods / Classes diff --git a/src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/Task/TaskRtTests_Core.cs b/src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/Task/TaskRtTests_Core.cs index d133ae78a57d11..657b1de87f740a 100644 --- a/src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/Task/TaskRtTests_Core.cs +++ b/src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/Task/TaskRtTests_Core.cs @@ -534,8 +534,8 @@ public static void TestTaskTConstruction_bare() Assert.True(ex == null, "TestTaskTConstruction_bare: Did not expect an exception"); Assert.True(sideEffect, "TestTaskTConstruction_bare: The func delegate apparently did not run"); - Assert.True(f1.Result == 42, "TestTaskTConstruction_bare: Expected future's result to be 42"); - Assert.True(f1.Status == TaskStatus.RanToCompletion, "TestTaskTConstruction_bare: Expected future to be in RanToCompletion status"); + Assert.True(f1.Result == 42, "TestTaskTConstruction_bare: Expected Task result to be 42"); + Assert.True(f1.Status == TaskStatus.RanToCompletion, "TestTaskTConstruction_bare: Expected Task to be in RanToCompletion status"); Assert.True(useObj || (asyncState == null), "TestTaskTConstruction_bare: Expected non-null AsyncState only if object overload was used"); Assert.True((!useObj) || (asyncState == refObj), "TestTaskTConstruction_bare: Wrong AsyncState value returned"); } @@ -607,8 +607,8 @@ public static void TestTaskTConstruction_ct() object asyncState = ((IAsyncResult)f1).AsyncState; Assert.True((ex != null) || (result == 42), "TestTaskTConstruction_ct: Expected either a valid result or an exception"); - Assert.True(preCanceledToken == (f1.Status == TaskStatus.Canceled), "TestTaskTConstruction_ct: Expected future cancellation only with pre-canceled token"); - Assert.True(preCanceledToken != (f1.Status == TaskStatus.RanToCompletion), "TestTaskTConstruction_ct: Expected future to complete only with un-canceled token"); + Assert.True(preCanceledToken == (f1.Status == TaskStatus.Canceled), "TestTaskTConstruction_ct: Expected Task cancellation only with pre-canceled token"); + Assert.True(preCanceledToken != (f1.Status == TaskStatus.RanToCompletion), "TestTaskTConstruction_ct: Expected Task to complete only with un-canceled token"); Assert.True(preCanceledToken != (result == 42), "TestTaskTConstruction_ct: Expected valid result only with non-canceled token"); Assert.True(preCanceledToken == (ex != null), "TestTaskTConstruction_ct: Expected exception only with pre-canceled token"); Assert.True( @@ -749,12 +749,12 @@ public static void TestTaskTConstruction_ct_tco() } } - // Basic future functionality. This is also covered in scenario unit tests, here we focus on wait functionality, and promises + // Basic Task functionality. This is also covered in scenario unit tests, here we focus on wait functionality, and promises [Fact] - public static void RunBasicFutureTest() + public static void RunBasicTaskWithResultTest() { // - // future basic functionality tests + // Task basic functionality tests // // @@ -765,53 +765,53 @@ public static void RunBasicFutureTest() TaskCompletionSource tcs = new TaskCompletionSource(); if (((IAsyncResult)tcs.Task).AsyncState != null) { - Assert.Fail("RunBasicFutureTest - TaskCompletionSource: > FAILED! non-null state when not spec'd in empty tcs ctor"); + Assert.Fail("RunBasicTaskWithResultTest - TaskCompletionSource: > FAILED! non-null state when not spec'd in empty tcs ctor"); } if (tcs.Task.CreationOptions != TaskCreationOptions.None) { - Assert.Fail("RunBasicFutureTest - TaskCompletionSource: > FAILED! non-None TCO in tcs ctor when not spec'd in empty ctor"); + Assert.Fail("RunBasicTaskWithResultTest - TaskCompletionSource: > FAILED! non-None TCO in tcs ctor when not spec'd in empty ctor"); } tcs.SetResult(10); tcs = new TaskCompletionSource(testOptions); if (tcs.Task.CreationOptions != testOptions) { - Assert.Fail("RunBasicFutureTest - TaskCompletionSource: > FAILED! TCO in tcs ctor not persistent"); + Assert.Fail("RunBasicTaskWithResultTest - TaskCompletionSource: > FAILED! TCO in tcs ctor not persistent"); } if (((IAsyncResult)tcs.Task).AsyncState != null) { - Assert.Fail("RunBasicFutureTest - TaskCompletionSource: > FAILED! non-null state when not spec'd in tcs ctor"); + Assert.Fail("RunBasicTaskWithResultTest - TaskCompletionSource: > FAILED! non-null state when not spec'd in tcs ctor"); } tcs.SetResult(10); tcs = new TaskCompletionSource(testState); if (((IAsyncResult)tcs.Task).AsyncState != testState) { - Assert.Fail("RunBasicFutureTest - TaskCompletionSource: > FAILED! state in tcs ctor not persistent"); + Assert.Fail("RunBasicTaskWithResultTest - TaskCompletionSource: > FAILED! state in tcs ctor not persistent"); } if (tcs.Task.CreationOptions != TaskCreationOptions.None) { - Assert.Fail("RunBasicFutureTest - TaskCompletionSource: > FAILED! non-None TCO in tcs ctor when not spec'd in ctor"); + Assert.Fail("RunBasicTaskWithResultTest - TaskCompletionSource: > FAILED! non-None TCO in tcs ctor when not spec'd in ctor"); } tcs.SetResult(10); tcs = new TaskCompletionSource(testState, testOptions); if (tcs.Task.CreationOptions != testOptions) { - Assert.Fail("RunBasicFutureTest - TaskCompletionSource: > FAILED! TCO with state in tcs ctor not persistent"); + Assert.Fail("RunBasicTaskWithResultTest - TaskCompletionSource: > FAILED! TCO with state in tcs ctor not persistent"); } if (((IAsyncResult)tcs.Task).AsyncState != testState) { - Assert.Fail("RunBasicFutureTest - TaskCompletionSource: > FAILED! state with options in tcs ctor not persistent"); + Assert.Fail("RunBasicTaskWithResultTest - TaskCompletionSource: > FAILED! state with options in tcs ctor not persistent"); } tcs.SetResult(10); } [Fact] - public static void RunBasicFutureTest_Negative() + public static void RunBasicTaskWithResultTest_Negative() { // - // future basic functionality tests + // Task basic functionality tests // // Test exceptional conditions @@ -830,7 +830,7 @@ public static void RunBasicFutureTest_Negative() } [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] - public static void RunBasicFutureTest_PromiseTestsAndCancellation() + public static void RunBasicTaskWithResultTest_PromiseTestsAndCancellation() { // // promise tests @@ -872,24 +872,24 @@ public static void RunBasicFutureTest_PromiseTestsAndCancellation() if (promise2.Task.Result != 5678) { - Assert.Fail("RunBasicFutureTest - Promise Test: > error: Promise value unblocked, but wrong value was read"); + Assert.Fail("RunBasicTaskWithResultTest - Promise Test: > error: Promise value unblocked, but wrong value was read"); } if (cancellationExceptionReceived == false || someotherExceptionReceived == true) { - Assert.Fail("RunBasicFutureTest - Promise Test: > error: Cancel()ed promise didn't throw TaskCanceledException on value accessor"); + Assert.Fail("RunBasicTaskWithResultTest - Promise Test: > error: Cancel()ed promise didn't throw TaskCanceledException on value accessor"); } if (unexpectedStateObserved) { - Assert.Fail("RunBasicFutureTest - Promise Test: > error: unexpected state observed in Promise test"); + Assert.Fail("RunBasicTaskWithResultTest - Promise Test: > error: unexpected state observed in Promise test"); } // Creating a TCS with a promise-style constructor that only allows TaskCreationOptions.AttachedToParent try { TaskCompletionSource tcs = new TaskCompletionSource(TaskCreationOptions.PreferFairness); - Assert.Fail("RunBasicFutureTest - TaskCompletionSource: > FAILED! illegal tcs ctor TCO did not cause exception"); + Assert.Fail("RunBasicTaskWithResultTest - TaskCompletionSource: > FAILED! illegal tcs ctor TCO did not cause exception"); } catch (ArgumentOutOfRangeException) { @@ -1618,7 +1618,7 @@ public static void RunLongRunningTaskTests() // Various tests to exercise the refactored Task class. - // Create()==>Factory.StartNew(), Task and Future ctors have been added, + // Create()==>Factory.StartNew(), Task and Task ctors have been added, // and Task.Start() has been added. [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] public static void RunRefactoringTests() diff --git a/src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/TaskFactory/TaskFactory_FromAsyncTests.cs b/src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/TaskFactory/TaskFactory_FromAsyncTests.cs index 597f3136dc1cd1..7f2d569f201a6d 100644 --- a/src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/TaskFactory/TaskFactory_FromAsyncTests.cs +++ b/src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/TaskFactory/TaskFactory_FromAsyncTests.cs @@ -299,31 +299,31 @@ public static void RunAPMFactoryTests() Assert.Equal(TaskStatus.Canceled, asyncTask.Status); // Test IAsyncResult overload that returns Task - Task asyncFuture = null; - asyncFuture = Task.Factory.FromAsync( + Task asyncTaskWithResult = null; + asyncTaskWithResult = Task.Factory.FromAsync( fac.StartRead(3, null, null), delegate (IAsyncResult iar) { throw new OperationCanceledException("FromAsync"); }); ae = Assert.Throws(() => { - asyncTask.Wait(); + asyncTaskWithResult.Wait(); }); Assert.Equal(typeof(TaskCanceledException), ae.InnerException.GetType()); - Assert.Equal(TaskStatus.Canceled, asyncTask.Status); + Assert.Equal(TaskStatus.Canceled, asyncTaskWithResult.Status); // Test beginMethod overload that returns Task - asyncFuture = null; - asyncFuture = Task.Factory.FromAsync( + asyncTaskWithResult = null; + asyncTaskWithResult = Task.Factory.FromAsync( fac.StartRead, delegate (IAsyncResult iar) { throw new OperationCanceledException("FromAsync"); }, 3, null); ae = Assert.Throws(() => { - asyncFuture.Wait(); + asyncTaskWithResult.Wait(); }); Assert.Equal(typeof(TaskCanceledException), ae.InnerException.GetType()); - Assert.Equal(TaskStatus.Canceled, asyncFuture.Status); + Assert.Equal(TaskStatus.Canceled, asyncTaskWithResult.Status); // // Make sure that tasks aren't left hanging if StartXYZ() throws an exception