You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by bt...@apache.org on 2021/03/15 09:54:06 UTC

[james-project] 18/32: JAMES-3492, fix tests, wait for elasticsearch flushes to complete for test assertions

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

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

commit f94b6c0ba57d16a9d28d3f66a88c4261d9c74e8f
Author: andreasvaldma <andreas.valdmanortal.com>
AuthorDate: Wed Mar 10 20:03:55 2021 +0200

    JAMES-3492, fix tests, wait for elasticsearch flushes to complete for test assertions
---
 .../james/imap/scripts/UidSearchAtomsIndexer.test  |   2 +
 .../james/webadmin/routes/UserQuotaRoutesTest.java | 194 ++++++++++++---------
 2 files changed, 115 insertions(+), 81 deletions(-)

diff --git a/mpt/impl/imap-mailbox/core/src/main/resources/org/apache/james/imap/scripts/UidSearchAtomsIndexer.test b/mpt/impl/imap-mailbox/core/src/main/resources/org/apache/james/imap/scripts/UidSearchAtomsIndexer.test
index 520cde1..539a933 100644
--- a/mpt/impl/imap-mailbox/core/src/main/resources/org/apache/james/imap/scripts/UidSearchAtomsIndexer.test
+++ b/mpt/impl/imap-mailbox/core/src/main/resources/org/apache/james/imap/scripts/UidSearchAtomsIndexer.test
@@ -2114,6 +2114,7 @@ S: A99 OK STORE completed\.
 LOG INFO Waiting for Indexer to index data
 
 AWAIT
+WAIT 10000
 
 LOG INFO Performing tests about search
 
@@ -2317,6 +2318,7 @@ S: A202 OK (\[.+\] )?APPEND completed\.
 LOG INFO Waiting for Indexer to index data
 
 AWAIT
+WAIT 10000
 
 LOG INFO Performing tests about search
 
diff --git a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserQuotaRoutesTest.java b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserQuotaRoutesTest.java
index 4afd3aa..d936a14 100644
--- a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserQuotaRoutesTest.java
+++ b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserQuotaRoutesTest.java
@@ -33,6 +33,7 @@ import static org.hamcrest.Matchers.is;
 import static org.hamcrest.Matchers.notNullValue;
 
 import java.nio.charset.StandardCharsets;
+import java.time.Duration;
 import java.util.Map;
 
 import org.apache.james.core.Domain;
@@ -56,6 +57,8 @@ import org.apache.james.quota.search.QuotaSearchTestSystem;
 import org.apache.james.user.api.UsersRepository;
 import org.apache.james.webadmin.utils.ErrorResponder;
 import org.assertj.core.api.SoftAssertions;
+import org.awaitility.Awaitility;
+import org.awaitility.core.ConditionFactory;
 import org.eclipse.jetty.http.HttpStatus;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Disabled;
