[MediaContent][Non-ACR] Update Cancel test logic 86/280586/1
authorHaesu Gwon <haesu.gwon@samsung.com>
Thu, 1 Sep 2022 03:03:32 +0000 (12:03 +0900)
committerHaesu Gwon <haesu.gwon@samsung.com>
Thu, 1 Sep 2022 03:03:32 +0000 (12:03 +0900)
Change-Id: I04592cd2ab453c128114f21ff35de34318f64d2b

tct-suite-vs/Tizen.Mediacontent.Tests/testcase/TSMediaInfoCommand.cs

index 9261678..1e8ccd3 100644 (file)
@@ -1556,14 +1556,43 @@ namespace Tizen.Content.MediaContent.Tests
         [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