Skip to content

Commit cdf0feb

Browse files
davidstosikdkeegan-figma
authored andcommitted
Use Concurrent::Set instead of Set
ci-queue depends on ActiveSupport, which depends on concurrent-ruby, so we do have access to `Concurrent::Set`.
1 parent 832415b commit cdf0feb

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

ruby/lib/ci/queue/redis/worker.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
require 'ci/queue/static'
4-
require 'set'
4+
require 'concurrent/set'
55

66
module CI
77
module Queue
@@ -21,6 +21,7 @@ class Worker < Base
2121

2222
def initialize(redis, config)
2323
@reserved_test = nil
24+
@reserved_tests = Concurrent::Set.new
2425
@shutdown_required = false
2526
@idle_since = nil
2627
super(redis, config)
@@ -301,6 +302,10 @@ def ensure_connection_and_script(script)
301302
redis.ping
302303
end
303304

305+
def reserved_tests
306+
@reserved_tests ||= Concurrent::Set.new
307+
end
308+
304309
def worker_id
305310
config.worker_id
306311
end

ruby/lib/ci/queue/static.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# frozen_string_literal: true
22

3+
require 'concurrent/set'
4+
35
module CI
46
module Queue
57
class Static
@@ -112,6 +114,10 @@ def should_requeue?(key)
112114
def requeues
113115
@requeues ||= Hash.new(0)
114116
end
117+
118+
def reserved_tests
119+
@reserved_tests ||= Concurrent::Set.new
120+
end
115121
end
116122
end
117123
end

ruby/test/integration/minitest_redis_test.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
require 'test_helper'
33
require 'tmpdir'
44
require 'active_support/testing/time_helpers'
5+
require 'concurrent/set'
56

67
module Integration
78
class MinitestRedisTest < Minitest::Test
@@ -308,6 +309,7 @@ def test_retry_report
308309
assert_equal 100, error_reports.size
309310

310311
error_reports.keys.each_with_index do |test_id, index|
312+
queue.instance_variable_set(:@reserved_tests, Concurrent::Set.new([test_id]))
311313
queue.build.record_success(test_id.dup, stats: {
312314
'assertions' => index + 1,
313315
'errors' => 0,

ruby/test/minitest/queue/build_status_recorder_test.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# frozen_string_literal: true
22
require 'test_helper'
3+
require 'concurrent/set'
34

45
module Minitest::Queue
56
class BuildStatusRecorderTest < Minitest::Test
@@ -50,6 +51,10 @@ def test_retrying_test
5051

5152
private
5253

54+
def reserve(queue, method_name)
55+
queue.instance_variable_set(:@reserved_tests, Concurrent::Set.new([Minitest::Queue::SingleExample.new("Minitest::Test", method_name).id]))
56+
end
57+
5358
def worker(id)
5459
CI::Queue::Redis.new(
5560
@redis_url,

0 commit comments

Comments
 (0)