Skip to content

Commit d06cb25

Browse files
committed
test(tdg): await data model readiness in TDGClientTest
TDGClientTest queried spaces right after cluster.start(), which only waits for the containers to come up. The TDG data model (and therefore the User/person spaces) is applied asynchronously afterwards, so on slower runners the first queries hit a not-yet-created space and failed with "attempt to index ... 'space' (a nil value)". Wait for the model in @BeforeAll by probing both spaces via retryUntilSuccess before the tests run.
1 parent eb2319c commit d06cb25

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

tarantool-client/src/test/java/io/tarantool/client/integration/tdg/TDGClientTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@
1616
import java.util.Objects;
1717
import java.util.UUID;
1818
import java.util.concurrent.CompletionException;
19+
import java.util.concurrent.TimeUnit;
1920

2021
import org.junit.jupiter.api.AfterAll;
2122
import org.junit.jupiter.api.AfterEach;
2223
import org.junit.jupiter.api.Assertions;
2324
import org.junit.jupiter.api.BeforeAll;
2425
import org.junit.jupiter.api.Test;
26+
import org.rnorth.ducttape.unreliables.Unreliables;
2527
import org.testcontainers.containers.tdg.cluster.TDGCluster;
2628
import org.testcontainers.containers.tdg.cluster.TDGClusterImpl;
2729
import org.testcontainers.containers.tdg.configuration.TDGConfigurator;
@@ -41,6 +43,9 @@ class TDGClientTest {
4143
DockerImageName.parse(
4244
System.getenv().getOrDefault("TARANTOOL_REGISTRY", "") + "tdg2:2.11.5-0-geff8adb3");
4345

46+
/** Upper bound for the TDG data model to be applied cluster-wide after the containers start. */
47+
private static final int MODEL_READINESS_TIMEOUT_SECONDS = 60;
48+
4449
private static final Path ROOT_CONFIG_PATH;
4550

4651
private static final TDGConfigurator configurator;
@@ -73,6 +78,24 @@ static void setUp() throws Exception {
7378
.withHost(configurator.core().getValue().iprotoMappedAddress().getHostName())
7479
.withPort(configurator.core().getValue().iprotoMappedAddress().getPort())
7580
.build();
81+
awaitModelReady();
82+
}
83+
84+
/**
85+
* Waits until the TDG data model is applied cluster-wide. {@link TDGCluster#start()} only blocks
86+
* until the containers are up, whereas the model (and therefore the spaces) is loaded
87+
* asynchronously afterwards. Without this wait the first queries may hit a not-yet-created space
88+
* and fail with "attempt to index ... 'space' (a nil value)" on slower runners.
89+
*/
90+
private static void awaitModelReady() {
91+
Unreliables.retryUntilSuccess(
92+
MODEL_READINESS_TIMEOUT_SECONDS,
93+
TimeUnit.SECONDS,
94+
() -> {
95+
client.space("User").get(1).join();
96+
client.space("person").get(1).join();
97+
return null;
98+
});
7699
}
77100

78101
@AfterAll

0 commit comments

Comments
 (0)