[Property("CRITERIA", "MR")]
[Property("COVPARAM", "string, CancellationToken")]
[Property("AUTHOR", "JungHo Kim, jhyo.kim@samsung.com")]
- public void CreateThumbnailAsync_WITH_CANCELLATION_CANCEL()
+ public async Task CreateThumbnailAsync_WITH_CANCELLATION_CANCEL()
{
- cts = new CancellationTokenSource();
- var task = _cmd.CreateThumbnailAsync(_cmd.Add(TestConstants.ImageFile).Id, cts.Token);
+ const int numberOfTasks = 20;
- cts.Cancel();
+ var taskArray = new Task<Task<string>>[numberOfTasks];
+ var ctsArray = new CancellationTokenSource[numberOfTasks];
+
+ for (int i = 0 ; i < numberOfTasks ; i++)
+ {
+ ctsArray[i] = new CancellationTokenSource();
+ }
+
+ Func<object, Task<string>> action = (object i) =>
+ _cmd.CreateThumbnailAsync(_cmd.Add(TestConstants.ImageFile).Id, ctsArray[(int)i].Token);
+
+ for (int i = 0 ; i < numberOfTasks ; i++)
+ {
+ taskArray[i] = new Task<Task<string>>(action, i);
+ }
+
+ for (int i = 0 ; i < numberOfTasks ; i++)
+ {
+ taskArray[i].Start();
+ ctsArray[i].Cancel();
+ }
+
+ Task.WaitAll(taskArray);
+
+ for (int i = 0 ; i < numberOfTasks ; i++)
+ {
+ if (taskArray[i].Result.IsCanceled)
+ {
+ Assert.Pass($"Task{i} is canceled successfully.");
+ }
+ }
- Assert.That(task.IsCanceled, Is.True);
+ Assert.Fail("All Tasks are not canceled");
}
#endregion