1010import java .util .concurrent .ExecutionException ;
1111import java .util .concurrent .TimeUnit ;
1212import java .util .concurrent .TimeoutException ;
13+ import java .util .concurrent .atomic .AtomicReference ;
1314import io .restassured .RestAssured ;
1415import io .restassured .filter .log .ErrorLoggingFilter ;
1516import io .restassured .http .ContentType ;
1819import io .vertx .core .Vertx ;
1920import io .vertx .core .json .Json ;
2021import io .vertx .core .json .JsonObject ;
22+ import org .awaitility .Awaitility ;
2123import org .folio .postgres .testing .PostgresTesterContainer ;
2224import org .folio .rest .jaxrs .model .Parameter ;
2325import org .folio .rest .jaxrs .model .TenantAttributes ;
@@ -66,24 +68,14 @@ static void beforeAll() {
6668
6769 // delete tenant (schema, tables, ...) if it exists from previous tests
6870 TenantAttributes ta = new TenantAttributes ().withPurge (true );
69- given (r ).header ("x-okapi-url-to" , "http://localhost:" + port ).
70- contentType (ContentType .JSON )
71- .body (Json .encode (ta ))
72- .when ().post ("/_/tenant" )
73- .then ().statusCode (204 );
71+ postTenantWithRetry (ta , 204 );
7472
7573 List <Parameter > list = new LinkedList <>();
7674 list .add (new Parameter ().withKey ("loadReference" ).withValue ("true" ));
7775 ta = new TenantAttributes ().withModuleTo ("mod-api-1.0.0" ).withParameters (list );
7876
7977 // create tenant (schema, tables, ...)
80- String location = given (r )
81- .header ("x-okapi-url-to" , "http://localhost:" + port )
82- .contentType (ContentType .JSON )
83- .body (Json .encode (ta ))
84- .when ().post ("/_/tenant" )
85- .then ().statusCode (201 )
86- .extract ().header ("Location" );
78+ String location = postTenantWithRetry (ta , 201 );
8779
8880 given (r )
8981 .header ("x-okapi-url-to" , "http://localhost:" + port )
@@ -94,6 +86,22 @@ static void beforeAll() {
9486 .body ("error" , is (nullValue ()));
9587 }
9688
89+ private static String postTenantWithRetry (TenantAttributes tenantAttributes , int expectedStatus ) {
90+ var location = new AtomicReference <String >();
91+ Awaitility .await ().untilAsserted (() -> location .set (
92+ given (r )
93+ .header ("x-okapi-url-to" , "http://localhost:" + port )
94+ .contentType (ContentType .JSON )
95+ .body (Json .encode (tenantAttributes ))
96+ .when ()
97+ .post ("/_/tenant" )
98+ .then ()
99+ .statusCode (expectedStatus )
100+ .extract ()
101+ .header ("Location" )));
102+ return location .get ();
103+ }
104+
97105 /**
98106 * @param path API path, for example <code>/bees</code>
99107 * @param arrayName property name of the result array, for example <code>bees</code>
0 commit comments