Skip to content

Make Vert.x test server Resource repeatable so the flaky-test retry works#5411

Merged
adamw merged 1 commit into
masterfrom
fix/vertx-test-server-resource-repeatable
Jul 13, 2026
Merged

Make Vert.x test server Resource repeatable so the flaky-test retry works#5411
adamw merged 1 commit into
masterfrom
fix/vertx-test-server-resource-repeatable

Conversation

@adamw

@adamw adamw commented Jul 13, 2026

Copy link
Copy Markdown
Member

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:

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:

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

…orks

The three Vert.x test interpreters created the HTTP server eagerly, outside
the Resource.make acquire, capturing a single server instance. The flaky-WS-
test retry (TestSuite.retries, added in #5410) re-uses the test's server
Resource, which re-runs listen() on that same instance; Vert.x 5's
CleanableHttpServer.listen throws IllegalStateException when listen() is called
twice on one server ("Starting server failed because of null"). So every retry
of a Vert.x test failed instantly on server startup, defeating the retry.

Create the server inside the acquire instead, so each acquire (and thus each
retry) gets a fresh server. Add ServerResourceRepeatableSpec, which fails on
the old eager code and passes now.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@adamw adamw merged commit 8a5d9cc into master Jul 13, 2026
22 checks passed
@adamw adamw deleted the fix/vertx-test-server-resource-repeatable branch July 13, 2026 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant