1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
# frozen_string_literal: true
require_relative 'helper'
require_relative 'lint/blocking_commands'
class TestBlockingCommands < Minitest::Test
include Helper::Client
include Lint::BlockingCommands
def assert_takes_longer_than_client_timeout
timeout = LOW_TIMEOUT
delay = timeout * 5
mock(delay: delay) do |r|
t1 = Time.now
yield(r)
t2 = Time.now
assert timeout == r._client.timeout
assert delay <= (t2 - t1)
end
end
def test_blpop_disable_client_timeout
assert_takes_longer_than_client_timeout do |r|
assert_equal %w[foo 0], r.blpop('foo')
end
end
def test_brpop_disable_client_timeout
assert_takes_longer_than_client_timeout do |r|
assert_equal %w[foo 0], r.brpop('foo')
end
end
def test_brpoplpush_disable_client_timeout
assert_takes_longer_than_client_timeout do |r|
assert_equal '0', r.brpoplpush('foo', 'bar')
end
end
def test_brpoplpush_in_transaction
results = r.multi do
r.brpoplpush('foo', 'bar')
r.brpoplpush('foo', 'bar', timeout: 2)
end
assert_equal [nil, nil], results
end
def test_brpoplpush_in_pipeline
mock do |r|
results = r.pipelined do
r.brpoplpush('foo', 'bar')
r.brpoplpush('foo', 'bar', timeout: 2)
end
assert_equal ['0', '2'], results
end
end
end
|