This is an automated email from the ASF dual-hosted git repository.

rouazana pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 44557665bc3d754bb5b805557e4774cb9575c44f
Author: RĂ©mi Kowalski <[email protected]>
AuthorDate: Tue Jun 11 15:53:38 2019 +0200

    JAMES-2788 release threads in TaskRoutesTest
---
 .../james/webadmin/routes/TasksRoutesTest.java     | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git 
a/server/protocols/webadmin/webadmin-core/src/test/java/org/apache/james/webadmin/routes/TasksRoutesTest.java
 
b/server/protocols/webadmin/webadmin-core/src/test/java/org/apache/james/webadmin/routes/TasksRoutesTest.java
index 1a693dc..cb1becf 100644
--- 
a/server/protocols/webadmin/webadmin-core/src/test/java/org/apache/james/webadmin/routes/TasksRoutesTest.java
+++ 
b/server/protocols/webadmin/webadmin-core/src/test/java/org/apache/james/webadmin/routes/TasksRoutesTest.java
@@ -49,6 +49,7 @@ class TasksRoutesTest {
 
     private MemoryTaskManager taskManager;
     private WebAdminServer webAdminServer;
+    private CountDownLatch waitingForResultLatch;
 
     @BeforeEach
     void setUp() {
@@ -60,10 +61,13 @@ class TasksRoutesTest {
         RestAssured.requestSpecification = 
WebAdminUtils.buildRequestSpecification(webAdminServer)
             .setBasePath(TasksRoutes.BASE)
             .build();
+
+        waitingForResultLatch = new CountDownLatch(1);
     }
 
     @AfterEach
     void tearDown() {
+        waitingForResultLatch.countDown();
         taskManager.stop();
         webAdminServer.destroy();
     }
@@ -81,7 +85,7 @@ class TasksRoutesTest {
         CountDownLatch taskInProgressLatch = new CountDownLatch(1);
         TaskId taskId = taskManager.submit(() -> {
             taskInProgressLatch.countDown();
-            await();
+            waitForResult();
             return Task.Result.COMPLETED;
         });
 
@@ -97,20 +101,24 @@ class TasksRoutesTest {
             .body("[0].class", is(not(empty())));
     }
 
-    private void await() {
+    private void await(CountDownLatch latch) {
         try {
-            new CountDownLatch(1).await();
+            latch.await();
         } catch (InterruptedException e) {
             throw new RuntimeException(e);
         }
     }
 
+    private void waitForResult() {
+        await(waitingForResultLatch);
+    }
+
     @Test
     void listShouldListTaskWhenStatusFilter() throws Exception {
         CountDownLatch inProgressLatch = new CountDownLatch(1);
         TaskId taskId = taskManager.submit(() -> {
             inProgressLatch.countDown();
-            await();
+            waitForResult();
             return Task.Result.COMPLETED;
         });
 
@@ -133,7 +141,7 @@ class TasksRoutesTest {
         CountDownLatch inProgressLatch = new CountDownLatch(1);
         taskManager.submit(() -> {
             inProgressLatch.countDown();
-            await();
+            waitForResult();
             return Task.Result.COMPLETED;
         });
 
@@ -153,7 +161,7 @@ class TasksRoutesTest {
         CountDownLatch inProgressLatch = new CountDownLatch(1);
         TaskId taskId = taskManager.submit(() -> {
             inProgressLatch.countDown();
-            await();
+            waitForResult();
             return Task.Result.COMPLETED;
         });
 
@@ -218,7 +226,7 @@ class TasksRoutesTest {
     @Test
     void deleteShouldReturnOk() {
         TaskId taskId = taskManager.submit(() -> {
-            await();
+            waitForResult();
             return Task.Result.COMPLETED;
         });
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to