1 // Licensed to the .NET Foundation under one or more agreements. 2 // The .NET Foundation licenses this file to you under the MIT license. 3 // See the LICENSE file in the project root for more information. 4 5 using Xunit; 6 using System; 7 using System.Threading; 8 using System.Threading.Tasks; 9 10 namespace System.Threading.Tasks.Tests.ContinueWithAllAny 11 { 12 #region Helper Classes / Enums 13 14 /// <summary> 15 /// Tests for ContinueWhenAny, and ContinueWhenAll 16 // The strategy is simple: create one or more antecedent tasks to pass into ContinueWhen/ContinueWhenAny. 17 /// Then, call ContinueWhen/ContinueWhenAny. Then check whether the continuation ran or not. 18 /// </summary> 19 public sealed class TaskContinueWithAllAnyTest 20 { 21 #region Private Fields 22 23 private API _api; // the API to be tested 24 private TaskType _taskType; // the continuation chain type 25 private TaskContinuationOptions _tcOption; // the TaskContinuationOptions given to the ContinueWhenAll/Any 26 private TaskScheduler _tm; // the TaskScheduler given to the ContinueWhenAll/Any 27 private CancellationToken _cancellationToken; // the CancellationToken given to the ContinueWhenAll/Any 28 private Task _continuation = null; 29 30 private TaskInfo[] _taskInfos; // task info for each task 31 private Task[] _tasks; // tasks to be continued from 32 33 #endregion 34 35 #region Constructor 36 37 /// <summary> 38 /// Create the test given the parameters 39 /// </summary> TaskContinueWithAllAnyTest(TestParameters parameters)40 public TaskContinueWithAllAnyTest(TestParameters parameters) 41 { 42 _api = parameters.Api; 43 _taskType = parameters.TaskType; 44 _tcOption = parameters.ContinuationOptions; 45 46 47 // set up the TaskScheduler under which the continuation will be scheduled 48 _tm = TaskScheduler.Default; 49 50 // create a new cancellation token for each test 51 _cancellationToken = parameters.WithCancellation ? CancellationToken.None : new CancellationToken(); 52 53 _taskInfos = parameters.AllTaskInfos; 54 _tasks = new Task[parameters.AllTaskInfos.Length]; 55 } 56 57 #endregion 58 59 /// <summary> 60 /// This is the real execution 61 /// </summary> 62 /// <returns>true for pass, false otherwise</returns> RealRun()63 internal void RealRun() 64 { 65 CreateTasks(); 66 67 // set up the continuation Action/Func body delegate 68 // The continuation task is the one that actually verifies that the antecedent tasks executed. 69 70 Action<Task[]> allCompletedAction = (inputTasks) => 71 { 72 VerifyAll(inputTasks); 73 }; 74 75 Action<Task<double>[]> allCompletedActionT = (inputTasks) => 76 { 77 VerifyAllT(inputTasks); 78 }; 79 80 Action<Task> oneCompletedAction = (inputTask) => 81 { 82 VerifyAny(inputTask); 83 }; 84 85 Action<Task<double>> oneCompletedActionT = (inputTask) => 86 { 87 VerifyAnyT(inputTask); 88 }; 89 90 Func<Task[], bool> allCompletedFunc = (inputTasks) => 91 { 92 VerifyAll(inputTasks); 93 return true; 94 }; 95 96 Func<Task<double>[], bool> allCompletedFuncT = (inputTasks) => 97 { 98 VerifyAllT(inputTasks); 99 return true; 100 }; 101 102 Func<Task, bool> oneCompletedFunc = (inputTask) => 103 { 104 VerifyAny(inputTask); 105 return true; 106 }; 107 108 Func<Task<double>, bool> oneCompletedFuncT = (inputTask) => 109 { 110 VerifyAnyT(inputTask); 111 return true; 112 }; 113 114 // invoke various continueWith overloads 115 // 116 // The long and deep nested if statements can be difficult to follow, but 117 // in general it is easier to go back from the instance of the test in the 118 // xml file src\QA\PCP\Pfx\Functional\TPL\APIs\Task\Data\TaskContinueWithAllAnyTest.xml 119 // and map it to one of the things this is running. 120 // 121 // That is, given a task type, tm type, api, cancellation, etc. it should be 122 // straightforward to figure out what variant of ContinueWhen is called. 123 // 124 switch (_taskType) 125 { 126 case TaskType.TaskContinueWithTask: 127 128 if (_cancellationToken.CanBeCanceled) 129 { 130 if (_api == API.ContinueWhenAll) 131 { 132 _continuation = Task.Factory.ContinueWhenAll(_tasks, allCompletedAction, _cancellationToken); 133 } 134 else // must be API.ContinueWhenAny 135 { 136 _continuation = Task.Factory.ContinueWhenAny(_tasks, oneCompletedAction, _cancellationToken); 137 } 138 } 139 else if (_tm != TaskScheduler.Default) 140 { 141 if (_api == API.ContinueWhenAll) 142 { 143 _continuation = Task.Factory.ContinueWhenAll(_tasks, allCompletedAction, _cancellationToken, _tcOption, _tm); 144 } 145 else // must be API.ContinueWhenAny 146 { 147 _continuation = Task.Factory.ContinueWhenAny(_tasks, oneCompletedAction, _cancellationToken, _tcOption, _tm); 148 } 149 } 150 else if (_tcOption != TaskContinuationOptions.None) 151 { 152 if (_api == API.ContinueWhenAll) 153 { 154 _continuation = Task.Factory.ContinueWhenAll(_tasks, allCompletedAction, _tcOption); 155 } 156 else // must be API.ContinueWhenAny 157 { 158 _continuation = Task.Factory.ContinueWhenAny(_tasks, oneCompletedAction, _tcOption); 159 } 160 } 161 else 162 { 163 if (_api == API.ContinueWhenAll) 164 { 165 _continuation = Task.Factory.ContinueWhenAll(_tasks, allCompletedAction); 166 } 167 else // must be API.ContinueWhenAny 168 { 169 _continuation = Task.Factory.ContinueWhenAny(_tasks, oneCompletedAction); 170 } 171 } 172 173 break; 174 175 case TaskType.TaskTContinueWithTask: 176 177 Task<double>[] taskDoubles = new Task<double>[_tasks.Length]; 178 for (int i = 0; i < _tasks.Length; i++) 179 taskDoubles[i] = (Task<double>)_tasks[i]; 180 181 if (_cancellationToken.CanBeCanceled) 182 { 183 if (_api == API.ContinueWhenAll) 184 _continuation = Task.Factory.ContinueWhenAll<double>(taskDoubles, allCompletedActionT, _cancellationToken); 185 else // must be API.ContinueWhenAny 186 _continuation = Task.Factory.ContinueWhenAny<double>(taskDoubles, oneCompletedActionT, _cancellationToken); 187 } 188 else if (_tm != TaskScheduler.Default) 189 { 190 if (_api == API.ContinueWhenAll) 191 _continuation = Task.Factory.ContinueWhenAll<double>(taskDoubles, allCompletedActionT, _cancellationToken, _tcOption, _tm); 192 else // must be API.ContinueWhenAny 193 _continuation = Task.Factory.ContinueWhenAny<double>(taskDoubles, oneCompletedActionT, _cancellationToken, _tcOption, _tm); 194 } 195 else if (_tcOption != TaskContinuationOptions.None) 196 { 197 if (_api == API.ContinueWhenAll) 198 _continuation = Task.Factory.ContinueWhenAll<double>(taskDoubles, allCompletedActionT, _tcOption); 199 else // must be API.ContinueWhenAny 200 _continuation = Task.Factory.ContinueWhenAny<double>(taskDoubles, oneCompletedActionT, _tcOption); 201 } 202 else 203 { 204 if (_api == API.ContinueWhenAll) 205 _continuation = Task.Factory.ContinueWhenAll<double>(taskDoubles, allCompletedActionT); 206 else // must be API.ContinueWhenAny 207 _continuation = Task.Factory.ContinueWhenAny<double>(taskDoubles, oneCompletedActionT); 208 } 209 210 break; 211 212 case TaskType.TaskContinueWithTaskT_NEW: 213 214 if (_cancellationToken.CanBeCanceled) 215 { 216 if (_api == API.ContinueWhenAll) 217 _continuation = Task.Factory.ContinueWhenAll<bool>(_tasks, allCompletedFunc, _cancellationToken); 218 else // must be API.ContinueWhenAny 219 _continuation = Task.Factory.ContinueWhenAny<bool>(_tasks, oneCompletedFunc, _cancellationToken); 220 } 221 else if (_tm != TaskScheduler.Default) 222 { 223 if (_api == API.ContinueWhenAll) 224 _continuation = Task.Factory.ContinueWhenAll<bool>(_tasks, allCompletedFunc, _cancellationToken, _tcOption, _tm); 225 else // must be API.ContinueWhenAny 226 _continuation = Task.Factory.ContinueWhenAny<bool>(_tasks, oneCompletedFunc, _cancellationToken, _tcOption, _tm); 227 } 228 else if (_tcOption != TaskContinuationOptions.None) 229 { 230 if (_api == API.ContinueWhenAll) 231 _continuation = Task.Factory.ContinueWhenAll<bool>(_tasks, allCompletedFunc, _tcOption); 232 else // must be API.ContinueWhenAny 233 _continuation = Task.Factory.ContinueWhenAny<bool>(_tasks, oneCompletedFunc, _tcOption); 234 } 235 else 236 { 237 if (_api == API.ContinueWhenAll) 238 _continuation = Task.Factory.ContinueWhenAll<bool>(_tasks, allCompletedFunc); 239 else // must be API.ContinueWhenAny 240 _continuation = Task.Factory.ContinueWhenAny<bool>(_tasks, oneCompletedFunc); 241 } 242 243 break; 244 245 case TaskType.TaskContinueWithTaskT: 246 247 if (_cancellationToken.CanBeCanceled) 248 { 249 if (_api == API.ContinueWhenAll) 250 _continuation = Task<bool>.Factory.ContinueWhenAll(_tasks, allCompletedFunc, _cancellationToken); 251 else // must be API.ContinueWhenAny 252 _continuation = Task<bool>.Factory.ContinueWhenAny(_tasks, oneCompletedFunc, _cancellationToken); 253 } 254 else if (_tm != TaskScheduler.Default) 255 { 256 if (_api == API.ContinueWhenAll) 257 _continuation = Task<bool>.Factory.ContinueWhenAll(_tasks, allCompletedFunc, _cancellationToken, _tcOption, _tm); 258 else // must be API.ContinueWhenAny 259 _continuation = Task<bool>.Factory.ContinueWhenAny(_tasks, oneCompletedFunc, _cancellationToken, _tcOption, _tm); 260 } 261 else if (_tcOption != TaskContinuationOptions.None) 262 { 263 if (_api == API.ContinueWhenAll) 264 _continuation = Task<bool>.Factory.ContinueWhenAll(_tasks, allCompletedFunc, _tcOption); 265 else // must be API.ContinueWhenAny 266 _continuation = Task<bool>.Factory.ContinueWhenAny(_tasks, oneCompletedFunc, _tcOption); 267 } 268 else 269 { 270 if (_api == API.ContinueWhenAll) 271 _continuation = Task<bool>.Factory.ContinueWhenAll(_tasks, allCompletedFunc); 272 else // must be API.ContinueWhenAny 273 _continuation = Task<bool>.Factory.ContinueWhenAny(_tasks, oneCompletedFunc); 274 } 275 276 break; 277 278 case TaskType.TaskTContinueWithTaskT_NEW: 279 280 Task<double>[] taskDoublesB = new Task<double>[_tasks.Length]; 281 for (int i = 0; i < _tasks.Length; i++) 282 taskDoublesB[i] = (Task<double>)_tasks[i]; 283 284 if (_cancellationToken.CanBeCanceled) 285 { 286 if (_api == API.ContinueWhenAll) 287 _continuation = Task.Factory.ContinueWhenAll<double, bool>(taskDoublesB, allCompletedFuncT, _cancellationToken); 288 else // must be API.ContinueWhenAny 289 _continuation = Task.Factory.ContinueWhenAny<double, bool>(taskDoublesB, oneCompletedFuncT, _cancellationToken); 290 } 291 else if (_tm != TaskScheduler.Default) 292 { 293 if (_api == API.ContinueWhenAll) 294 _continuation = Task.Factory.ContinueWhenAll<double, bool>(taskDoublesB, allCompletedFuncT, _cancellationToken, _tcOption, _tm); 295 else // must be API.ContinueWhenAny 296 _continuation = Task.Factory.ContinueWhenAny<double, bool>(taskDoublesB, oneCompletedFuncT, _cancellationToken, _tcOption, _tm); 297 } 298 else if (_tcOption != TaskContinuationOptions.None) 299 { 300 if (_api == API.ContinueWhenAll) 301 _continuation = Task.Factory.ContinueWhenAll<double, bool>(taskDoublesB, allCompletedFuncT, _tcOption); 302 else // must be API.ContinueWhenAny 303 _continuation = Task.Factory.ContinueWhenAny<double, bool>(taskDoublesB, oneCompletedFuncT, _tcOption); 304 } 305 else 306 { 307 if (_api == API.ContinueWhenAll) 308 _continuation = Task.Factory.ContinueWhenAll<double, bool>(taskDoublesB, allCompletedFuncT); 309 else // must be API.ContinueWhenAny 310 _continuation = Task.Factory.ContinueWhenAny<double, bool>(taskDoublesB, oneCompletedFuncT); 311 } 312 313 break; 314 315 case TaskType.TaskTContinueWithTaskT: 316 Task<double>[] taskDoublesC = new Task<double>[_tasks.Length]; 317 for (int i = 0; i < _tasks.Length; i++) 318 taskDoublesC[i] = (Task<double>)_tasks[i]; 319 320 if (_cancellationToken.CanBeCanceled) 321 { 322 if (_api == API.ContinueWhenAll) 323 _continuation = Task<bool>.Factory.ContinueWhenAll<double>(taskDoublesC, allCompletedFuncT, _cancellationToken); 324 else // must be API.ContinueWhenAny 325 _continuation = Task<bool>.Factory.ContinueWhenAny<double>(taskDoublesC, oneCompletedFuncT, _cancellationToken); 326 } 327 else if (_tm != TaskScheduler.Default) 328 { 329 if (_api == API.ContinueWhenAll) 330 _continuation = Task<bool>.Factory.ContinueWhenAll<double>(taskDoublesC, allCompletedFuncT, _cancellationToken, _tcOption, _tm); 331 else // must be API.ContinueWhenAny 332 _continuation = Task<bool>.Factory.ContinueWhenAny<double>(taskDoublesC, oneCompletedFuncT, _cancellationToken, _tcOption, _tm); 333 } 334 else if (_tcOption != TaskContinuationOptions.None) 335 { 336 if (_api == API.ContinueWhenAll) 337 _continuation = Task<bool>.Factory.ContinueWhenAll<double>(taskDoublesC, allCompletedFuncT, _tcOption); 338 else // must be API.ContinueWhenAny 339 _continuation = Task<bool>.Factory.ContinueWhenAny<double>(taskDoublesC, oneCompletedFuncT, _tcOption); 340 } 341 else 342 { 343 if (_api == API.ContinueWhenAll) 344 _continuation = Task<bool>.Factory.ContinueWhenAll<double>(taskDoublesC, allCompletedFuncT); 345 else // must be API.ContinueWhenAny 346 _continuation = Task<bool>.Factory.ContinueWhenAny<double>(taskDoublesC, oneCompletedFuncT); 347 } 348 349 break; 350 } 351 352 // check continuation is non-blocking, i.e., it does not block until all/one tasks finish 353 if (_continuation.Status != TaskStatus.WaitingForActivation) 354 Assert.True(false, string.Format("continuation task should be created when none task finish")); 355 356 // allow continuation to kick off later 357 foreach (Task t in _tasks) 358 { 359 t.Start(); 360 } 361 362 bool verified = true; 363 364 // check result 365 if (_continuation is Task<bool>) 366 { 367 verified = ((Task<bool>)_continuation).Result; 368 } 369 else 370 { 371 _continuation.Wait(); 372 } 373 } 374 375 #region Private Methods 376 CreateTasks()377 private void CreateTasks() 378 { 379 for (int i = 0; i < _taskInfos.Length; i++) 380 { 381 int iCopy = i; 382 if (_taskType == TaskType.TaskContinueWithTask || _taskType == TaskType.TaskContinueWithTaskT) 383 { 384 _taskInfos[i].Task = new Task(() => 385 { 386 _taskInfos[iCopy].RunWorkload(); 387 }, _taskInfos[i].CancellationTokenSource.Token); 388 } 389 else 390 { 391 _taskInfos[i].Task = new Task<double>(() => 392 { 393 _taskInfos[iCopy].RunWorkload(); 394 return _taskInfos[iCopy].Result; 395 }, _taskInfos[i].CancellationTokenSource.Token); 396 } 397 398 _tasks[i] = _taskInfos[i].Task; 399 } 400 } 401 402 // verification for ContinueWhenAll VerifyAll(Task[] inputTasks)403 private void VerifyAll(Task[] inputTasks) 404 { 405 int firstIncompleteTaskIndex = -1; 406 for (int i = 0; i < inputTasks.Length; i++) 407 { 408 var task = inputTasks[i]; 409 if (!task.IsCompleted) 410 { 411 firstIncompleteTaskIndex = i; 412 break; 413 } 414 } 415 416 if (firstIncompleteTaskIndex != -1) 417 Assert.True(false, string.Format("ContinueWhenAll contract is broken -- Task at Index = {0} does not finish", firstIncompleteTaskIndex)); 418 419 // do the sanity check against the input tasks 420 CheckSequence(_tasks, inputTasks); 421 422 Verify(); 423 } 424 425 // verification for ContinueWhenAll VerifyAllT(Task<double>[] inputTasks)426 private void VerifyAllT(Task<double>[] inputTasks) 427 { 428 int firstIncompleteTaskIndex = -1; 429 for (int i = 0; i < inputTasks.Length; i++) 430 { 431 var task = inputTasks[i]; 432 if (!task.IsCompleted) 433 { 434 firstIncompleteTaskIndex = i; 435 break; 436 } 437 } 438 439 if (firstIncompleteTaskIndex != -1) 440 Assert.True(false, string.Format("ContinueWhenAll contract is broken -- Task at Index = {0} does not finish", firstIncompleteTaskIndex)); 441 442 // do the sanity check against the input tasks 443 CheckSequence(_tasks, inputTasks); 444 445 Verify(); 446 } 447 448 // verification for ContinueWhenAny VerifyAny(Task inputTask)449 private void VerifyAny(Task inputTask) 450 { 451 if (!inputTask.IsCompleted) 452 Assert.True(false, string.Format("ContinueWhenAny contract is broken -- none task has completed")); 453 454 // do the sanity check against the input task 455 456 bool found = false; 457 for (int i = 0; i < _tasks.Length; i++) 458 { 459 Task task = _tasks[i]; 460 if (task.Equals(inputTask)) 461 { 462 found = true; 463 break; 464 } 465 } 466 467 if (!found) 468 Assert.True(false, string.Format("input task do not exist in the expected original tasks")); 469 470 Verify(); 471 } 472 473 // verification for ContinueWhenAny VerifyAnyT(Task<double> inputTask)474 private void VerifyAnyT(Task<double> inputTask) 475 { 476 if (!inputTask.IsCompleted) 477 Assert.True(false, string.Format("ContinueWhenAny contract is broken -- none task has completed")); 478 479 // do the sanity check against the input task 480 481 482 bool found = false; 483 for (int i = 0; i < _tasks.Length; i++) 484 { 485 Task task = _tasks[i]; 486 if (task.Equals(inputTask)) 487 { 488 found = true; 489 break; 490 } 491 } 492 493 if (!found) 494 Assert.True(false, string.Format("input task do not exist in the expected original tasks")); 495 496 Verify(); 497 } 498 499 // the common verification shared by ContinueWhenAll/Any Verify()500 private void Verify() 501 { 502 // check against the taskCreationOptions 503 TaskCreationOptions option = (TaskCreationOptions)(_tcOption & ~TaskContinuationOptions.ExecuteSynchronously); 504 505 if (TaskContinuationOptions.LazyCancellation != _tcOption) 506 { 507 if (_continuation.CreationOptions != option) 508 Assert.True(false, string.Format("Wrong TaskCreationOption of {0}, expecting {1}", _continuation.CreationOptions, _tcOption)); 509 } 510 else 511 { 512 if (_continuation.CreationOptions != TaskCreationOptions.None) 513 Assert.True(false, string.Format("Wrong TaskCreationOption of {0}, expecting {1}", _continuation.CreationOptions, TaskCreationOptions.None)); 514 } 515 516 // check against the taskScheduler 517 // @TODO: add verification for SynchronizedTM, CustomizedTM later 518 if (TaskScheduler.Current != _tm) 519 Assert.True(false, string.Format("Wrong TaskScheduler of {0}, expecting {1}", TaskScheduler.Current.Id, _tm.Id)); 520 521 // check for the workload results 522 for (int i = 0; i < _taskInfos.Length; i++) 523 { 524 TaskInfo ti = _taskInfos[i]; 525 526 WorkloadType workType = ti.WorkType; 527 528 if (workType == WorkloadType.Exceptional) 529 { 530 try 531 { 532 ti.Task.Wait(); 533 534 // should never come here 535 Assert.True(false, string.Format("excepted TPLTestException in Task at Index = {0} NOT caught", i)); 536 } 537 catch (AggregateException ex) 538 { 539 ex.Flatten().Handle((e) => 540 { 541 TPLTestException expectedExp = e as TPLTestException; 542 return expectedExp != null && expectedExp.FromTaskId == ti.Task.Id; 543 }); 544 } 545 } 546 else if (workType == WorkloadType.Cancelled) 547 { 548 try 549 { 550 ti.Task.Wait(); 551 552 // should never come here 553 Assert.True(false, string.Format("excepted TaskCanceledException in Task at Index = {0} NOT caught", i)); 554 } 555 catch (AggregateException ex) 556 { 557 ex.Flatten().Handle((e) => 558 { 559 TaskCanceledException expectedExp = e as TaskCanceledException; 560 return expectedExp != null && expectedExp.Task == ti.Task; 561 }); 562 } 563 } 564 else 565 { 566 double result = (ti.Task is Task<double>) ? ((Task<double>)(ti.Task)).Result : ti.Result; 567 if (ti.Task.IsCompleted && !CheckResult(result)) 568 Assert.True(false, string.Format("Failed result verification in Task at Index = {0}. Task result is {1} TaskStatus is {2}", i, result, ti.Task.Status)); 569 570 //else if (ti.Thread == null && result != -1) 571 //{ 572 // Assert.True(false, string.Format("Result must remain uninitialized for unstarted task")); 573 //} 574 } 575 } 576 } 577 CheckResult(double result)578 private bool CheckResult(double result) 579 { 580 //Function point comparison cant be done by rounding off to nearest decimal points since 581 //1.64 could be represented as 1.63999999 or as 1.6499999999. To perform floating point comparisons, 582 //a range has to be defined and check to ensure that the result obtained is within the specified range 583 double minLimit = 1.63; 584 double maxLimit = 1.65; 585 586 return result > minLimit && result < maxLimit; 587 } 588 CheckSequence(Task[] expected, Task[] actual)589 private void CheckSequence(Task[] expected, Task[] actual) 590 { 591 Assert.Equal(expected.Length, actual.Length); 592 for (int i = 0; i < expected.Length; i++) 593 { 594 Assert.Equal(expected[i], actual[i]); 595 } 596 } 597 598 #endregion 599 } 600 601 public class TestParameters 602 { 603 public readonly TaskInfo[] AllTaskInfos; 604 605 public readonly API Api; 606 607 public readonly TaskType TaskType; 608 609 public readonly TaskContinuationOptions ContinuationOptions; 610 611 public readonly bool WithCancellation; 612 TestParameters(API api, TaskType taskType, TaskContinuationOptions continuationOptions, bool withCancellation, TaskInfo[] allTasks)613 public TestParameters(API api, TaskType taskType, TaskContinuationOptions continuationOptions, bool withCancellation, TaskInfo[] allTasks) 614 { 615 Api = api; 616 TaskType = taskType; 617 ContinuationOptions = continuationOptions; 618 WithCancellation = withCancellation; 619 AllTaskInfos = allTasks; 620 } 621 } 622 623 /// <summary> 624 /// The Tree node Data type 625 /// 626 /// While the tree is not restricted to this data type 627 /// the implemented tests are using the TaskInfo_ContinueWithAllAny data type for their scenarios 628 /// </summary> 629 public class TaskInfo 630 { 631 private static double s_UNINITIALED_RESULT = -1; 632 TaskInfo(WorkloadType workType)633 public TaskInfo(WorkloadType workType) 634 { 635 WorkType = workType; 636 637 CancellationTokenSource = new CancellationTokenSource(); 638 CancellationToken = CancellationTokenSource.Token; 639 640 Result = s_UNINITIALED_RESULT; 641 } 642 643 #region Properties 644 645 /// <summary> 646 /// The task associated with the current node 647 /// </summary> 648 public Task Task { get; set; } 649 650 /// <summary> 651 /// Current node Name 652 /// </summary> 653 public string Name { get; set; } 654 655 /// <summary> 656 /// WorkloadType_ContinueWithAllAny of task associated with the current node 657 /// </summary> 658 public WorkloadType WorkType { get; private set; } 659 660 /// <summary> 661 /// The token associated with the current node's task 662 /// </summary> 663 public CancellationToken CancellationToken { get; set; } 664 665 /// <summary> 666 /// Every node has a cancellation source - its token participate in the task creation 667 /// </summary> 668 public CancellationTokenSource CancellationTokenSource { get; set; } 669 670 /// <summary> 671 /// While a tasks is correct execute a result is produced 672 /// this is the result 673 /// </summary> 674 public double Result { get; private set; } 675 676 #endregion 677 678 #region Helper Methods 679 680 /// <summary> 681 /// The Task workload execution 682 /// </summary> RunWorkload()683 public void RunWorkload() 684 { 685 //Thread = Thread.CurrentThread; 686 687 if (WorkType == WorkloadType.Exceptional) 688 { 689 ThrowException(); 690 } 691 else if (WorkType == WorkloadType.Cancelled) 692 { 693 CancelSelf(this.CancellationTokenSource, this.CancellationToken); 694 } 695 else 696 { 697 // run the workload 698 if (Result == s_UNINITIALED_RESULT) 699 { 700 Result = ZetaSequence((int)WorkType); 701 } 702 else // task re-entry, mark it failed 703 { 704 Result = s_UNINITIALED_RESULT; 705 } 706 } 707 } 708 ZetaSequence(int n)709 public static double ZetaSequence(int n) 710 { 711 double result = 0; 712 for (int i = 1; i < n; i++) 713 { 714 result += 1.0 / ((double)i * (double)i); 715 } 716 717 return result; 718 } 719 720 /// <summary> 721 /// Cancel self workload. The CancellationToken has been wired such that the source passed to this method 722 /// is a source that can actually causes the Task CancellationToken to be canceled. The source could be the 723 /// Token's original source, or one of the sources in case of Linked Tokens 724 /// </summary> 725 /// <param name="cts"></param> CancelSelf(CancellationTokenSource cts, CancellationToken ct)726 public static void CancelSelf(CancellationTokenSource cts, CancellationToken ct) 727 { 728 cts.Cancel(); 729 throw new OperationCanceledException(ct); 730 } 731 ThrowException()732 public static void ThrowException() 733 { 734 throw new TPLTestException(); 735 } 736 737 #endregion 738 } 739 740 public enum API 741 { 742 ContinueWhenAll, 743 ContinueWhenAny, 744 } 745 746 /// <summary> 747 /// Every task has an workload associated 748 /// These are the workload types used in the task tree 749 /// The workload is not common for the whole tree - Every node can have its own workload 750 /// </summary> 751 public enum WorkloadType 752 { 753 Exceptional = -2, 754 Cancelled = -1, 755 VeryLight = 100, // the number is the N input to the ZetaSequence workload 756 Light = 200, 757 Medium = 400, 758 Heavy = 800, 759 VeryHeavy = 1600, 760 } 761 762 /// <summary> 763 /// TaskType argument tells us what the type of all the antecedent tasks is, and what the type of the continuation task is. 764 /// The TaskTypeOption that ends with “NEW” additionally specifies that the ContinueWhen overload to be used is one that 765 /// has two type arguments (TAntecedentResult, TResult). 766 /// </summary> 767 public enum TaskType 768 { 769 TaskContinueWithTask, // test Task.Factory.ContinueWhenAll/Any(..., Action,...) 770 TaskContinueWithTaskT, // test Task<T>.Factory.ContinueWhenAll/Any(..., Func<>,...) 771 TaskContinueWithTaskT_NEW, // test new overload of Task.Factory.ContinueWhenAll/Any<TNEW>(..., Func<>,...) 772 TaskTContinueWithTask, // test Task.Factory.Factory.ContinueWhenAll/Any<T>(..., Action,...) 773 TaskTContinueWithTaskT, // test Task<T>.Factory.Factory.ContinueWhenAll/Any<T>(..., Func<>,...) 774 TaskTContinueWithTaskT_NEW, // test new overload of Task.Factory.Factory.ContinueWhenAll/Any<T1, T2>(..., Func<>,...) 775 } 776 777 #endregion 778 779 public sealed class TaskContinueWithAllAnyTests 780 { 781 [Fact] TaskContinueWithAllAnyTest0()782 public static void TaskContinueWithAllAnyTest0() 783 { 784 TaskInfo node1 = new TaskInfo(WorkloadType.Medium); 785 TaskInfo[] allTasks = new[] { node1, }; 786 TestParameters parameters = new TestParameters(API.ContinueWhenAll, TaskType.TaskContinueWithTaskT, TaskContinuationOptions.ExecuteSynchronously, false, allTasks); 787 788 TaskContinueWithAllAnyTest test = new TaskContinueWithAllAnyTest(parameters); 789 test.RealRun(); 790 } 791 792 [Fact] TaskContinueWithAllAnyTest1()793 public static void TaskContinueWithAllAnyTest1() 794 { 795 TaskInfo node1 = new TaskInfo(WorkloadType.Exceptional); 796 TaskInfo node2 = new TaskInfo(WorkloadType.Medium); 797 TaskInfo node3 = new TaskInfo(WorkloadType.Light); 798 TaskInfo[] allTasks = new[] { node1, node2, node3, }; 799 TestParameters parameters = new TestParameters(API.ContinueWhenAll, TaskType.TaskContinueWithTaskT, TaskContinuationOptions.None, false, allTasks); 800 801 TaskContinueWithAllAnyTest test = new TaskContinueWithAllAnyTest(parameters); 802 test.RealRun(); 803 } 804 805 [Fact] 806 [OuterLoop] TaskContinueWithAllAnyTest2()807 public static void TaskContinueWithAllAnyTest2() 808 { 809 TaskInfo node1 = new TaskInfo(WorkloadType.Light); 810 TaskInfo node2 = new TaskInfo(WorkloadType.Heavy); 811 TaskInfo node3 = new TaskInfo(WorkloadType.Cancelled); 812 TaskInfo node4 = new TaskInfo(WorkloadType.VeryHeavy); 813 TaskInfo node5 = new TaskInfo(WorkloadType.VeryLight); 814 TaskInfo[] allTasks = new[] { node1, node2, node3, node4, node5, }; 815 TestParameters parameters = new TestParameters(API.ContinueWhenAll, TaskType.TaskContinueWithTaskT, TaskContinuationOptions.PreferFairness, false, allTasks); 816 817 TaskContinueWithAllAnyTest test = new TaskContinueWithAllAnyTest(parameters); 818 test.RealRun(); 819 } 820 821 [Fact] 822 [OuterLoop] TaskContinueWithAllAnyTest3()823 public static void TaskContinueWithAllAnyTest3() 824 { 825 TaskInfo node1 = new TaskInfo(WorkloadType.Heavy); 826 TaskInfo node2 = new TaskInfo(WorkloadType.Cancelled); 827 TaskInfo node3 = new TaskInfo(WorkloadType.Light); 828 TaskInfo[] allTasks = new[] { node1, node2, node3, }; 829 TestParameters parameters = new TestParameters(API.ContinueWhenAny, TaskType.TaskContinueWithTaskT, TaskContinuationOptions.AttachedToParent, false, allTasks); 830 831 TaskContinueWithAllAnyTest test = new TaskContinueWithAllAnyTest(parameters); 832 test.RealRun(); 833 } 834 835 [Fact] TaskContinueWithAllAnyTest4()836 public static void TaskContinueWithAllAnyTest4() 837 { 838 TaskInfo node1 = new TaskInfo(WorkloadType.Exceptional); 839 TaskInfo[] allTasks = new[] { node1, }; 840 TestParameters parameters = new TestParameters(API.ContinueWhenAny, TaskType.TaskContinueWithTaskT, TaskContinuationOptions.LongRunning, false, allTasks); 841 842 TaskContinueWithAllAnyTest test = new TaskContinueWithAllAnyTest(parameters); 843 test.RealRun(); 844 } 845 846 [Fact] 847 [OuterLoop] TaskContinueWithAllAnyTest5()848 public static void TaskContinueWithAllAnyTest5() 849 { 850 TaskInfo node1 = new TaskInfo(WorkloadType.VeryHeavy); 851 TaskInfo node2 = new TaskInfo(WorkloadType.Medium); 852 TaskInfo node3 = new TaskInfo(WorkloadType.VeryLight); 853 TaskInfo[] allTasks = new[] { node1, node2, node3, }; 854 TestParameters parameters = new TestParameters(API.ContinueWhenAll, TaskType.TaskContinueWithTaskT_NEW, TaskContinuationOptions.AttachedToParent, false, allTasks); 855 856 TaskContinueWithAllAnyTest test = new TaskContinueWithAllAnyTest(parameters); 857 test.RealRun(); 858 } 859 860 [Fact] TaskContinueWithAllAnyTest6()861 public static void TaskContinueWithAllAnyTest6() 862 { 863 TaskInfo node1 = new TaskInfo(WorkloadType.Medium); 864 TaskInfo node2 = new TaskInfo(WorkloadType.Cancelled); 865 TaskInfo node3 = new TaskInfo(WorkloadType.Cancelled); 866 TaskInfo node4 = new TaskInfo(WorkloadType.Exceptional); 867 TaskInfo node5 = new TaskInfo(WorkloadType.Exceptional); 868 TaskInfo[] allTasks = new[] { node1, node2, node3, node4, node5, }; 869 TestParameters parameters = new TestParameters(API.ContinueWhenAll, TaskType.TaskContinueWithTaskT_NEW, TaskContinuationOptions.ExecuteSynchronously, false, allTasks); 870 871 TaskContinueWithAllAnyTest test = new TaskContinueWithAllAnyTest(parameters); 872 test.RealRun(); 873 } 874 875 [Fact] 876 [OuterLoop] TaskContinueWithAllAnyTest7()877 public static void TaskContinueWithAllAnyTest7() 878 { 879 TaskInfo node1 = new TaskInfo(WorkloadType.VeryHeavy); 880 TaskInfo node2 = new TaskInfo(WorkloadType.VeryLight); 881 TaskInfo node3 = new TaskInfo(WorkloadType.Cancelled); 882 TaskInfo node4 = new TaskInfo(WorkloadType.VeryHeavy); 883 TaskInfo node5 = new TaskInfo(WorkloadType.VeryLight); 884 TaskInfo[] allTasks = new[] { node1, node2, node3, node4, node5, }; 885 TestParameters parameters = new TestParameters(API.ContinueWhenAll, TaskType.TaskContinueWithTaskT_NEW, TaskContinuationOptions.None, false, allTasks); 886 887 TaskContinueWithAllAnyTest test = new TaskContinueWithAllAnyTest(parameters); 888 test.RealRun(); 889 } 890 891 [Fact] TaskContinueWithAllAnyTest8()892 public static void TaskContinueWithAllAnyTest8() 893 { 894 TaskInfo node1 = new TaskInfo(WorkloadType.Cancelled); 895 TaskInfo[] allTasks = new[] { node1, }; 896 TestParameters parameters = new TestParameters(API.ContinueWhenAny, TaskType.TaskContinueWithTaskT_NEW, TaskContinuationOptions.LongRunning, false, allTasks); 897 898 TaskContinueWithAllAnyTest test = new TaskContinueWithAllAnyTest(parameters); 899 test.RealRun(); 900 } 901 902 [Fact] 903 [OuterLoop] TaskContinueWithAllAnyTest9()904 public static void TaskContinueWithAllAnyTest9() 905 { 906 TaskInfo node1 = new TaskInfo(WorkloadType.VeryHeavy); 907 TaskInfo node2 = new TaskInfo(WorkloadType.Cancelled); 908 TaskInfo node3 = new TaskInfo(WorkloadType.VeryLight); 909 TaskInfo[] allTasks = new[] { node1, node2, node3, }; 910 TestParameters parameters = new TestParameters(API.ContinueWhenAll, TaskType.TaskContinueWithTask, TaskContinuationOptions.PreferFairness, false, allTasks); 911 912 TaskContinueWithAllAnyTest test = new TaskContinueWithAllAnyTest(parameters); 913 test.RealRun(); 914 } 915 916 [Fact] 917 [OuterLoop] TaskContinueWithAllAnyTest10()918 public static void TaskContinueWithAllAnyTest10() 919 { 920 TaskInfo node1 = new TaskInfo(WorkloadType.VeryHeavy); 921 TaskInfo node2 = new TaskInfo(WorkloadType.Cancelled); 922 TaskInfo node3 = new TaskInfo(WorkloadType.VeryLight); 923 TaskInfo node4 = new TaskInfo(WorkloadType.Exceptional); 924 TaskInfo node5 = new TaskInfo(WorkloadType.Medium); 925 TaskInfo[] allTasks = new[] { node1, node2, node3, node4, node5, }; 926 TestParameters parameters = new TestParameters(API.ContinueWhenAll, TaskType.TaskContinueWithTask, TaskContinuationOptions.AttachedToParent, false, allTasks); 927 928 TaskContinueWithAllAnyTest test = new TaskContinueWithAllAnyTest(parameters); 929 test.RealRun(); 930 } 931 932 [Fact] 933 [OuterLoop] TaskContinueWithAllAnyTest11()934 public static void TaskContinueWithAllAnyTest11() 935 { 936 TaskInfo node1 = new TaskInfo(WorkloadType.Exceptional); 937 TaskInfo node2 = new TaskInfo(WorkloadType.VeryHeavy); 938 TaskInfo node3 = new TaskInfo(WorkloadType.VeryLight); 939 TaskInfo node4 = new TaskInfo(WorkloadType.Cancelled); 940 TaskInfo node5 = new TaskInfo(WorkloadType.VeryHeavy); 941 TaskInfo node6 = new TaskInfo(WorkloadType.VeryLight); 942 TaskInfo[] allTasks = new[] { node1, node2, node3, node4, node5, node6, }; 943 TestParameters parameters = new TestParameters(API.ContinueWhenAll, TaskType.TaskContinueWithTask, TaskContinuationOptions.PreferFairness, false, allTasks); 944 945 TaskContinueWithAllAnyTest test = new TaskContinueWithAllAnyTest(parameters); 946 test.RealRun(); 947 } 948 949 [Fact] TaskContinueWithAllAnyTest12()950 public static void TaskContinueWithAllAnyTest12() 951 { 952 TaskInfo node1 = new TaskInfo(WorkloadType.Medium); 953 TaskInfo[] allTasks = new[] { node1, }; 954 TestParameters parameters = new TestParameters(API.ContinueWhenAny, TaskType.TaskContinueWithTask, TaskContinuationOptions.ExecuteSynchronously, false, allTasks); 955 956 TaskContinueWithAllAnyTest test = new TaskContinueWithAllAnyTest(parameters); 957 test.RealRun(); 958 } 959 [Fact] TaskContinueWithAllAnyTest13()960 public static void TaskContinueWithAllAnyTest13() 961 { 962 TaskInfo node1 = new TaskInfo(WorkloadType.Exceptional); 963 TaskInfo node2 = new TaskInfo(WorkloadType.Medium); 964 TaskInfo node3 = new TaskInfo(WorkloadType.Light); 965 TaskInfo[] allTasks = new[] { node1, node2, node3, }; 966 TestParameters parameters = new TestParameters(API.ContinueWhenAny, TaskType.TaskContinueWithTask, TaskContinuationOptions.LongRunning, false, allTasks); 967 968 TaskContinueWithAllAnyTest test = new TaskContinueWithAllAnyTest(parameters); 969 test.RealRun(); 970 } 971 972 [Fact] 973 [OuterLoop] TaskContinueWithAllAnyTest14()974 public static void TaskContinueWithAllAnyTest14() 975 { 976 TaskInfo node1 = new TaskInfo(WorkloadType.Light); 977 TaskInfo node2 = new TaskInfo(WorkloadType.Heavy); 978 TaskInfo node3 = new TaskInfo(WorkloadType.Cancelled); 979 TaskInfo node4 = new TaskInfo(WorkloadType.VeryHeavy); 980 TaskInfo node5 = new TaskInfo(WorkloadType.VeryLight); 981 TaskInfo[] allTasks = new[] { node1, node2, node3, node4, node5, }; 982 TestParameters parameters = new TestParameters(API.ContinueWhenAny, TaskType.TaskContinueWithTask, TaskContinuationOptions.None, false, allTasks); 983 984 TaskContinueWithAllAnyTest test = new TaskContinueWithAllAnyTest(parameters); 985 test.RealRun(); 986 } 987 988 [Fact] TaskContinueWithAllAnyTest15()989 public static void TaskContinueWithAllAnyTest15() 990 { 991 TaskInfo node1 = new TaskInfo(WorkloadType.Medium); 992 TaskInfo node2 = new TaskInfo(WorkloadType.Medium); 993 TaskInfo[] allTasks = new[] { node1, node2, }; 994 TestParameters parameters = new TestParameters(API.ContinueWhenAll, TaskType.TaskTContinueWithTaskT, TaskContinuationOptions.AttachedToParent, false, allTasks); 995 996 TaskContinueWithAllAnyTest test = new TaskContinueWithAllAnyTest(parameters); 997 test.RealRun(); 998 } 999 1000 [Fact] TaskContinueWithAllAnyTest16()1001 public static void TaskContinueWithAllAnyTest16() 1002 { 1003 TaskInfo node1 = new TaskInfo(WorkloadType.Exceptional); 1004 TaskInfo[] allTasks = new[] { node1, }; 1005 TestParameters parameters = new TestParameters(API.ContinueWhenAll, TaskType.TaskTContinueWithTaskT, TaskContinuationOptions.ExecuteSynchronously, false, allTasks); 1006 1007 TaskContinueWithAllAnyTest test = new TaskContinueWithAllAnyTest(parameters); 1008 test.RealRun(); 1009 } 1010 1011 1012 [Fact] 1013 [OuterLoop] TaskContinueWithAllAnyTest17()1014 public static void TaskContinueWithAllAnyTest17() 1015 { 1016 TaskInfo node1 = new TaskInfo(WorkloadType.VeryHeavy); 1017 TaskInfo node2 = new TaskInfo(WorkloadType.Medium); 1018 TaskInfo node3 = new TaskInfo(WorkloadType.VeryLight); 1019 TaskInfo[] allTasks = new[] { node1, node2, node3, }; 1020 TestParameters parameters = new TestParameters(API.ContinueWhenAll, TaskType.TaskTContinueWithTaskT, TaskContinuationOptions.LongRunning, false, allTasks); 1021 1022 TaskContinueWithAllAnyTest test = new TaskContinueWithAllAnyTest(parameters); 1023 test.RealRun(); 1024 } 1025 1026 [Fact] TaskContinueWithAllAnyTest18()1027 public static void TaskContinueWithAllAnyTest18() 1028 { 1029 TaskInfo node1 = new TaskInfo(WorkloadType.Medium); 1030 TaskInfo node2 = new TaskInfo(WorkloadType.Cancelled); 1031 TaskInfo node3 = new TaskInfo(WorkloadType.Cancelled); 1032 TaskInfo node4 = new TaskInfo(WorkloadType.Exceptional); 1033 TaskInfo node5 = new TaskInfo(WorkloadType.Exceptional); 1034 TaskInfo[] allTasks = new[] { node1, node2, node3, node4, node5, }; 1035 TestParameters parameters = new TestParameters(API.ContinueWhenAny, TaskType.TaskTContinueWithTaskT, TaskContinuationOptions.None, false, allTasks); 1036 1037 TaskContinueWithAllAnyTest test = new TaskContinueWithAllAnyTest(parameters); 1038 test.RealRun(); 1039 } 1040 1041 [Fact] TaskContinueWithAllAnyTest19()1042 public static void TaskContinueWithAllAnyTest19() 1043 { 1044 TaskInfo node1 = new TaskInfo(WorkloadType.VeryLight); 1045 TaskInfo node2 = new TaskInfo(WorkloadType.Medium); 1046 TaskInfo node3 = new TaskInfo(WorkloadType.VeryLight); 1047 TaskInfo[] allTasks = new[] { node1, node2, node3, }; 1048 TestParameters parameters = new TestParameters(API.ContinueWhenAny, TaskType.TaskTContinueWithTaskT, TaskContinuationOptions.PreferFairness, false, allTasks); 1049 1050 TaskContinueWithAllAnyTest test = new TaskContinueWithAllAnyTest(parameters); 1051 test.RealRun(); 1052 } 1053 1054 [Fact] TaskContinueWithAllAnyTest20()1055 public static void TaskContinueWithAllAnyTest20() 1056 { 1057 TaskInfo node1 = new TaskInfo(WorkloadType.Medium); 1058 TaskInfo[] allTasks = new[] { node1, }; 1059 TestParameters parameters = new TestParameters(API.ContinueWhenAll, TaskType.TaskTContinueWithTaskT_NEW, TaskContinuationOptions.ExecuteSynchronously, false, allTasks); 1060 1061 TaskContinueWithAllAnyTest test = new TaskContinueWithAllAnyTest(parameters); 1062 test.RealRun(); 1063 } 1064 1065 [Fact] TaskContinueWithAllAnyTest21()1066 public static void TaskContinueWithAllAnyTest21() 1067 { 1068 TaskInfo node1 = new TaskInfo(WorkloadType.Cancelled); 1069 TaskInfo[] allTasks = new[] { node1, }; 1070 TestParameters parameters = new TestParameters(API.ContinueWhenAll, TaskType.TaskTContinueWithTaskT_NEW, TaskContinuationOptions.LongRunning, false, allTasks); 1071 1072 TaskContinueWithAllAnyTest test = new TaskContinueWithAllAnyTest(parameters); 1073 test.RealRun(); 1074 } 1075 1076 [Fact] 1077 [OuterLoop] TaskContinueWithAllAnyTest22()1078 public static void TaskContinueWithAllAnyTest22() 1079 { 1080 TaskInfo node1 = new TaskInfo(WorkloadType.VeryHeavy); 1081 TaskInfo node2 = new TaskInfo(WorkloadType.Cancelled); 1082 TaskInfo node3 = new TaskInfo(WorkloadType.VeryLight); 1083 TaskInfo[] allTasks = new[] { node1, node2, node3, }; 1084 TestParameters parameters = new TestParameters(API.ContinueWhenAll, TaskType.TaskTContinueWithTaskT_NEW, TaskContinuationOptions.None, false, allTasks); 1085 1086 TaskContinueWithAllAnyTest test = new TaskContinueWithAllAnyTest(parameters); 1087 test.RealRun(); 1088 } 1089 1090 [Fact] TaskContinueWithAllAnyTest23()1091 public static void TaskContinueWithAllAnyTest23() 1092 { 1093 TaskInfo node1 = new TaskInfo(WorkloadType.VeryLight); 1094 TaskInfo node2 = new TaskInfo(WorkloadType.Medium); 1095 TaskInfo node3 = new TaskInfo(WorkloadType.Light); 1096 TaskInfo[] allTasks = new[] { node1, node2, node3, }; 1097 TestParameters parameters = new TestParameters(API.ContinueWhenAll, TaskType.TaskTContinueWithTaskT_NEW, TaskContinuationOptions.PreferFairness, false, allTasks); 1098 1099 TaskContinueWithAllAnyTest test = new TaskContinueWithAllAnyTest(parameters); 1100 test.RealRun(); 1101 } 1102 1103 [Fact] 1104 [OuterLoop] TaskContinueWithAllAnyTest24()1105 public static void TaskContinueWithAllAnyTest24() 1106 { 1107 TaskInfo node1 = new TaskInfo(WorkloadType.VeryHeavy); 1108 TaskInfo node2 = new TaskInfo(WorkloadType.Cancelled); 1109 TaskInfo node3 = new TaskInfo(WorkloadType.VeryLight); 1110 TaskInfo node4 = new TaskInfo(WorkloadType.Exceptional); 1111 TaskInfo node5 = new TaskInfo(WorkloadType.Medium); 1112 TaskInfo[] allTasks = new[] { node1, node2, node3, node4, node5, }; 1113 TestParameters parameters = new TestParameters(API.ContinueWhenAny, TaskType.TaskTContinueWithTaskT_NEW, TaskContinuationOptions.AttachedToParent, false, allTasks); 1114 1115 TaskContinueWithAllAnyTest test = new TaskContinueWithAllAnyTest(parameters); 1116 test.RealRun(); 1117 } 1118 1119 [Fact] TaskContinueWithAllAnyTest25()1120 public static void TaskContinueWithAllAnyTest25() 1121 { 1122 TaskInfo node1 = new TaskInfo(WorkloadType.Medium); 1123 TaskInfo[] allTasks = new[] { node1, }; 1124 TestParameters parameters = new TestParameters(API.ContinueWhenAll, TaskType.TaskTContinueWithTask, TaskContinuationOptions.AttachedToParent, false, allTasks); 1125 1126 TaskContinueWithAllAnyTest test = new TaskContinueWithAllAnyTest(parameters); 1127 test.RealRun(); 1128 } 1129 1130 [Fact] 1131 [OuterLoop] TaskContinueWithAllAnyTest26()1132 public static void TaskContinueWithAllAnyTest26() 1133 { 1134 TaskInfo node1 = new TaskInfo(WorkloadType.VeryHeavy); 1135 TaskInfo node2 = new TaskInfo(WorkloadType.Cancelled); 1136 TaskInfo node3 = new TaskInfo(WorkloadType.VeryLight); 1137 TaskInfo node4 = new TaskInfo(WorkloadType.Exceptional); 1138 TaskInfo node5 = new TaskInfo(WorkloadType.Medium); 1139 TaskInfo node6 = new TaskInfo(WorkloadType.VeryHeavy); 1140 TaskInfo node7 = new TaskInfo(WorkloadType.Cancelled); 1141 TaskInfo node8 = new TaskInfo(WorkloadType.VeryLight); 1142 TaskInfo node9 = new TaskInfo(WorkloadType.Exceptional); 1143 TaskInfo node10 = new TaskInfo(WorkloadType.Medium); 1144 TaskInfo[] allTasks = new[] { node1, node2, node3, node4, node5, node6, node7, node8, node9, node10, }; 1145 TestParameters parameters = new TestParameters(API.ContinueWhenAll, TaskType.TaskTContinueWithTask, TaskContinuationOptions.LongRunning, false, allTasks); 1146 1147 TaskContinueWithAllAnyTest test = new TaskContinueWithAllAnyTest(parameters); 1148 test.RealRun(); 1149 } 1150 1151 [Fact] TaskContinueWithAllAnyTest27()1152 public static void TaskContinueWithAllAnyTest27() 1153 { 1154 TaskInfo node1 = new TaskInfo(WorkloadType.Exceptional); 1155 TaskInfo node2 = new TaskInfo(WorkloadType.Medium); 1156 TaskInfo node3 = new TaskInfo(WorkloadType.Light); 1157 TaskInfo node4 = new TaskInfo(WorkloadType.Cancelled); 1158 TaskInfo node5 = new TaskInfo(WorkloadType.VeryLight); 1159 TaskInfo node6 = new TaskInfo(WorkloadType.Exceptional); 1160 TaskInfo node7 = new TaskInfo(WorkloadType.Medium); 1161 TaskInfo[] allTasks = new[] { node1, node2, node3, node4, node5, node6, node7, }; 1162 TestParameters parameters = new TestParameters(API.ContinueWhenAll, TaskType.TaskTContinueWithTask, TaskContinuationOptions.None, false, allTasks); 1163 1164 TaskContinueWithAllAnyTest test = new TaskContinueWithAllAnyTest(parameters); 1165 test.RealRun(); 1166 } 1167 1168 [Fact] 1169 [OuterLoop] TaskContinueWithAllAnyTest28()1170 public static void TaskContinueWithAllAnyTest28() 1171 { 1172 TaskInfo node1 = new TaskInfo(WorkloadType.VeryHeavy); 1173 TaskInfo node2 = new TaskInfo(WorkloadType.Cancelled); 1174 TaskInfo node3 = new TaskInfo(WorkloadType.VeryLight); 1175 TaskInfo node4 = new TaskInfo(WorkloadType.Exceptional); 1176 TaskInfo node5 = new TaskInfo(WorkloadType.Medium); 1177 TaskInfo node6 = new TaskInfo(WorkloadType.VeryHeavy); 1178 TaskInfo node7 = new TaskInfo(WorkloadType.Cancelled); 1179 TaskInfo node8 = new TaskInfo(WorkloadType.VeryLight); 1180 TaskInfo node9 = new TaskInfo(WorkloadType.Exceptional); 1181 TaskInfo node10 = new TaskInfo(WorkloadType.Medium); 1182 TaskInfo[] allTasks = new[] { node1, node2, node3, node4, node5, node6, node7, node8, node9, node10, }; 1183 TestParameters parameters = new TestParameters(API.ContinueWhenAny, TaskType.TaskTContinueWithTask, TaskContinuationOptions.ExecuteSynchronously, false, allTasks); 1184 1185 TaskContinueWithAllAnyTest test = new TaskContinueWithAllAnyTest(parameters); 1186 test.RealRun(); 1187 } 1188 1189 [Fact] 1190 [OuterLoop] TaskContinueWithAllAnyTest29()1191 public static void TaskContinueWithAllAnyTest29() 1192 { 1193 TaskInfo node1 = new TaskInfo(WorkloadType.VeryHeavy); 1194 TaskInfo node2 = new TaskInfo(WorkloadType.Cancelled); 1195 TaskInfo node3 = new TaskInfo(WorkloadType.VeryLight); 1196 TaskInfo node4 = new TaskInfo(WorkloadType.Exceptional); 1197 TaskInfo node5 = new TaskInfo(WorkloadType.Medium); 1198 TaskInfo node6 = new TaskInfo(WorkloadType.VeryHeavy); 1199 TaskInfo node7 = new TaskInfo(WorkloadType.Cancelled); 1200 TaskInfo node8 = new TaskInfo(WorkloadType.VeryLight); 1201 TaskInfo node9 = new TaskInfo(WorkloadType.Exceptional); 1202 TaskInfo node10 = new TaskInfo(WorkloadType.Medium); 1203 TaskInfo[] allTasks = new[] { node1, node2, node3, node4, node5, node6, node7, node8, node9, node10, }; 1204 TestParameters parameters = new TestParameters(API.ContinueWhenAny, TaskType.TaskTContinueWithTask, TaskContinuationOptions.PreferFairness, false, allTasks); 1205 1206 TaskContinueWithAllAnyTest test = new TaskContinueWithAllAnyTest(parameters); 1207 test.RealRun(); 1208 } 1209 1210 [Fact] 1211 [OuterLoop] TaskContinueWithAllAnyTest30()1212 public static void TaskContinueWithAllAnyTest30() 1213 { 1214 TaskInfo node1 = new TaskInfo(WorkloadType.VeryHeavy); 1215 TaskInfo node2 = new TaskInfo(WorkloadType.Cancelled); 1216 TaskInfo node3 = new TaskInfo(WorkloadType.VeryLight); 1217 TaskInfo node4 = new TaskInfo(WorkloadType.Exceptional); 1218 TaskInfo node5 = new TaskInfo(WorkloadType.Medium); 1219 TaskInfo node6 = new TaskInfo(WorkloadType.VeryHeavy); 1220 TaskInfo node7 = new TaskInfo(WorkloadType.Cancelled); 1221 TaskInfo node8 = new TaskInfo(WorkloadType.VeryLight); 1222 TaskInfo node9 = new TaskInfo(WorkloadType.Exceptional); 1223 TaskInfo node10 = new TaskInfo(WorkloadType.Medium); 1224 TaskInfo[] allTasks = new[] { node1, node2, node3, node4, node5, node6, node7, node8, node9, node10, }; 1225 TestParameters parameters = new TestParameters(API.ContinueWhenAll, TaskType.TaskContinueWithTaskT_NEW, TaskContinuationOptions.None, true, allTasks); 1226 1227 TaskContinueWithAllAnyTest test = new TaskContinueWithAllAnyTest(parameters); 1228 test.RealRun(); 1229 } 1230 [Fact] TaskContinueWithAllAnyTest31()1231 public static void TaskContinueWithAllAnyTest31() 1232 { 1233 TaskInfo node1 = new TaskInfo(WorkloadType.Exceptional); 1234 TaskInfo node2 = new TaskInfo(WorkloadType.Cancelled); 1235 TaskInfo node3 = new TaskInfo(WorkloadType.VeryLight); 1236 TaskInfo[] allTasks = new[] { node1, node2, node3, }; 1237 TestParameters parameters = new TestParameters(API.ContinueWhenAny, TaskType.TaskContinueWithTaskT_NEW, TaskContinuationOptions.None, true, allTasks); 1238 1239 TaskContinueWithAllAnyTest test = new TaskContinueWithAllAnyTest(parameters); 1240 test.RealRun(); 1241 } 1242 [Fact] TaskContinueWithAllAnyTest32()1243 public static void TaskContinueWithAllAnyTest32() 1244 { 1245 TaskInfo node1 = new TaskInfo(WorkloadType.Exceptional); 1246 TaskInfo node2 = new TaskInfo(WorkloadType.Cancelled); 1247 TaskInfo node3 = new TaskInfo(WorkloadType.VeryLight); 1248 TaskInfo[] allTasks = new[] { node1, node2, node3, }; 1249 TestParameters parameters = new TestParameters(API.ContinueWhenAll, TaskType.TaskTContinueWithTaskT_NEW, TaskContinuationOptions.None, true, allTasks); 1250 1251 TaskContinueWithAllAnyTest test = new TaskContinueWithAllAnyTest(parameters); 1252 test.RealRun(); 1253 } 1254 [Fact] TaskContinueWithAllAnyTest33()1255 public static void TaskContinueWithAllAnyTest33() 1256 { 1257 TaskInfo node1 = new TaskInfo(WorkloadType.Exceptional); 1258 TaskInfo node2 = new TaskInfo(WorkloadType.Cancelled); 1259 TaskInfo node3 = new TaskInfo(WorkloadType.VeryLight); 1260 TaskInfo[] allTasks = new[] { node1, node2, node3, }; 1261 TestParameters parameters = new TestParameters(API.ContinueWhenAny, TaskType.TaskTContinueWithTaskT_NEW, TaskContinuationOptions.None, true, allTasks); 1262 1263 TaskContinueWithAllAnyTest test = new TaskContinueWithAllAnyTest(parameters); 1264 test.RealRun(); 1265 } 1266 [Fact] TaskContinueWithAllAnyTest34()1267 public static void TaskContinueWithAllAnyTest34() 1268 { 1269 TaskInfo node1 = new TaskInfo(WorkloadType.Cancelled); 1270 TaskInfo node2 = new TaskInfo(WorkloadType.VeryLight); 1271 TaskInfo[] allTasks = new[] { node1, node2, }; 1272 TestParameters parameters = new TestParameters(API.ContinueWhenAny, TaskType.TaskTContinueWithTaskT_NEW, TaskContinuationOptions.LazyCancellation, true, allTasks); 1273 1274 TaskContinueWithAllAnyTest test = new TaskContinueWithAllAnyTest(parameters); 1275 test.RealRun(); 1276 } 1277 [Fact] TaskContinueWithAllAnyTest35()1278 public static void TaskContinueWithAllAnyTest35() 1279 { 1280 TaskInfo node1 = new TaskInfo(WorkloadType.Exceptional); 1281 TaskInfo node2 = new TaskInfo(WorkloadType.VeryLight); 1282 TaskInfo[] allTasks = new[] { node1, node2, }; 1283 TestParameters parameters = new TestParameters(API.ContinueWhenAll, TaskType.TaskContinueWithTask, TaskContinuationOptions.LazyCancellation, true, allTasks); 1284 1285 TaskContinueWithAllAnyTest test = new TaskContinueWithAllAnyTest(parameters); 1286 test.RealRun(); 1287 } 1288 [Fact] TaskContinueWithAllAnyTest36()1289 public static void TaskContinueWithAllAnyTest36() 1290 { 1291 TaskInfo node1 = new TaskInfo(WorkloadType.Exceptional); 1292 TaskInfo node2 = new TaskInfo(WorkloadType.Cancelled); 1293 TaskInfo node3 = new TaskInfo(WorkloadType.VeryLight); 1294 TaskInfo[] allTasks = new[] { node1, node2, node3, }; 1295 TestParameters parameters = new TestParameters(API.ContinueWhenAny, TaskType.TaskContinueWithTaskT, TaskContinuationOptions.LazyCancellation, false, allTasks); 1296 1297 TaskContinueWithAllAnyTest test = new TaskContinueWithAllAnyTest(parameters); 1298 test.RealRun(); 1299 } 1300 1301 [Fact] TaskContinueWithAllAnyTest37()1302 public static void TaskContinueWithAllAnyTest37() 1303 { 1304 TaskInfo node1 = new TaskInfo(WorkloadType.Exceptional); 1305 TaskInfo node2 = new TaskInfo(WorkloadType.Cancelled); 1306 TaskInfo node3 = new TaskInfo(WorkloadType.VeryLight); 1307 TaskInfo[] allTasks = new[] { node1, node2, node3, }; 1308 TestParameters parameters = new TestParameters(API.ContinueWhenAll, TaskType.TaskTContinueWithTask, TaskContinuationOptions.LazyCancellation, false, allTasks); 1309 1310 TaskContinueWithAllAnyTest test = new TaskContinueWithAllAnyTest(parameters); 1311 test.RealRun(); 1312 } 1313 1314 [Fact] 1315 [OuterLoop] TaskContinueWithAllAnyTest38()1316 public static void TaskContinueWithAllAnyTest38() 1317 { 1318 TaskInfo node1 = new TaskInfo(WorkloadType.VeryHeavy); 1319 TaskInfo node2 = new TaskInfo(WorkloadType.VeryLight); 1320 TaskInfo[] allTasks = new[] { node1, node2, }; 1321 TestParameters parameters = new TestParameters(API.ContinueWhenAny, TaskType.TaskTContinueWithTaskT, TaskContinuationOptions.LazyCancellation, true, allTasks); 1322 1323 TaskContinueWithAllAnyTest test = new TaskContinueWithAllAnyTest(parameters); 1324 test.RealRun(); 1325 } 1326 1327 [Fact] 1328 [OuterLoop] TaskContinueWithAllAnyTest39()1329 public static void TaskContinueWithAllAnyTest39() 1330 { 1331 TaskInfo node1 = new TaskInfo(WorkloadType.VeryHeavy); 1332 TaskInfo node2 = new TaskInfo(WorkloadType.VeryLight); 1333 TaskInfo[] allTasks = new[] { node1, node2, }; 1334 TestParameters parameters = new TestParameters(API.ContinueWhenAll, TaskType.TaskTContinueWithTaskT_NEW, TaskContinuationOptions.LazyCancellation, true, allTasks); 1335 1336 TaskContinueWithAllAnyTest test = new TaskContinueWithAllAnyTest(parameters); 1337 test.RealRun(); 1338 } 1339 } 1340 } 1341