@@ -71,6 +74,11 @@ import io.restassured.path.json.JsonPath;
 
 class UserQuotaRoutesTest {
 
+    private static final ConditionFactory CALMLY_AWAIT = Awaitility
+        .with().pollInterval(Duration.ofMillis(100))
+        .and().pollDelay(Duration.ofMillis(100))
+        .await();
+
     private static final String QUOTA_USERS = "/quota/users";
     private static final String LOST_LOCAL = "lost.local";
     private static final String STRANGE_LOCAL = "strange.local";
@@ -108,15 +116,18 @@ class UserQuotaRoutesTest {
 
             testSystem.getQuotaSearchTestSystem().await();
 
-            given()
-                .get("/quota/users")
-            .then()
-                .statusCode(HttpStatus.OK_200)
-                .contentType(ContentType.JSON)
-                .body("username", containsInAnyOrder(
-                    BOB.asString(),
-                    JACK.asString(),
-                    GUY_WITH_STRANGE_DOMAIN.asString()));
+            CALMLY_AWAIT.atMost(Duration.ofSeconds(10))
+                .untilAsserted(() -> {
+                    given()
+                        .get("/quota/users")
+                        .then()
+                        .statusCode(HttpStatus.OK_200)
+                        .contentType(ContentType.JSON)
+                        .body("username", containsInAnyOrder(
+                            BOB.asString(),
+                            JACK.asString(),
+                            GUY_WITH_STRANGE_DOMAIN.asString()));
+                });
         }
 
         @Test
@@ -127,16 +138,19 @@ class UserQuotaRoutesTest {
 
             testSystem.getQuotaSearchTestSystem().await();
 
-            given()
-                .param("domain", LOST_LOCAL)
-            .when()
-                .get("/quota/users")
-            .then()
-                .statusCode(HttpStatus.OK_200)
-                .contentType(ContentType.JSON)
-                .body("username", containsInAnyOrder(
-                    BOB.asString(),
-                    JACK.asString()));
+            CALMLY_AWAIT.atMost(Duration.ofSeconds(10))
+                .untilAsserted(() -> {
+                    given()
+                        .param("domain", LOST_LOCAL)
+                        .when()
+                        .get("/quota/users")
+                        .then()
+                        .statusCode(HttpStatus.OK_200)
+                        .contentType(ContentType.JSON)
+                        .body("username", containsInAnyOrder(
+                            BOB.asString(),
+                            JACK.asString()));
+                });
         }
 
         @Test
@@ -147,16 +161,19 @@ class UserQuotaRoutesTest {
 
             testSystem.getQuotaSearchTestSystem().await();
 
-            given()
-                .param("limit", 2)
-            .when()
-                .get("/quota/users")
-            .then()
-                .statusCode(HttpStatus.OK_200)
-                .contentType(ContentType.JSON)
-                .body("username", containsInAnyOrder(
-                    BOB.asString(),
-                    GUY_WITH_STRANGE_DOMAIN.asString()));
+            CALMLY_AWAIT.atMost(Duration.ofSeconds(10))
+                .untilAsserted(() -> {
+                    given()
+                        .param("limit", 2)
+                        .when()
+                        .get("/quota/users")
+                        .then()
+                        .statusCode(HttpStatus.OK_200)
+                        .contentType(ContentType.JSON)
+                        .body("username", containsInAnyOrder(
+                            BOB.asString(),
+                            GUY_WITH_STRANGE_DOMAIN.asString()));
+                });
         }
 
         @Test
@@ -167,16 +184,19 @@ class UserQuotaRoutesTest {
 
             testSystem.getQuotaSearchTestSystem().await();
 
-            given()
-                .param("offset", 1)
-            .when()
-                .get("/quota/users")
-            .then()
-                .statusCode(HttpStatus.OK_200)
-                .contentType(ContentType.JSON)
-                .body("username", containsInAnyOrder(
-                    JACK.asString(),
-                    GUY_WITH_STRANGE_DOMAIN.asString()));
+            CALMLY_AWAIT.atMost(Duration.ofSeconds(10))
+                .untilAsserted(() -> {
+                    given()
+                        .param("offset", 1)
+                        .when()
+                        .get("/quota/users")
+                        .then()
+                        .statusCode(HttpStatus.OK_200)
+                        .contentType(ContentType.JSON)
+                        .body("username", containsInAnyOrder(
+                            JACK.asString(),
+                            GUY_WITH_STRANGE_DOMAIN.asString()));
+                });
         }
 
         @Test
@@ -190,16 +210,19 @@ class UserQuotaRoutesTest {
 
             testSystem.getQuotaSearchTestSystem().await();
 
-            given()
-                .param("minOccupationRatio", 0.5)
-            .when()
-                .get("/quota/users")
-            .then()
-                .statusCode(HttpStatus.OK_200)
-                .contentType(ContentType.JSON)
-                .body("username", containsInAnyOrder(
-                    JACK.asString(),
-                    GUY_WITH_STRANGE_DOMAIN.asString()));
+            CALMLY_AWAIT.atMost(Duration.ofSeconds(10))
+                .untilAsserted(() -> {
+                    given()
+                        .param("minOccupationRatio", 0.5)
+                        .when()
+                        .get("/quota/users")
+                        .then()
+                        .statusCode(HttpStatus.OK_200)
+                        .contentType(ContentType.JSON)
+                        .body("username", containsInAnyOrder(
+                            JACK.asString(),
+                            GUY_WITH_STRANGE_DOMAIN.asString()));
+                });
         }
 
         @Test
@@ -213,16 +236,19 @@ class UserQuotaRoutesTest {
 
             testSystem.getQuotaSearchTestSystem().await();
 
-            given()
-                .param("maxOccupationRatio", 0.5)
-            .when()
-                .get("/quota/users")
-            .then()
-                .statusCode(HttpStatus.OK_200)
-                .contentType(ContentType.JSON)
-                .body("username", containsInAnyOrder(
-                    JACK.asString(),
-                    BOB.asString()));
+            CALMLY_AWAIT.atMost(Duration.ofSeconds(10))
+                .untilAsserted(() -> {
+                    given()
+                        .param("maxOccupationRatio", 0.5)
+                        .when()
+                        .get("/quota/users")
+                        .then()
+                        .statusCode(HttpStatus.OK_200)
+                        .contentType(ContentType.JSON)
+                        .body("username", containsInAnyOrder(
+                            JACK.asString(),
+                            BOB.asString()));
+                });
         }
 
         @Test
@@ -236,15 +262,18 @@ class UserQuotaRoutesTest {
 
             testSystem.getQuotaSearchTestSystem().await();
 
-            given()
-                .get("/quota/users")
-            .then()
-                .statusCode(HttpStatus.OK_200)
-                .contentType(ContentType.JSON)
-                .body("username", contains(
-                    BOB.asString(),
-                    GUY_WITH_STRANGE_DOMAIN.asString(),
-                    JACK.asString()));
+            CALMLY_AWAIT.atMost(Duration.ofSeconds(10))
+                .untilAsserted(() -> {
+                    given()
+                        .get("/quota/users")
+                        .then()
+                        .statusCode(HttpStatus.OK_200)
+                        .contentType(ContentType.JSON)
+                        .body("username", contains(
+                            BOB.asString(),
+                            GUY_WITH_STRANGE_DOMAIN.asString(),
+                            JACK.asString()));
+                });
         }
 
         @Test
@@ -400,19 +429,21 @@ class UserQuotaRoutesTest {
 
             testSystem.getQuotaSearchTestSystem().await();
 
-            String jsonAsString =
-                with()
-                    .param("minOccupationRatio", 0.5)
-                    .get("/quota/users")
-                .then()
-                    .statusCode(HttpStatus.OK_200)
-                .extract()
-                    .body()
-                    .asString();
-
-            assertThatJson(jsonAsString)
-                .when(IGNORING_ARRAY_ORDER)
-                    .isEqualTo("[" +
+            CALMLY_AWAIT.atMost(Duration.ofSeconds(10))
+                .untilAsserted(() -> {
+                    String jsonAsString =
+                        with()
+                            .param("minOccupationRatio", 0.5)
+                            .get("/quota/users")
+                            .then()
+                            .statusCode(HttpStatus.OK_200)
+                            .extract()
+                            .body()
+                            .asString();
+
+                    assertThatJson(jsonAsString)
+                        .when(IGNORING_ARRAY_ORDER)
+                        .isEqualTo("[" +
                             "    {" +
                             "        \"detail\": {" +
                             "            \"global\": {" +
@@ -438,6 +469,7 @@ class UserQuotaRoutesTest {
                             "        \"username\": \"guy@strange.local\"" +
                             "    }" +
                             "]");
+                });
         }
 
 


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org