1
0
Fork 0
mirror of https://github.com/mperham/sidekiq.git synced 2022-11-09 13:52:34 -05:00

Fix various flaky tests due to process-wide data changes

This commit is contained in:
Mike Perham 2019-02-28 14:07:27 -08:00
parent cfe53e5fad
commit 20f4cdb4ff
2 changed files with 101 additions and 97 deletions

View file

@ -3,19 +3,23 @@ require_relative 'helper'
require 'sidekiq/util' require 'sidekiq/util'
class TestUtil < Minitest::Test class TestUtil < Minitest::Test
class Helpers class Helpers
include Sidekiq::Util include Sidekiq::Util
end end
def test_event_firing def test_event_firing
Sidekiq.options[:lifecycle_events][:startup] = [proc { raise "boom" }] before_handlers = Sidekiq.options[:lifecycle_events][:startup]
h = Helpers.new begin
h.fire_event(:startup) Sidekiq.options[:lifecycle_events][:startup] = [proc { raise "boom" }]
h = Helpers.new
h.fire_event(:startup)
Sidekiq.options[:lifecycle_events][:startup] = [proc { raise "boom" }] Sidekiq.options[:lifecycle_events][:startup] = [proc { raise "boom" }]
assert_raises RuntimeError do assert_raises RuntimeError do
h.fire_event(:startup, reraise: true) h.fire_event(:startup, reraise: true)
end
ensure
Sidekiq.options[:lifecycle_events][:startup] = before_handlers
end end
end end
end end

View file

@ -17,7 +17,9 @@ describe Sidekiq::Web do
end end
before do before do
ENV["RACK_ENV"] = "test"
Sidekiq.redis {|c| c.flushdb } Sidekiq.redis {|c| c.flushdb }
Sidekiq::Web.middlewares.clear
end end
class WebWorker class WebWorker
@ -634,110 +636,108 @@ describe Sidekiq::Web do
end end
end end
end end
end
describe 'sidekiq web with basic auth' do describe 'basic auth' do
include Rack::Test::Methods
def app
app = Sidekiq::Web.new
app.use(Rack::Auth::Basic) { |user, pass| user == "a" && pass == "b" }
app
end
it 'requires basic authentication' do
get '/'
assert_equal 401, last_response.status
refute_nil last_response.header["WWW-Authenticate"]
end
it 'authenticates successfuly' do
basic_authorize 'a', 'b'
get '/'
assert_equal 200, last_response.status
end
end
describe 'sidekiq web with custom session' do
include Rack::Test::Methods
def app
app = Sidekiq::Web.new
app.use Rack::Session::Cookie, secret: 'v3rys3cr31', host: 'nicehost.org'
app
end
it 'requires basic authentication' do
get '/'
session_options = last_request.env['rack.session'].options
assert_equal 'v3rys3cr31', session_options[:secret]
assert_equal 'nicehost.org', session_options[:host]
end
describe 'sessions options' do
include Rack::Test::Methods include Rack::Test::Methods
describe 'using #disable' do def app
def app app = Sidekiq::Web.new
app = Sidekiq::Web.new app.use(Rack::Auth::Basic) { |user, pass| user == "a" && pass == "b" }
app.disable(:sessions)
app
end
it "doesn't create sessions" do app
get '/'
assert_nil last_request.env['rack.session']
end
end end
describe 'using #set with false argument' do it 'requires basic authentication' do
def app get '/'
app = Sidekiq::Web.new
app.set(:sessions, false)
app
end
it "doesn't create sessions" do assert_equal 401, last_response.status
get '/' refute_nil last_response.header["WWW-Authenticate"]
assert_nil last_request.env['rack.session']
end
end end
describe 'using #set with an hash' do it 'authenticates successfuly' do
def app basic_authorize 'a', 'b'
app = Sidekiq::Web.new
app.set(:sessions, { domain: :all })
app
end
it "creates sessions" do get '/'
get '/'
refute_nil last_request.env['rack.session'] assert_equal 200, last_response.status
refute_empty last_request.env['rack.session'].options end
assert_equal :all, last_request.env['rack.session'].options[:domain] end
end
describe 'custom session' do
include Rack::Test::Methods
def app
app = Sidekiq::Web.new
app.use Rack::Session::Cookie, secret: 'v3rys3cr31', host: 'nicehost.org'
app
end end
describe 'using #enable' do it 'requires basic authentication' do
def app get '/'
app = Sidekiq::Web.new
app.enable(:sessions) session_options = last_request.env['rack.session'].options
app
assert_equal 'v3rys3cr31', session_options[:secret]
assert_equal 'nicehost.org', session_options[:host]
end
describe 'sessions options' do
include Rack::Test::Methods
describe 'using #disable' do
def app
app = Sidekiq::Web.new
app.disable(:sessions)
app
end
it "doesn't create sessions" do
get '/'
assert_nil last_request.env['rack.session']
end
end end
it "creates sessions" do describe 'using #set with false argument' do
get '/' def app
refute_nil last_request.env['rack.session'] app = Sidekiq::Web.new
refute_empty last_request.env['rack.session'].options app.set(:sessions, false)
refute_nil last_request.env['rack.session'].options[:secret] app
end
it "doesn't create sessions" do
get '/'
assert_nil last_request.env['rack.session']
end
end
describe 'using #set with an hash' do
def app
app = Sidekiq::Web.new
app.set(:sessions, { domain: :all })
app
end
it "creates sessions" do
get '/'
refute_nil last_request.env['rack.session']
refute_empty last_request.env['rack.session'].options
assert_equal :all, last_request.env['rack.session'].options[:domain]
end
end
describe 'using #enable' do
def app
app = Sidekiq::Web.new
app.enable(:sessions)
app
end
it "creates sessions" do
get '/'
refute_nil last_request.env['rack.session']
refute_empty last_request.env['rack.session'].options
refute_nil last_request.env['rack.session'].options[:secret]
end
end end
end end
end end