Skip to content

Commit

Permalink
Use RSpec 3.3. Eagerly initialize let blocks to prevent deadlocks.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jared Jenkins committed Nov 9, 2015
1 parent 528bf9b commit 12babd9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
31 changes: 20 additions & 11 deletions spec/worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,33 @@ def maybe_cleanup_file(file_path)
:timeout => timeout
end

let(:expiration) { work_time * 4 }
let(:work_time) { 0.1 }
# Eagerly initializing work_time and the like so that
# we don't introduce deadlocks inside of our subject. Believe
# this is related to RSpec 3.3 thread-safety changes: subject/let
# blocks are now sychronized across multiple threads. It's possible that the
# interaction between Celluloid (threading library for Sidekiq) and RSpec
# is causing the deadlock, but it's not exactly clear why.
# See for possible explanation: https://github.com/rspec/rspec-core/issues/2064
let!(:expiration) { work_time * 4 }
let!(:work_time) { 0.1 }

subject do
threads = []
threads << Thread.new { FakeWorker.new.perform(work_time) }
threads << Thread.new do
# TODO(jaredjenkins): figure out why this is causing a deadlock
# with out the eager loading the RSpec lets.
sleep wait_time
FakeWorker.new.perform(work_time)
end
threads.each(&:join)
threads.select(&:alive?).each(&:join)
end

context "overlapping schedule" do
let(:wait_time) { 0 }
let!(:wait_time) { 0 }

context "timeout is less than work_time (too short)" do
let(:timeout) { work_time / 2 }
let!(:timeout) { work_time / 2 }

it "one worker should be blocked" do
subject
Expand Down Expand Up @@ -91,7 +100,7 @@ def maybe_cleanup_file(file_path)
end

context "timeout is greater than work_time" do
let(:timeout) { work_time * 4 }
let!(:timeout) { work_time * 4 }

it "no worker should be blocked" do
subject
Expand Down Expand Up @@ -119,7 +128,7 @@ def maybe_cleanup_file(file_path)
end

context "expiration too short" do
let(:expiration) { work_time / 2 }
let!(:expiration) { work_time / 2 }

it "no worker should be blocked" do
subject
Expand Down Expand Up @@ -151,10 +160,10 @@ def maybe_cleanup_file(file_path)
end

context "non-overlapping schedule" do
let(:wait_time) { work_time * 2 }
let!(:wait_time) { work_time * 2 }

context "timeout is less than work_time (too short)" do
let(:timeout) { work_time }
let!(:timeout) { work_time }

it "no workers should be blocked" do
subject
Expand Down Expand Up @@ -184,7 +193,7 @@ def maybe_cleanup_file(file_path)
end

context "timeout is greater than work_time" do
let(:timeout) { work_time * 2 }
let!(:timeout) { work_time * 2 }

it "no worker should be blocked" do
subject
Expand All @@ -207,7 +216,7 @@ def maybe_cleanup_file(file_path)
end

context "expiration too short" do
let(:expiration) { work_time / 2 }
let!(:expiration) { work_time / 2 }

it "no worker should be blocked" do
subject
Expand Down
2 changes: 1 addition & 1 deletion sqeduler.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Gem::Specification.new do |gem|
gem.add_development_dependency "bundler", "~> 1.7"
gem.add_development_dependency "pry", "~> 0"
gem.add_development_dependency "rake", "~> 10"
gem.add_development_dependency "rspec", "~> 3"
gem.add_development_dependency "rspec", "~> 3.3"
gem.add_development_dependency "rubocop", "~> 0.24"
gem.add_development_dependency "timecop", "~> 0"
gem.add_development_dependency "yard", "~> 0"
Expand Down

0 comments on commit 12babd9

Please sign in to comment.