mirror of
https://github.com/discourse/discourse.git
synced 2025-02-05 19:11:13 +00:00
c30aeafd9d
Why this change? We have been debugging flaky system tests and noticed in https://github.com/discourse/discourse/actions/runs/7911902047/job/21596791343?pr=25690 that ActiveRecord connection checkout timeouts are encountered because the Capybara server thread is processing requests even after `Capybara.reset_session!` and ActiveRecord's `teardown_fixtures` have already been call. The theory here is that an inflight request can still hit the Capybara server even after `Capybara.reset_session!` has been called and end up eating up an ActiveRecord connection for too long and also messing with the database outside of a transaction. What does this change do? This change adds a `BlockRequestsMiddleware` middleware in the test environment which is enabled to reject all incoming requests at the end of each system test and before `Capybara.reset_session!` is called. At the start of each RSpec test, the middleware is disabled again.