Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
supercaracal committed May 28, 2024
1 parent ff601e3 commit 5e3d2e0
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion test/benchmark_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,24 @@
when 'hiredis' then require 'hiredis-client'
end

class BenchmarkWrapper < Minitest::Benchmark; end
class BenchmarkWrapper < Minitest::Benchmark
private

def swap_timeout(client, timeout:)
return if client.nil?

node = client.instance_variable_get(:@router)&.instance_variable_get(:@node)
raise 'The client must be initialized.' if node.nil?

updater = lambda do |c, t|
c.read_timeout = t
c.config.instance_variable_set(:@read_timeout, t)
end

regular_timeout = node.first.read_timeout
node.each { |cli| updater.call(cli, timeout) }
result = yield client
node.each { |cli| updater.call(cli, regular_timeout) }
result
end
end

0 comments on commit 5e3d2e0

Please sign in to comment.