Repository navigation
Backport: make WEBrick test teardown block until the server thread exits (#165) - #168
Conversation
…ash-plugins#165) The flaky HTTP output specs were starting WEBrick on a background thread and tearing it down asynchronously, which could leave the listener alive between examples and hang retries against a server that had not fully stopped. - **Return the WEBrick thread from the shared test helper** - `start_app_and_wait` now returns both the server instance and the thread running `app.start!` - this gives teardown a reliable handle for waiting until WEBrick has actually exited - **Add a blocking teardown helper** - introduced `stop_app_and_wait(app, server, server_thread)` - shutdown order is now: 1. `app.stop!` 2. `server.shutdown` 3. `server_thread.join(30)` - if shutdown does not complete within the bound, the helper emits a clear warning and kills the thread instead of silently hanging - **Update the existing spec call sites** - both the main HTTP spec setup and the TLS-specific setup now capture `@server_thread` - both teardown paths now use the shared blocking helper instead of manually shutting down WEBrick ```ruby @server, @server_thread = start_app_and_wait(TestApp) stop_app_and_wait(TestApp, @server, @server_thread) ``` Co-authored-by: donoghuc <15354214+donoghuc@users.noreply.github.com>
Changelog and Version ManagementNo changelog or version changes detected. You can either update them manually or use a comment command to update them automatically on merge:
Omit the entry line to use the PR title. If multiple commands are posted, the last one wins. |
There was a problem hiding this comment.
🟡 Changes recommended
The TLS helper can return before a killed server thread exits, allowing the next example to race with teardown on the shared port.
1 open issue
What changed in this PR
Backports #165 to the 5.x branch to address flaky WEBrick teardown in the HTTP output specs, as requested in #166. Changes are limited to specs.
Changes:
- Return the server thread alongside the server instance from the startup helper.
- Add shared teardown that waits up to 30 seconds, then warns and kills the thread on timeout.
- Update HTTP and TLS specs to use the shared teardown helper.
| File | Description |
|---|---|
spec/spec_helper.rb |
Track the server thread and add blocking teardown with a timeout fallback. |
spec/outputs/http_spec.rb |
Capture thread handles and use shared teardown in HTTP and TLS specs. |
Review effort: Balanced
|
|
||
| unless server_thread.join(30) | ||
| warn "Timed out waiting for test server thread to stop" | ||
| server_thread.kill |
There was a problem hiding this comment.
This could be solved by a join, but it is not a big deal since it would only affect the timeout path

Backport of #165 to 5.x. Spec-only change.
Fixes #166