From 88637de0032869d34be6bfa55fc51eb3b3023bb2 Mon Sep 17 00:00:00 2001 From: Stefanos Boglou Date: Wed, 26 Oct 2022 15:33:52 +0300 Subject: [PATCH 1/2] Correctly allow re-runs with the reproduction flag There is no reason to have to randomize the build_id on each reproduction run, thus we can just override the rspecq state when we publish the queue. --- lib/rspecq/queue.rb | 11 +++++++++++ lib/rspecq/worker.rb | 8 ++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/rspecq/queue.rb b/lib/rspecq/queue.rb index 8846d91..0f7f6a9 100644 --- a/lib/rspecq/queue.rb +++ b/lib/rspecq/queue.rb @@ -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) diff --git a/lib/rspecq/worker.rb b/lib/rspecq/worker.rb index b235637..5694136 100644 --- a/lib/rspecq/worker.rb +++ b/lib/rspecq/worker.rb @@ -145,9 +145,10 @@ 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})", @@ -155,6 +156,9 @@ def try_publish_queue!(queue) ) 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) } From b23ed6399cf6d8858ca374d40293d9e7bd5fe6e5 Mon Sep 17 00:00:00 2001 From: Stefanos Boglou Date: Wed, 26 Oct 2022 15:37:51 +0300 Subject: [PATCH 2/2] Remove --worker and --build as mandatory arguments Considering that we, now, can re-run the same builds using `--reproduce` it makes sense to simplify the re-run command we report in sentry. --- bin/rspecq | 6 ++++-- lib/rspecq/queue.rb | 4 ++-- test/test_reporter.rb | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/bin/rspecq b/bin/rspecq index 200b649..e83bca0 100755 --- a/bin/rspecq +++ b/bin/rspecq @@ -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 @@ -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 +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") diff --git a/lib/rspecq/queue.rb b/lib/rspecq/queue.rb index 0f7f6a9..0869b10 100644 --- a/lib/rspecq/queue.rb +++ b/lib/rspecq/queue.rb @@ -173,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 diff --git a/test/test_reporter.rb b/test/test_reporter.rb index d573166..21b14bb 100644 --- a/test/test_reporter.rb +++ b/test/test_reporter.rb @@ -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