Created
July 6, 2021 13:01
-
-
Save nandilugio/31d0c96f9cc300d9cbda1993d8989390 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is a debugging tool for flaky ruby/rack (rails) browser tests not properly | |
# waiting for potentially slow server responses (eg. with Capybara). Its a Rack | |
# middleware that adds a delay to every response, thus making the problem | |
# evident. | |
# | |
# In Rails, add the following to the end of your Application class definition in | |
# `config/application.rb`, AND REMOVE AFTER DEBUGGING!!! | |
# | |
# # TODO: REMOVE!! | |
# require("slow_requests_for_debugging") | |
# config.middleware.use SlowRequestsForDebugging | |
# | |
class SlowRequestsForDebugging | |
DELAY_SECS = 5 | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
@request = Rack::Request.new(env) | |
puts "Holding for #{DELAY_SECS} seconds the response to #{@request.url}" | |
sleep(DELAY_SECS) | |
puts "Response hold released for " + @request.url | |
@app.call(env) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Other reasons for flaky tests: