Skip to content

Commit

Permalink
test: no need to wait uselessly
Browse files Browse the repository at this point in the history
  • Loading branch information
supercaracal committed Sep 30, 2024
1 parent c4270ff commit 7869faa
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions test/test_against_cluster_broken.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class TestAgainstClusterBroken < TestingWrapper
WAIT_SEC = 0.1
MAX_ATTEMPTS = 100
NUMBER_OF_KEYS = 1600
NUMBER_OF_KEYS = 16_000
MAX_PIPELINE_SIZE = 40
HASH_TAG_GRAIN = 5
SLICED_NUMBERS = (0...NUMBER_OF_KEYS).each_slice(MAX_PIPELINE_SIZE).freeze
Expand Down Expand Up @@ -79,7 +79,7 @@ def prepare_test_data
def do_assertions(offset:)
log_info('assertions') do
log_info('assertions: single') do
(NUMBER_OF_KEYS / MAX_PIPELINE_SIZE).times do |i|
NUMBER_OF_KEYS.times do |i|
want = (i + offset).to_s
got = retryable { @clients[0].call_once('GET', "single:#{i}") }
assert_equal(want, got, 'Case: Single GET')
Expand Down Expand Up @@ -111,7 +111,7 @@ def do_assertions(offset:)
end

log_info('assertions: transaction') do
(NUMBER_OF_KEYS / (MAX_PIPELINE_SIZE / HASH_TAG_GRAIN)).times.group_by { |i| i / HASH_TAG_GRAIN }.each do |group, numbers|
NUMBER_OF_KEYS.times.group_by { |i| i / HASH_TAG_GRAIN }.each do |group, numbers|
want = numbers.map { 'OK' }
keys = numbers.map { |i| "{group#{group}}:transaction:#{i}" }
got = retryable do
Expand Down Expand Up @@ -179,17 +179,18 @@ def retryable(attempts: MAX_ATTEMPTS, wait_sec: WAIT_SEC)
break yield
rescue ::RedisClient::ConnectionError, ::RedisClient::Cluster::NodeMightBeDown
@cluster_down_error_count += 1
sleep wait_sec
rescue ::RedisClient::CommandError => e
raise unless e.message.start_with?('CLUSTERDOWN')

@cluster_down_error_count += 1
sleep wait_sec
rescue ::RedisClient::Cluster::ErrorCollection => e
raise unless e.errors.values.all? do |err|
err.message.start_with?('CLUSTERDOWN') || err.is_a?(::RedisClient::ConnectionError)
end

@cluster_down_error_count += 1
ensure
sleep wait_sec
end
end
Expand Down

0 comments on commit 7869faa

Please sign in to comment.