Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reruns with same build #83

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 4 additions & 2 deletions bin/rspecq
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
require "optparse"
require "rspecq"

DEFAULT_WORKER = "foo".freeze
DEFAULT_BUILD = "bar".freeze
DEFAULT_REDIS_HOST = "127.0.0.1".freeze
DEFAULT_REPORT_TIMEOUT = 3600 # 1 hour
DEFAULT_MAX_REQUEUES = 3
Expand Down Expand Up @@ -127,8 +129,8 @@ OptionParser.new do |o|
end
end.parse!

opts[:build] ||= ENV["RSPECQ_BUILD"]
opts[:worker] ||= ENV["RSPECQ_WORKER"]
opts[:build] ||= ENV["RSPECQ_BUILD"] || DEFAULT_BUILD
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This however makes sense only when reproduction is true.

opts[:worker] ||= ENV["RSPECQ_WORKER"] || DEFAULT_WORKER
opts[:seed] ||= ENV["RSPECQ_SEED"]
opts[:redis_host] ||= ENV["RSPECQ_REDIS"] || DEFAULT_REDIS_HOST
opts[:timings] ||= env_set?("RSPECQ_UPDATE_TIMINGS")
Expand Down
15 changes: 13 additions & 2 deletions lib/rspecq/queue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,19 @@ def initialize(build_id, worker_id, redis_opts)
end

# NOTE: jobs will be processed from head to tail (lpop)
# Also some state keys are wiped to facilitate re-runs
# with the same job build prefix.
def publish(jobs, fail_fast = 0)
cleanup_keys = [
key_queue_unprocessed, key_queue_running, key_queue_processed, key_failures,
key_flaky_failures, key_errors, key_requeues, key_example_count,
key_worker_heartbeats
]

redis.multi do |pipeline|
cleanup_keys.each do |key|
pipeline.del(key)
end
pipeline.hset(key_queue_config, "fail_fast", fail_fast)
pipeline.rpush(key_queue_unprocessed, jobs)
pipeline.set(key_queue_status, STATUS_READY)
Expand Down Expand Up @@ -162,8 +173,8 @@ def job_rerun_command(job)
jobs = redis.lrange(key("queue", "jobs_per_worker", worker), 0, -1)
seed = redis.hget(key("worker_seed"), worker)

"DISABLE_SPRING=1 DISABLE_BOOTSNAP=1 bin/rspecq --build 1 " \
"--worker foo --seed #{seed} --max-requeues 0 --fail-fast 1 " \
"DISABLE_SPRING=1 DISABLE_BOOTSNAP=1 bin/rspecq " \
"--seed #{seed} --max-requeues 0 --fail-fast 1 " \
"--reproduction #{jobs.join(' ')}"
end

Expand Down
8 changes: 6 additions & 2 deletions lib/rspecq/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,20 @@ def update_heartbeat
end

def try_publish_queue!(queue)
return if !queue.become_master

if reproduction
# We assume that if we are trying to reproduce, only one
# worker will run and that one will be the master.
# Thus we forcibly publish (override) a new queue.
q_size = queue.publish(files_or_dirs_to_run, fail_fast)
log_event(
"Reproduction mode. Published queue as given (size=#{q_size})",
"info"
)
return
end

return if !queue.become_master

RSpec.configuration.files_or_directories_to_run = files_or_dirs_to_run
files_to_run = RSpec.configuration.files_to_run.map { |j| relative_path(j) }

Expand Down
4 changes: 2 additions & 2 deletions test/test_reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def test_flakey_suite

assert_match "Flaky jobs detected", output
assert_match "./spec/foo_spec.rb:2 @ #{worker_id}", output
assert_match "DISABLE_SPRING=1 DISABLE_BOOTSNAP=1 bin/rspecq --build 1 " \
"--worker foo --seed 1234 --max-requeues 0 --fail-fast 1 --reproduction " \
assert_match "DISABLE_SPRING=1 DISABLE_BOOTSNAP=1 bin/rspecq " \
"--seed 1234 --max-requeues 0 --fail-fast 1 --reproduction " \
"./spec/foo_spec.rb ./spec/foo_spec.rb[1:1] ./spec/foo_spec.rb[1:1]", output
refute_match "Failed examples", output
end
Expand Down