Commit 732614a
Fix flaky SSE tests in akka/pekko server modules (#5387)
## Problem
The "Send and receive SSE" test in `AkkaHttpServerTest` flaked on CI
(seen on PR #5381's CI run, 2026-07-07, ci 2.13 / JVM 11) with only:
```
org.scalatest.exceptions.TestFailedException was thrown. (AkkaHttpServerTest.scala:82)
```
No message, no cause. An identical sibling test exists in
`PekkoHttpServerTest`.
Two things went wrong:
1. **Swallowed exception**: the test ended with `.transform(sse => sse
shouldBe ..., ex => fail(ex))`. `fail(ex)` wraps the real exception as
the *cause* of a message-less `TestFailedException`, and the test
reporter prints neither — hence the bare failure line.
2. **The actual flake**: the sttp client backend was created with
default `ConnectionPoolSettings`, whose
`response-entity-subscription-timeout` is **1s**. The test consumes the
response via `asStreamUnsafe` and only materializes the SSE-parsing
`runFold` in a later future callback. On a loaded CI runner that gap can
exceed 1s, at which point the akka/pekko-http client pool fails the
entity stream ("Response entity was not subscribed after 1 second...").
## Fix
- Build the per-test client backend with
`ConnectionPoolSettings(actorSystem).withResponseEntitySubscriptionTimeout(1.minute)`
so a slow runner can't hit the subscription timeout.
- Replace the `.transform(..., ex => fail(ex))` with a plain `.map(...)`
so if the test ever fails again, the real exception (message + type)
propagates to the report instead of a bare `TestFailedException`.
- Close the per-test client backend after the request completes (it was
previously leaked).
Same changes applied to both the akka and pekko variants.
## Force-repro proof
- A
`-Dakka.http.host-connection-pool.response-entity-subscription-timeout=1ms`
override propagates into the (non-forked) test JVM but does *not*
reproduce locally: on an idle machine the stream is subscribed before
the scheduler-tick-granularity timeout task can fire.
- Simulating CI load instead — inserting `Thread.sleep(1500)` before the
`runFold` materialization on unmodified master (default 1s timeout) —
reproduces the **exact** CI symptom: `TestFailedException was thrown.
(AkkaHttpServerTest.scala:82)`.
- The same 1500ms delay with this fix applied: test **passes**.
## Verification
- Both SSE tests (akka + pekko) run 3x each: all green.
- `akkaHttpServer2_12/Test/compile`, `pekkoHttpServer2_12/Test/compile`,
`pekkoHttpServer3/Test/compile`: all pass.
- Full `AkkaHttpServerTest` suite: 301 tests, 0 failures.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>1 parent a122c5e commit 732614a
2 files changed
Lines changed: 22 additions & 4 deletions
File tree
- server
- akka-http-server/src/test/scala/sttp/tapir/server/akkahttp
- pekko-http-server/src/test/scala/sttp/tapir/server/pekkohttp
Lines changed: 11 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| 31 | + | |
30 | 32 | | |
31 | 33 | | |
32 | 34 | | |
| |||
64 | 66 | | |
65 | 67 | | |
66 | 68 | | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
67 | 75 | | |
68 | 76 | | |
69 | 77 | | |
| |||
78 | 86 | | |
79 | 87 | | |
80 | 88 | | |
81 | | - | |
82 | | - | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
83 | 92 | | |
84 | 93 | | |
85 | 94 | | |
| |||
Lines changed: 11 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| 32 | + | |
31 | 33 | | |
32 | 34 | | |
33 | 35 | | |
| |||
65 | 67 | | |
66 | 68 | | |
67 | 69 | | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
68 | 76 | | |
69 | 77 | | |
70 | 78 | | |
| |||
79 | 87 | | |
80 | 88 | | |
81 | 89 | | |
82 | | - | |
83 | | - | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
84 | 93 | | |
85 | 94 | | |
86 | 95 | | |
| |||
0 commit comments