Skip to content

Commit 976f5d5

Browse files
committed
Redis 4.6 compatibility
1 parent fe6135c commit 976f5d5

File tree

8 files changed

+47
-50
lines changed

8 files changed

+47
-50
lines changed

.github/workflows/tests.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ jobs:
1313
- 6379:6379
1414

1515
strategy:
16+
fail-fast: false
1617
matrix:
17-
ruby: [ '2.6', '2.7' ]
18+
ruby: [ '2.6', '2.7', '3.0', '3.1' ]
1819
steps:
1920
- uses: actions/checkout@v2
2021
- name: Set up Ruby ${{ matrix.ruby }}
@@ -32,6 +33,9 @@ jobs:
3233
python-tests:
3334
runs-on: ubuntu-latest
3435

36+
strategy:
37+
fail-fast: false
38+
3539
services:
3640
redis:
3741
image: redis

ruby/ci-queue.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Gem::Specification.new do |spec|
3232
spec.add_development_dependency 'bundler'
3333
spec.add_development_dependency 'rake'
3434
spec.add_development_dependency 'minitest', ENV.fetch('MINITEST_VERSION', '~> 5.11')
35-
spec.add_development_dependency 'rspec', '~> 3.7.0'
35+
spec.add_development_dependency 'rspec', '~> 3.10'
3636
spec.add_development_dependency 'redis'
3737
spec.add_development_dependency 'simplecov', '~> 0.12'
3838
spec.add_development_dependency 'minitest-reporters', '~> 1.1'

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ def exhausted?
2121
end
2222

2323
def size
24-
redis.multi do
25-
redis.llen(key('queue'))
26-
redis.zcard(key('running'))
24+
redis.multi do |transaction|
25+
transaction.llen(key('queue'))
26+
transaction.zcard(key('running'))
2727
end.inject(:+)
2828
end
2929

3030
def to_a
31-
redis.multi do
32-
redis.lrange(key('queue'), 0, -1)
33-
redis.zrange(key('running'), 0, -1)
31+
redis.multi do |transaction|
32+
transaction.lrange(key('queue'), 0, -1)
33+
transaction.zrange(key('running'), 0, -1)
3434
end.flatten.reverse.map { |k| index.fetch(k) }
3535
end
3636

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ def failed_tests
2222
end
2323

2424
def pop_warnings
25-
warnings = redis.multi do
26-
redis.lrange(key('warnings'), 0, -1)
27-
redis.del(key('warnings'))
25+
warnings = redis.multi do |transaction|
26+
transaction.lrange(key('warnings'), 0, -1)
27+
transaction.del(key('warnings'))
2828
end.first
2929

3030
warnings.map { |p| Marshal.load(p) }
@@ -35,21 +35,21 @@ def record_warning(type, attributes)
3535
end
3636

