Commit 8a5d9cc
Make Vert.x test server Resource repeatable so the flaky-test retry works (#5411)
## Problem
The flaky-WebSocket-test retry added in #5410 (`TestSuite.retries`) did
**not** actually rescue the Vert.x WS flake. On CI the retry ran but
every attempt after the first failed **instantly** with:
```
ERROR DefaultCreateServerTest - Starting server failed because of null
java.lang.IllegalStateException
at io.vertx.core.http.impl.CleanableHttpServer.listen(CleanableHttpServer.java:61)
```
## Root cause
The three Vert.x **test** interpreters build the HTTP server **eagerly,
outside** the `Resource.make` acquire:
```scala
val server = vertx.createHttpServer(...).requestHandler(router) // captured once
val listenIO = vertxFutureToIo(server.listen(0))
Resource.make(listenIO)(...)
```
The retry re-runs the whole test, re-using the same server `Resource`,
which calls `listen()` a **second time on the same server instance**.
Vert.x 5's `CleanableHttpServer.listen` throws `IllegalStateException`
(empty message → logged as "because of null") when its `listenContext`
is already set. So the per-test server Resource simply wasn't repeatable
— the shared Vert.x was never actually broken.
## Fix
Create the server **inside** the acquire, so each acquire (and each
retry) gets a fresh server:
```scala
val listenIO = IO.delay {
val router = Router.router(vertx)
val _ = route(router)
vertx.createHttpServer(...).requestHandler(router)
}.flatMap(server => vertxFutureToIo(server.listen(0)))
Resource.make(listenIO)(s => vertxFutureToIo(s.close()).void).map(_.actualPort())
```
Applied to `VertxTestServerInterpreter`,
`CatsVertxTestServerInterpreter`, `ZioVertxTestServerInterpreter`.
## Test
`ServerResourceRepeatableSpec` acquires the server Resource twice (what
the retry does). It throws the exact `IllegalStateException` on the old
eager code and passes with this fix.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>1 parent f31bde1 commit 8a5d9cc
4 files changed
Lines changed: 65 additions & 16 deletions
File tree
- server/vertx-server
- cats/src/test/scala/sttp/tapir/server/vertx/cats
- src/test/scala/sttp/tapir/server/vertx
- zio/src/test/scala/sttp/tapir/server/vertx/zio
Lines changed: 11 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
38 | 44 | | |
39 | 45 | | |
40 | 46 | | |
| |||
Lines changed: 30 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
Lines changed: 12 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
36 | 43 | | |
37 | 44 | | |
38 | 45 | | |
| |||
Lines changed: 12 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
36 | 42 | | |
37 | 43 | | |
38 | 44 | | |
| |||
0 commit comments