forked from redis/redis-rb
-
Notifications
You must be signed in to change notification settings - Fork 10
/
distributed_blocking_commands_test.rb
53 lines (40 loc) · 1.24 KB
/
distributed_blocking_commands_test.rb
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
# encoding: UTF-8
require File.expand_path("./helper", File.dirname(__FILE__))
require "redis/distributed"
setup do
log = StringIO.new
init Redis::Distributed.new(NODES, :logger => ::Logger.new(log))
end
test "BLPOP" do |r|
r.lpush("foo", "s1")
r.lpush("foo", "s2")
wire = Wire.new do
redis = Redis::Distributed.new(NODES)
Wire.sleep 0.3
redis.lpush("foo", "s3")
end
assert ["foo", "s2"] == r.blpop("foo", :timeout => 1)
assert ["foo", "s1"] == r.blpop("foo", :timeout => 1)
assert ["foo", "s3"] == r.blpop("foo", :timeout => 1)
wire.join
end
test "BRPOP" do |r|
r.rpush("foo", "s1")
r.rpush("foo", "s2")
wire = Wire.new do
redis = Redis::Distributed.new(NODES)
Wire.sleep 0.3
redis.rpush("foo", "s3")
end
assert ["foo", "s2"] == r.brpop("foo", :timeout => 1)
assert ["foo", "s1"] == r.brpop("foo", :timeout => 1)
assert ["foo", "s3"] == r.brpop("foo", :timeout => 1)
wire.join
end
test "BRPOP should unset a configured socket timeout" do |r|
r = Redis::Distributed.new(NODES, :timeout => 1)
assert_nothing_raised do
r.brpop("foo", :timeout => 2)
end # Errno::EAGAIN raised if socket times out before redis command times out
assert r.nodes.all? { |node| node.client.timeout == 1 }
end