Skip to content

Commit

Permalink
Raise if queue is not empty
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisBr committed Aug 29, 2024
1 parent d282ebf commit cc2ae11
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
8 changes: 7 additions & 1 deletion ruby/lib/ci/queue/redis/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions ruby/test/integration/rspec_redis_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit cc2ae11

Please sign in to comment.