diff --git a/ruby/lib/ci/queue/redis/worker.rb b/ruby/lib/ci/queue/redis/worker.rb index 542f029d..9e37528f 100644 --- a/ruby/lib/ci/queue/redis/worker.rb +++ b/ruby/lib/ci/queue/redis/worker.rb @@ -200,11 +200,17 @@ def try_to_reserve_lost_test lost_test end + QueueNotEmptyError = Class.new(StandardError) + def push(tests) @total = tests.size if @master = redis.setnx(key('master-status'), 'setup') - puts "Worker electected as leader, pushing #{@total} tests to the queue." + current_length = redis.llen(key('queue')) + + raise QueueNotEmptyError, "Queue is not empty (#{current_length})" if current_length > 0 + + puts "Worker electected as leader, pushing #{@total} tests to the queue (#{current_length})." puts duration = measure do diff --git a/ruby/test/integration/rspec_redis_test.rb b/ruby/test/integration/rspec_redis_test.rb index a459e688..4640d795 100644 --- a/ruby/test/integration/rspec_redis_test.rb +++ b/ruby/test/integration/rspec_redis_test.rb @@ -34,7 +34,7 @@ def test_redis_runner assert_empty err expected_output = strip_heredoc <<-EOS - Worker electected as leader, pushing 3 tests to the queue. + Worker electected as leader, pushing 3 tests to the queue (0). Finished pushing 3 tests to the queue in X.XXs. @@ -91,7 +91,7 @@ def test_redis_runner_retry assert_empty err expected_output = strip_heredoc <<-EOS - Worker electected as leader, pushing 3 tests to the queue. + Worker electected as leader, pushing 3 tests to the queue (0). Finished pushing 3 tests to the queue in X.XXs. @@ -273,7 +273,7 @@ def test_before_suite_errors assert_empty err expected_output = strip_heredoc <<-EOS - Worker electected as leader, pushing 2 tests to the queue. + Worker electected as leader, pushing 2 tests to the queue (0). Finished pushing 2 tests to the queue in X.XXs. @@ -317,7 +317,7 @@ def test_report assert_empty err expected_output = strip_heredoc <<-EOS - Worker electected as leader, pushing 3 tests to the queue. + Worker electected as leader, pushing 3 tests to the queue (0). Finished pushing 3 tests to the queue in X.XXs. @@ -418,7 +418,7 @@ def test_world_wants_to_quit assert_empty err expected_output = strip_heredoc <<-EOS - Worker electected as leader, pushing 1 tests to the queue. + Worker electected as leader, pushing 1 tests to the queue (0). Finished pushing 1 tests to the queue in X.XXs.