Skip to content

Commit 84e2142

Browse files
committed
fix(tests): wait for box.stat.net().CONNECTIONS.current to stabilise
The ConnectionPoolHeartbeatTest assertions in BasePoolTest.getActiveConnectionsCount were flaky because tarantool's box.stat.net().CONNECTIONS.current is updated asynchronously by the IProto worker. When the test creates 20+ pool entries in a tight burst (pool.get() in a loop followed by CompletableFuture.allOf().join()), netty establishes all the TCP connections in ~50 ms, but the IProto worker in tarantool processes them serially with 10-30 ms per connection. The test then reads the counter before the worker has caught up, so the returned value is 5-15 below the expected count. In the most extreme case, even the helper's own 'tt' connection is not yet counted in CONNECTIONS.current by the time the Lua runs (because the IProto worker updates the counter after sending the response, and the 'tt' connection can close before the response reaches it), producing a delta of -2 to -5 relative to the baseline and failing the equality check with messages like 'expected: <20> but was: <10>' or 'expected: <13> but was: <-2>'. Fix: run the read inside a wait-for-stable loop. The Lua sleeps on a fiber for 50 ms between reads, which yields the IProto worker and gives it time to accept the pending TCP connections and update the counter. The loop exits as soon as two consecutive reads return the same value, with a 2.5 s safety timeout. Verified: - ConnectionPoolHeartbeatTest: 10/10 runs pass (previously 2-5/10) - ConnectionPoolHeartbeatTest: 5/5 full profile runs pass (17/17 tests) - ConnectionPoolReconnectsTest: 5/5 runs pass (no regression) - ConnectionPoolTest: 5/5 runs pass (12/12 tests, no regression) - 24/24 unit tests pass (no regression) - 349/349 crud integration tests pass (no regression)
1 parent bba3007 commit 84e2142

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,23 @@ protected void execLua(TarantoolContainer<?> container, String command) {
9393

9494
protected int getActiveConnectionsCount(TarantoolContainer<?> tt) {
9595
try {
96-
List<? extends Object> result =
97-
TarantoolContainerClientHelper.executeCommandDecoded(
98-
tt, "return box.stat.net().CONNECTIONS.current");
99-
return (Integer) result.get(0) - 1;
96+
// box.stat.net().CONNECTIONS.current is updated asynchronously by the IProto
97+
// worker; when many connections are opened in a burst it lags behind by
98+
// 100-500 ms. Wait for it to stabilise (fiber.sleep yields the worker so it
99+
// can accept the pending connections) before reading the value.
100+
String lua =
101+
"local last = box.stat.net().CONNECTIONS.current\n"
102+
+ "for i = 1, 50 do\n"
103+
+ " require('fiber').sleep(0.05)\n"
104+
+ " local cur = box.stat.net().CONNECTIONS.current\n"
105+
+ " if cur == last then\n"
106+
+ " return cur - 1\n"
107+
+ " end\n"
108+
+ " last = cur\n"
109+
+ "end\n"
110+
+ "return last - 1";
111+
List<? extends Object> result = TarantoolContainerClientHelper.executeCommandDecoded(tt, lua);
112+
return (Integer) result.get(0);
100113
} catch (Exception e) {
101114
throw new RuntimeException(e);
102115
}

0 commit comments

Comments
 (0)