Skip to content

Commit 8207589

Browse files
author
opencode
committed
fix(tests): wait for active connection count to reach expected value in ConnectionPoolReconnectsTest
box.stat.net().CONNECTIONS.current is updated asynchronously by the IProto worker and closing the administrative net.box connection used by executeCommandDecoded is asynchronous on the server, so a single read can briefly observe a stale or transitional value. This made the absolute assertion `assertEquals(count1, getActiveConnectionsCount(tt))` flaky when timings shifted (e.g. under docker emulation locally and on the self-hosted 3.5.0 runner), producing `expected: <11> but was: <12>`. Add a waitForActiveConnections(tt, expected) helper in BasePoolTest that retries the assertion via the existing waitFor() loop, and use it in ConnectionPoolReconnectsTest#testReconnectAfterNodeFailure at both assertion sites (initial connect and post-reconnect). Other tests (ConnectionPoolTest, ConnectionPoolHeartbeatTest) are unaffected as they use the established baseline+delta pattern or pass in CI. Verified locally on 3.5.0: - ConnectionPoolReconnectsTest: 10/10 PASS (previously flaky) - Full box-integration target modules: 0 failures
1 parent 35bd47c commit 8207589

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

tarantool-pooling/src/test/java/io/tarantool/pool/integration/BasePoolTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.util.concurrent.CompletionException;
1616
import java.util.concurrent.ThreadLocalRandom;
1717

18+
import static org.junit.jupiter.api.Assertions.assertEquals;
1819
import static org.junit.jupiter.api.Assertions.assertTrue;
1920
import static org.junit.jupiter.api.Assertions.fail;
2021
import io.micrometer.core.instrument.Counter;
@@ -117,6 +118,28 @@ protected int getActiveConnectionsCountDelta(TarantoolContainer<?> tt, int basel
117118
return getActiveConnectionsCount(tt) - baseline;
118119
}
119120

121+
/**
122+
* Asserts that the active connection count on the given Tarantool container reaches {@code
123+
* expected}, retrying until it does. The IProto worker updates {@code
124+
* box.stat.net().CONNECTIONS.current} asynchronously, and closing administrative connections
125+
* (e.g. the {@code net.box} connection used by {@code executeCommandDecoded}) is asynchronous on
126+
* the server, so a single read can briefly observe a stale or transitional value. Retrying the
127+
* assert lets the worker converge on the final value.
128+
*
129+
* @param tt the Tarantool container under test
130+
* @param expected the expected number of active connections
131+
*/
132+
protected void waitForActiveConnections(TarantoolContainer<?> tt, int expected) {
133+
try {
134+
waitFor(
135+
"Active connections count never reached " + expected,
136+
Duration.ofSeconds(10),
137+
() -> assertEquals(expected, getActiveConnectionsCount(tt)));
138+
} catch (Exception e) {
139+
throw new RuntimeException(e);
140+
}
141+
}
142+
120143
protected MeterRegistry createMetricsRegistry() {
121144
MeterRegistry metricsRegistry = new SimpleMeterRegistry();
122145
LongTaskTimer.builder("request.timer")

tarantool-pooling/src/test/java/io/tarantool/pool/integration/ConnectionPoolReconnectsTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public void testReconnectAfterNodeFailure() throws Exception {
7777
assertTrue(pool.hasAvailableClients());
7878
List<IProtoClient> clients = getConnects(pool, "node-a", count1);
7979
assertTrue(pingClients(clients));
80-
assertEquals(count1, getActiveConnectionsCount(tt));
80+
waitForActiveConnections(tt, count1);
8181

8282
tt.stop();
8383
Thread.sleep(1000);
@@ -110,7 +110,7 @@ public void testReconnectAfterNodeFailure() throws Exception {
110110
});
111111

112112
assertTrue(pingClients(clients));
113-
assertEquals(count1, getActiveConnectionsCount(tt));
113+
waitForActiveConnections(tt, count1);
114114

115115
assertEquals(count1, metricsRegistry.get("pool.size").gauge().value());
116116
assertEquals(count1, metricsRegistry.get("pool.available").gauge().value());

0 commit comments

Comments
 (0)