Skip to content

Commit b698648

Browse files
committed
conform test to the rest of the suite
1 parent 44aa588 commit b698648

File tree

1 file changed

+50
-46
lines changed

1 file changed

+50
-46
lines changed

test/redis_queue_test.rb

Lines changed: 50 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,86 @@
11
require 'test_helper'
22
require 'resque/queue'
33

4-
module Resque
5-
class TestQueue < MiniTest::Unit::TestCase
6-
include Test::Unit::Assertions
4+
describe "Resque::Queue" do
5+
include Test::Unit::Assertions
76

8-
class Thing
9-
attr_reader :inside
7+
class Thing
8+
attr_reader :inside
109

11-
def initialize
12-
@inside = "x"
13-
end
14-
15-
def == other
16-
super || @inside == other.inside
17-
end
10+
def initialize
11+
@inside = "x"
1812
end
1913

20-
def test_sanity
21-
queue = q
22-
x = Thing.new
23-
queue.push x
24-
assert_equal x, queue.pop
14+
def == other
15+
super || @inside == other.inside
2516
end
17+
end
2618

27-
def test_pop_blocks
28-
queue1 = q
29-
queue2 = q
19+
it "acts sanely" do
20+
queue = q
21+
x = Thing.new
22+
queue.push x
23+
assert_equal x, queue.pop
24+
end
3025

31-
t = Thread.new { queue1.pop }
32-
x = Thing.new
26+
it "blocks on pop" do
27+
queue1 = q
28+
queue2 = q
3329

34-
queue2.push x
35-
assert_equal x, t.join.value
36-
end
30+
t = Thread.new { queue1.pop }
31+
x = Thing.new
3732

38-
def test_nonblock_pop
39-
queue1 = q
33+
queue2.push x
34+
assert_equal x, t.join.value
35+
end
36+
37+
it "nonblocking pop works" do
38+
queue1 = q
4039

41-
assert_raises ThreadError do
42-
queue1.pop(true)
43-
end
40+
assert_raises ThreadError do
41+
queue1.pop(true)
4442
end
43+
end
4544

46-
def test_pop_blocks_forever
47-
queue1 = q
48-
assert_raises Timeout::Error do
49-
Timeout.timeout(2) { queue1.pop }
50-
end
45+
it "blocks forever on pop" do
46+
queue1 = q
47+
assert_raises Timeout::Error do
48+
Timeout.timeout(2) { queue1.pop }
5149
end
50+
end
5251

53-
def test_size
54-
queue = q
52+
it "#size" do
53+
queue = q
54+
55+
begin
5556
assert_equal 0, queue.size
5657

5758
queue << Thing.new
5859
assert_equal 1, queue.size
5960
ensure
6061
queue.pop
6162
end
63+
end
6264

63-
def test_empty?
64-
queue = q
65+
it "#empty?" do
66+
queue = q
67+
68+
begin
6569
assert queue.empty?
6670

6771
queue << Thing.new
6872
refute queue.empty?
6973
ensure
7074
queue.pop
7175
end
76+
end
7277

73-
def q
74-
Queue.new 'foo', backend
75-
end
78+
def q
79+
Resque::Queue.new 'foo', backend
80+
end
7681

77-
def backend
78-
redis = Redis.new(:host => "127.0.0.1", :port => 9736)
79-
Redis::Namespace.new :resque, :redis => redis
80-
end
82+
def backend
83+
redis = Redis.new(:host => "127.0.0.1", :port => 9736)
84+
Redis::Namespace.new :resque, :redis => redis
8185
end
8286
end

0 commit comments

Comments
 (0)