Compare commits

..
Author SHA1 Message Date
rootandClaude Opus 5.5 8f0e8922a7 test(gateway): assert one controller connection at a time, not in total
CI / Check (gateway, backend, frontend) (push) Successful in 1m10s
The boost test counted every connection the mock accepted. After the boost
the gateway re-polls about 3 s later and the restore comes about 4 s after
that, close to the 5 s idle close, so on a slow CI runner the transport
closes the socket and the restore opens a second one, one after the other.
That is correct behaviour; what the MK01 cannot take is two at once, so the
mock now records the peak of open connections and the test checks that.
Reproduced by delaying the restore 9 s: the old assertion fails with the
CI message, the new one passes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015x6FWeKCY59JfFJmzAm4TL
2026-10-25 14:38:09 +01:00
2 changed files with 8 additions and 2 deletions

No files matched your search

@@ -133,7 +133,7 @@ class GatewayEndToEndTest {
waitFor(() -> controllerWrites().size() == 2);
assertEquals(List.of(1, 4143, 38), controllerWrites().get(1));
assertEquals(1, controller.connections(), "the MK01 drops a client when a second one connects");
assertEquals(1, controller.peakOpenConnections(), "the MK01 drops a client when a second one connects");
gateway.close(); // flushes the audit lines, which otherwise wait for the next flush period
var audit = auditLines().toList();
@@ -30,6 +30,7 @@ public final class MockModbusServer implements Closeable {
private final Map<Integer, Integer> input = new ConcurrentHashMap<>();
private final AtomicInteger connections = new AtomicInteger();
private final AtomicInteger open = new AtomicInteger();
private final AtomicInteger peakOpen = new AtomicInteger();
private final List<int[]> writes = new CopyOnWriteArrayList<>();
private final List<int[]> multipleWrites = new CopyOnWriteArrayList<>();
private volatile Duration responseDelay = Duration.ZERO;
@@ -68,6 +69,11 @@ public final class MockModbusServer implements Closeable {
return open.get();
}
/** The most connections that were open at the same time. */
public int peakOpenConnections() {
return peakOpen.get();
}
public void holding(int address, int value) {
holding.put(address, value);
}
@@ -135,7 +141,7 @@ public final class MockModbusServer implements Closeable {
try {
Socket client = server.accept();
connections.incrementAndGet();
open.incrementAndGet();
peakOpen.accumulateAndGet(open.incrementAndGet(), Math::max);
Thread.ofVirtual().start(() -> serve(client));
} catch (IOException e) {
return;