Skip to content

Commit efd037d

Browse files
authored
test: fix memory profiling settings (#175)
2 parents 2a48105 + 273aa5f commit efd037d

File tree

10 files changed

+54
-27
lines changed

10 files changed

+54
-27
lines changed

.github/workflows/test.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,8 @@ jobs:
348348
timeout-minutes: 15
349349
strategy:
350350
fail-fast: false
351+
matrix:
352+
mode: ['single', 'excessive_pipelining', 'pipelining_in_moderation']
351353
runs-on: ubuntu-latest
352354
env:
353355
REDIS_VERSION: '7.0.1'
@@ -370,5 +372,7 @@ jobs:
370372
run: docker compose -f $DOCKER_COMPOSE_FILE ps
371373
- name: Run memory profiler
372374
run: bundle exec rake prof
375+
env:
376+
MEMORY_PROFILE_MODE: ${{ matrix.mode }}
373377
- name: Stop containers
374378
run: docker compose -f $DOCKER_COMPOSE_FILE down

.rubocop.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require:
88
AllCops:
99
TargetRubyVersion: 2.7
1010
DisplayCopNames: true
11-
NewCops: enable
11+
NewCops: disable
1212

1313
Metrics/AbcSize:
1414
Exclude:

test/benchmark_mixin.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def setup
1010
end
1111

1212
def teardown
13-
@client.call('FLUSHDB')
13+
@client&.call('FLUSHDB')
1414
wait_for_replication
1515
@client&.close
1616
end
@@ -74,7 +74,7 @@ def bench_pipeline_get
7474
def wait_for_replication
7575
client_side_timeout = TEST_TIMEOUT_SEC + 1.0
7676
server_side_timeout = (TEST_TIMEOUT_SEC * 1000).to_i
77-
@client.blocking_call(client_side_timeout, 'WAIT', TEST_REPLICA_SIZE, server_side_timeout)
77+
@client&.blocking_call(client_side_timeout, 'WAIT', TEST_REPLICA_SIZE, server_side_timeout)
7878
end
7979
end
8080

@@ -87,7 +87,7 @@ def setup
8787
end
8888

8989
def teardown
90-
@cluster_client.call('FLUSHDB')
90+
@cluster_client&.call('FLUSHDB')
9191
wait_for_replication
9292
@cluster_client&.close
9393
@client&.close
@@ -102,6 +102,6 @@ def new_cluster_client
102102
def wait_for_replication
103103
client_side_timeout = TEST_TIMEOUT_SEC + 1.0
104104
server_side_timeout = (TEST_TIMEOUT_SEC * 1000).to_i
105-
@cluster_client.blocking_call(client_side_timeout, 'WAIT', TEST_REPLICA_SIZE, server_side_timeout)
105+
@cluster_client&.blocking_call(client_side_timeout, 'WAIT', TEST_REPLICA_SIZE, server_side_timeout)
106106
end
107107
end

test/cluster_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ def flush_all_data(clients)
253253
clients.each do |c|
254254
c.call('FLUSHALL')
255255
print_debug("#{c.config.host}:#{c.config.port} ... FLUSHALL")
256-
rescue ::RedisClient::CommandError
256+
rescue ::RedisClient::CommandError, ::RedisClient::ReadOnlyError
257257
# READONLY You can't write against a read only replica.
258258
nil
259259
end

test/prof_mem.rb

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,48 @@ module ProfMem
88
module_function
99

1010
ATTEMPT_COUNT = 1000
11+
MAX_PIPELINE_SIZE = 30
12+
SLICED_NUMBERS = Array.new(ATTEMPT_COUNT) { |i| i }.each_slice(MAX_PIPELINE_SIZE).freeze
13+
CLI_TYPES = %w[primary_only scale_read_random scale_read_latency pooled].freeze
14+
MODES = {
15+
single: lambda do |client_builder_method|
16+
cli = send(client_builder_method)
17+
ATTEMPT_COUNT.times { |i| cli.call('SET', i, i) }
18+
ATTEMPT_COUNT.times { |i| cli.call('GET', i) }
19+
end,
20+
excessive_pipelining: lambda do |client_builder_method|
21+
cli = send(client_builder_method)
22+
cli.pipelined do |pi|
23+
ATTEMPT_COUNT.times { |i| pi.call('SET', i, i) }
24+
end
1125

12-
def run
13-
%w[primary_only scale_read_random scale_read_latency pooled].each do |cli_type|
14-
prepare
15-
print_letter(cli_type, 'w/ pipelining')
16-
profile do
17-
send("new_#{cli_type}_client".to_sym).pipelined do |pi|
18-
ATTEMPT_COUNT.times { |i| pi.call('SET', i, i) }
19-
ATTEMPT_COUNT.times { |i| pi.call('GET', i) }
26+
cli.pipelined do |pi|
27+
ATTEMPT_COUNT.times { |i| pi.call('GET', i) }
28+
end
29+
end,
30+
pipelining_in_moderation: lambda do |client_builder_method|
31+
cli = send(client_builder_method)
32+
SLICED_NUMBERS.each do |numbers|
33+
cli.pipelined do |pi|
34+
numbers.each { |i| pi.call('SET', i, i) }
35+
end
36+
37+
cli.pipelined do |pi|
38+
numbers.each { |i| pi.call('GET', i) }
2039
end
2140
end
41+
end
42+
}.freeze
2243

44+
def run
45+
mode = ENV.fetch('MEMORY_PROFILE_MODE', :single).to_sym
46+
subject = MODES.fetch(mode)
47+
48+
CLI_TYPES.each do |cli_type|
2349
prepare
24-
print_letter(cli_type, 'w/o pipelining')
25-
profile do
26-
cli = send("new_#{cli_type}_client".to_sym)
27-
ATTEMPT_COUNT.times { |i| cli.call('SET', i, i) }
28-
ATTEMPT_COUNT.times { |i| cli.call('GET', i) }
29-
end
50+
print_letter(mode, cli_type)
51+
client_builder_method = "new_#{cli_type}_client".to_sym
52+
profile { subject.call(client_builder_method) }
3053
end
3154
end
3255

test/redis_client/cluster/test_normalized_cmd_name.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def setup
1111
end
1212

1313
def teardown
14-
@subject.clear
14+
@subject&.clear
1515
end
1616

1717
def test_get_by_command

test/redis_client/test_cluster.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ def test_compatibility_with_redis_gem
253253
def wait_for_replication
254254
client_side_timeout = TEST_TIMEOUT_SEC + 1.0
255255
server_side_timeout = (TEST_TIMEOUT_SEC * 1000).to_i
256-
@client.blocking_call(client_side_timeout, 'WAIT', TEST_REPLICA_SIZE, server_side_timeout)
256+
@client&.blocking_call(client_side_timeout, 'WAIT', TEST_REPLICA_SIZE, server_side_timeout)
257257
end
258258
end
259259

test/test_against_cluster_broken.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ def setup
2020
end
2121

2222
def teardown
23-
@client.close
24-
@controller.close
23+
@client&.close
24+
@controller&.close
2525
end
2626

2727
def test_a_replica_is_down

test/test_against_cluster_state.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ def setup
1717
end
1818

1919
def teardown
20-
@controller.close
21-
@client.close
20+
@controller&.close
21+
@client&.close
2222
end
2323

2424
def test_the_state_of_cluster_down

test/test_concurrency.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def setup
1313
end
1414

1515
def teardown
16-
@client.close
16+
@client&.close
1717
end
1818

1919
def test_forking

0 commit comments

Comments
 (0)