3737
def record_error(id, payload, stats: nil)
38-
redis.pipelined do
39-
redis.hset(
38+
redis.pipelined do |pipeline|
39+
pipeline.hset(
4040
key('error-reports'),
4141
id.dup.force_encoding(Encoding::BINARY),
4242
payload.dup.force_encoding(Encoding::BINARY),
4343
)
44-
record_stats(stats)
44+
record_stats(stats, pipeline: pipeline)
4545
end
4646
nil
4747
end
4848

4949
def record_success(id, stats: nil)
50-
redis.pipelined do
51-
redis.hdel(key('error-reports'), id.dup.force_encoding(Encoding::BINARY))
52-
record_stats(stats)
50+
redis.pipelined do |pipeline|
51+
pipeline.hdel(key('error-reports'), id.dup.force_encoding(Encoding::BINARY))
52+
record_stats(stats, pipeline: pipeline)
5353
end
5454
nil
5555
end
@@ -65,8 +65,8 @@ def error_reports
6565
end
6666

6767
def fetch_stats(stat_names)
68-
counts = redis.pipelined do
69-
stat_names.each { |c| redis.hvals(key(c)) }
68+
counts = redis.pipelined do |pipeline|
69+
stat_names.each { |c| pipeline.hvals(key(c)) }
7070
end
7171
sum_counts = counts.map do |values|
7272
values.map(&:to_f).inject(:+).to_f
@@ -75,9 +75,9 @@ def fetch_stats(stat_names)
7575
end
7676

7777
def reset_stats(stat_names)
78-
redis.pipelined do
78+
redis.pipelined do |pipeline|
7979
stat_names.each do |stat_name|
80-
redis.hdel(key(stat_name), config.worker_id)
80+
pipeline.hdel(key(stat_name), config.worker_id)
8181
end
8282
end
8383
end
@@ -86,10 +86,10 @@ def reset_stats(stat_names)
8686

8787
attr_reader :config, :redis
8888

89-
def record_stats(stats)
89+
def record_stats(stats, pipeline: redis)
9090
return unless stats
9191
stats.each do |stat_name, stat_value|
92-
redis.hset(key(stat_name), config.worker_id, stat_value)
92+
pipeline.hset(key(stat_name), config.worker_id, stat_value)
9393
end
9494
end
9595

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ def initialize(queue, redis, config)
1111
end
1212

1313
def record_error(payload, stats: nil)
14-
redis.pipelined do
15-
redis.lpush(
14+
redis.pipelined do |pipeline|
15+
pipeline.lpush(
1616
key('error-reports'),
1717
payload.force_encoding(Encoding::BINARY),
1818
)
19-
record_stats(stats)
19+
record_stats(stats, pipeline: pipeline)
2020
end
2121
nil
2222
end
@@ -34,8 +34,8 @@ def error_reports
3434
end
3535

3636
def fetch_stats(stat_names)
37-
counts = redis.pipelined do
38-
stat_names.each { |c| redis.hvals(key(c)) }
37+
counts = redis.pipelined do |pipeline|
38+
stat_names.each { |c| pipeline.hvals(key(c)) }
3939
end
4040
stat_names.zip(counts.map { |values| values.map(&:to_f).inject(:+).to_f }).to_h
4141
end
@@ -54,10 +54,10 @@ def key(*args)
5454
['build', config.build_id, *args].join(':')
5555
end
5656

57-
def record_stats(stats)
57+
def record_stats(stats, pipeline: redis)
5858
return unless stats
5959
stats.each do |stat_name, stat_value|
60-
redis.hset(key(stat_name), config.worker_id, stat_value)
60+
pipeline.hset(key(stat_name), config.worker_id, stat_value)
6161
end
6262
end
6363
end

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

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ def fetch
1919
attr_reader :redis
2020

2121
def record_test_time(test_name, duration)
22-
redis.pipelined do
23-
redis.lpush(
22+
redis.pipelined do |pipeline|
23+
pipeline.lpush(
2424
test_time_key(test_name),
2525
duration.to_s.force_encoding(Encoding::BINARY),
2626
)
@@ -29,8 +29,8 @@ def record_test_time(test_name, duration)
2929
end
3030

3131
def record_test_name(test_name)
32-
redis.pipelined do
33-
redis.lpush(
32+
redis.pipelined do |pipeline|
33+
pipeline.lpush(
3434
all_test_names_key,
3535
test_name.dup.force_encoding(Encoding::BINARY),
3636
)
@@ -39,18 +39,15 @@ def record_test_name(test_name)
3939
end
4040

4141
def fetch_all_test_names
42-
values = redis.pipelined do
43-
redis.lrange(all_test_names_key, 0, -1)
42+
values = redis.pipelined do |pipeline|
43+
pipeline.lrange(all_test_names_key, 0, -1)
4444
end
4545
values.flatten.map(&:to_s)
4646
end
4747

4848
def fetch_test_time(test_name)
49-
values = redis.pipelined do
50-
key = test_time_key(test_name)
51-
redis.lrange(key, 0, -1)
52-
end
53-
values.flatten.map(&:to_f)
49+
key = test_time_key(test_name)
50+
redis.lrange(key, 0, -1).map(&:to_f)
5451
end
5552

5653
def all_test_names_key

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,10 @@ def push(tests)
194194
@total = tests.size
195195

196196
if @master = redis.setnx(key('master-status'), 'setup')
197-
redis.multi do
198-
redis.lpush(key('queue'), tests) unless tests.empty?
199-
redis.set(key('total'), @total)
200-
redis.set(key('master-status'), 'ready')
197+
redis.multi do |transaction|
198+
transaction.lpush(key('queue'), tests) unless tests.empty?
199+
transaction.set(key('total'), @total)
200+
transaction.set(key('master-status'), 'ready')
201201
end
202202
end
203203
register

ruby/test/integration/rspec_redis_test.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -381,18 +381,14 @@ def test_world_wants_to_quit
381381
assert_empty err
382382
expected_output = strip_heredoc <<-EOS
383383
384-
Randomized with seed 123
385-
386384
387385
Finished in X.XXXXX seconds (files took X.XXXXX seconds to load)
388386
0 examples, 0 failures
389387
390-
Randomized with seed 123
391-
392388
EOS
393389
assert_equal expected_output, normalize(out)
394390

395-
assert_equal 0, $?.exitstatus
391+
assert_equal 1, $?.exitstatus
396392

397393

398394
out, err = capture_subprocess_io do

0 commit comments

Comments
 (0)