[deploy] Flaky Spec Fix:Set TimeZone For All Spec Requests to Match Zonebie (#10891)

This commit is contained in:
Molly Struve 2020-10-19 10:24:58 -04:00 committed by GitHub
parent adb41a0a15
commit c55bd0948f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 0 deletions

View file

@ -0,0 +1,13 @@
module Middleware
class TimeZoneSetter
def initialize(app)
@app = app
end
def call(env)
Time.zone = ActiveSupport::TimeZone.new(ENV["TZ"]) if ENV["TZ"]
@app.call(env)
end
end
end

View file

@ -5,6 +5,10 @@ $VERBOSE = nil
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Include middleware to ensure timezone for browser requests for Capybara specs
# matches the random zonebie timezone set at the beginning of our spec run
config.middleware.use(Middleware::TimeZoneSetter)
# The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that
# your test database is "scratch space" for the test suite and is wiped

View file

@ -84,6 +84,10 @@ RSpec.configure do |config|
end
config.before(:suite) do
# Set the TZ ENV variable with the current random timezone from zonebie
# which we can then use to properly set the browser time for Capybara specs
ENV["TZ"] = Time.zone.tzinfo.name
Search::Cluster.recreate_indexes
end