Commit fb7c824
Fix flaky Netty request-timeout metrics tests (#5381)
## Problem
The test `properly update metrics when a request times out` (in
`NettyFutureRequestTimeoutTests`, and its sync counterpart in
`NettySyncRequestTimeoutTests`) is flaky on CI, failing intermittently
with `1 was not equal to 0` at the `activeRequests.get() shouldBe 0`
assertion. It failed on three dependency-update PRs in the week of
2026-07-06 alone (runs for #5379, #5376 and #5373).
The root cause is a race in the test, not in production code: the
metrics are only decremented when the endpoint's logic completes, which
for the Future-based server happens ~1 second *after* the 503 timeout
response is received (the `Future` running the logic is not
interruptible). The test used a fixed `Thread.sleep(1100)`, leaving only
a ~100 ms margin before asserting — not enough on a loaded CI machine.
The sync test had an even tighter fixed `Thread.sleep(100)`.
## Fix
Replace the fixed sleeps with `eventually { ... }` and a widened
patience config (15 s timeout / 150 ms interval) — the same idiom
already used for the same reason in `ServerMetricsTest`. This asserts
eventual consistency instead of racing the asynchronous metrics update.
No production code is changed.
## Verification
Ran locally:
- `sbt "nettyServer/testOnly
sttp.tapir.server.netty.NettyFutureServerTest -- -z \"properly update
metrics\""` — passed
- `sbt "nettyServerSync3/testOnly
sttp.tapir.server.netty.sync.NettySyncServerTest -- -z \"properly update
metrics\""` — passed
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>1 parent c1e7367 commit fb7c824
2 files changed
Lines changed: 28 additions & 8 deletions
File tree
- server/netty-server
- src/test/scala/sttp/tapir/server/netty
- sync/src/test/scala/sttp/tapir/server/netty/sync
Lines changed: 14 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
| 18 | + | |
17 | 19 | | |
18 | 20 | | |
19 | 21 | | |
20 | 22 | | |
21 | 23 | | |
22 | 24 | | |
23 | 25 | | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
24 | 32 | | |
25 | 33 | | |
26 | 34 | | |
| |||
68 | 76 | | |
69 | 77 | | |
70 | 78 | | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
75 | 85 | | |
76 | 86 | | |
77 | 87 | | |
| |||
Lines changed: 14 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
6 | 8 | | |
7 | 9 | | |
8 | 10 | | |
| |||
23 | 25 | | |
24 | 26 | | |
25 | 27 | | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
26 | 34 | | |
27 | 35 | | |
28 | 36 | | |
| |||
77 | 85 | | |
78 | 86 | | |
79 | 87 | | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
84 | 94 | | |
85 | 95 | | |
86 | 96 | | |
0 commit comments