forked from resque/resque
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathredis_queue_test.rb
More file actions
131 lines (102 loc) · 2.06 KB
/
redis_queue_test.rb
File metadata and controls
131 lines (102 loc) · 2.06 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
require 'test_helper'
require 'resque/queue'
describe "Resque::Queue" do
class Thing
attr_reader :inside
def initialize
@inside = "x"
end
def == other
super || @inside == other.inside
end
end
before do
Resque.redis.flushall
end
it "generates a redis_name" do
assert_equal "queue:foo", q.redis_name
end
it "acts sanely" do
queue = q
x = Thing.new
queue.push x
assert_equal x, queue.pop
end
it "blocks on pop" do
queue1 = q
queue2 = q
t = Thread.new { queue1.pop }
x = Thing.new
queue2.push x
assert_equal x, t.join.value
end
it "nonblocking pop works" do
queue1 = q
x = Thing.new
queue1 << x
assert_equal x, queue1.pop
end
it "nonblocking pop doesn't block" do
queue1 = q
assert_raises ThreadError do
queue1.pop(true)
end
end
it "blocks forever on pop" do
queue1 = q
assert_raises Timeout::Error do
Timeout.timeout(2) { queue1.pop }
end
end
it "#size" do
queue = q
begin
assert_equal 0, queue.size
queue << Thing.new
assert_equal 1, queue.size
ensure
queue.pop
end
end
it "#empty?" do
queue = q
begin
assert queue.empty?
queue << Thing.new
refute queue.empty?
ensure
queue.pop
end
end
it "registers itself with Resque" do
q
assert_equal ["foo"], Resque.queues
end
it "cleans up after itself when destroyed" do
queue = q
queue << Thing.new
q.destroy
assert_equal [], Resque.queues
assert !Resque.redis.exists(queue.redis_name)
end
it "returns false if a queue is not destroyed" do
assert !q.destroyed?
end
it "returns true if a queue is destroyed" do
queue1 = q
queue1.destroy
assert queue1.destroyed?
end
it "can't push to queue after destroying it" do
queue1 = q
x = Thing.new
queue1 << x
queue1.destroy
assert_raises Resque::QueueDestroyed do
queue1 << x
end
end
def q
Resque::Queue.new 'foo', Resque.redis
end
end