Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/rspecq/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ def work

queue.save_worker_seed(@worker_id, seed)

# Use `--seed` to deterministically reproduce test failures
# related to randomization by passing the same `--seed` value
# as the one that triggered the failure.
#
# We also use the same seed to feed Rspec's `--seed` option.
Kernel.srand(seed)

loop do
# we have to bootstrap this so that it can be used in the first call
# to `requeue_lost_job` inside the work loop
Expand Down
3 changes: 3 additions & 0 deletions test/sample_suites/random_failing/spec/seed_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
RSpec.describe do
it { expect(rand(2)).to be_zero }
end
12 changes: 12 additions & 0 deletions test/test_e2e.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,18 @@ def test_suite_with_failures_and_fail_fast
assert_includes [2, 3], queue.processed_jobs.length
end

def test_seed_reproducability
initial_outcome = nil

3.times do |i|
queue = exec_build("random_failing", " --max-requeues 0 --seed 1234", build_id: "run-#{i}")
outcome = queue.build_successful?
initial_outcome ||= outcome

assert_equal outcome, initial_outcome, "the outcome should be the same for the same seed"
end
end

def test_graceful_shutdown
pid, queue = start_worker("rescue_exception",
"--max-requeues=0 --graceful_shutdown_timeout=5")
Expand Down