Skip to content

Make WEBrick test teardown block until the server thread exits - #165

Open
donoghuc with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-webrick-shutdown-sequence
Open

Make WEBrick test teardown block until the server thread exits#165
donoghuc with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-webrick-shutdown-sequence

Conversation

Copilot AI commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

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
@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>
Copilot AI changed the title [WIP] Fix flakiness in tests due to WEBrick shutdown sequence Make WEBrick test teardown block until the server thread exits Sep 8, 2026
Copilot AI requested a review from donoghuc September 8, 2026 23:01
@donoghuc
donoghuc marked this pull request as ready for review September 9, 2026 23:44
@donoghuc
donoghuc requested a review from andsel September 9, 2026 23:44
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.

Flakyness in tests due to WEBrick shutdown sequence

2 participants