beaneater 1.3.1 → 1.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/test/tubes_test.rb DELETED
@@ -1,194 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # test/tubes_test.rb
4
-
5
- require File.expand_path('../test_helper', __FILE__)
6
-
7
- describe Beaneater::Tubes do
8
- describe "for #find" do
9
- before do
10
- @beanstalk = stub
11
- @tubes = Beaneater::Tubes.new(@beanstalk)
12
- end
13
-
14
- it("should return Tube obj") { assert_kind_of Beaneater::Tube, @tubes.find(:foo) }
15
- it("should return Tube name") { assert_equal "foo", @tubes.find(:foo).name }
16
- it("should support hash syntax") { assert_equal "bar", @tubes["bar"].name }
17
- end # find
18
-
19
- describe "for #use" do
20
- before do
21
- @beanstalk = Beaneater.new('localhost')
22
- end
23
-
24
- it "should switch to used tube for valid name" do
25
- Beaneater::Tube.new(@beanstalk, 'some_name')
26
- @beanstalk.tubes.use('some_name')
27
- assert_equal 'some_name', @beanstalk.tubes.used.name
28
- end
29
-
30
- it "should raise for invalid tube name" do
31
- assert_raises(Beaneater::InvalidTubeName) { @beanstalk.tubes.use('; ') }
32
- end
33
- end # use
34
-
35
- describe "for #watch & #watched" do
36
- before do
37
- @beanstalk = Beaneater.new('localhost')
38
- end
39
-
40
- it 'should watch specified tubes' do
41
- @beanstalk.tubes.watch('foo')
42
- @beanstalk.tubes.watch('bar')
43
- assert_equal ['default', 'foo', 'bar'].sort, @beanstalk.tubes.watched.map(&:name).sort
44
- end
45
-
46
- it 'should raise invalid name for bad tube' do
47
- assert_raises(Beaneater::InvalidTubeName) { @beanstalk.tubes.watch('; ') }
48
- end
49
-
50
- it 'should remember each watched tube once, by name, for a reconnect to restore' do
51
- @beanstalk.tubes.watch('a')
52
- @beanstalk.tubes.watch('a')
53
- @beanstalk.tubes.watch(:a)
54
- assert_equal ['default', 'a'], @beanstalk.connection.tubes_watched
55
- end
56
- end # watch! & watched
57
-
58
- describe "for #all" do
59
- before do
60
- @beanstalk = Beaneater.new('localhost')
61
- @beanstalk.tubes.find('foo').put 'bar'
62
- @beanstalk.tubes.find('bar').put 'foo'
63
- end
64
-
65
- it 'should retrieve all tubes' do
66
- ['default', 'foo', 'bar'].each do |t|
67
- assert @beanstalk.tubes.all.map(&:name).include?(t)
68
- end
69
- end
70
-
71
- it 'should return tube names that look like numbers or dates as strings' do
72
- names = ['1.10', '2026-10-30', 'true', 'a-b']
73
- names.each { |t| @beanstalk.tubes.find(t).put 'x' }
74
- all = @beanstalk.tubes.all.map(&:name)
75
- names.each { |t| assert_includes all, t }
76
- end
77
- end # all
78
-
79
- describe "for Enumerable" do
80
- before do
81
- @beanstalk = Beaneater.new('localhost')
82
- @beanstalk.tubes.find('foo').put 'bar'
83
- @beanstalk.tubes.find('bar').put 'foo'
84
- end
85
-
86
- it 'should map tubes' do
87
- ['default', 'foo', 'bar'].each do |t|
88
- assert @beanstalk.tubes.map(&:name).include?(t)
89
- end
90
- end
91
- end
92
-
93
- describe "for #used" do
94
- before do
95
- @beanstalk = Beaneater.new('localhost')
96
- @beanstalk.tubes.find('foo').put 'bar'
97
- @beanstalk.tubes.find('bar').put 'foo'
98
- end
99
-
100
- it 'should retrieve used tube' do
101
- assert_equal 'bar', @beanstalk.tubes.used.name
102
- end
103
-
104
- it 'should support dashed tubes' do
105
- @beanstalk.tubes.find('der-bam').put 'foo'
106
- assert_equal 'der-bam', @beanstalk.tubes.used.name
107
- end
108
- end # used
109
-
110
- describe "for #watch!" do
111
- before do
112
- @beanstalk = Beaneater.new('localhost')
113
- end
114
-
115
- it 'should watch specified tubes' do
116
- @beanstalk.tubes.watch!(:foo)
117
- @beanstalk.tubes.watch!('bar')
118
- assert_equal ['bar'].sort, @beanstalk.tubes.watched.map(&:name).sort
119
- end
120
- end # watch!
121
-
122
- describe "for #ignore" do
123
- before do
124
- @beanstalk = Beaneater.new('localhost')
125
- end
126
-
127
- it 'should ignore specified tubes' do
128
- @beanstalk.tubes.watch('foo')
129
- @beanstalk.tubes.watch('bar')
130
- @beanstalk.tubes.ignore('foo')
131
- assert_equal ['default', 'bar'].sort, @beanstalk.tubes.watched.map(&:name).sort
132
- end
133
-
134
- it 'should forget an ignored tube however its name is given' do
135
- @beanstalk.tubes.watch('foo')
136
- @beanstalk.tubes.watch('bar')
137
- @beanstalk.tubes.ignore(:foo)
138
- assert_equal ['default', 'bar'], @beanstalk.connection.tubes_watched
139
- end
140
- end # ignore
141
-
142
- describe "for #reserve" do
143
- before do
144
- @beanstalk = Beaneater.new('localhost')
145
- @tube = @beanstalk.tubes.find 'tube'
146
- @time = Time.now.to_i
147
- @tube.put "foo reserve #{@time}"
148
- end
149
-
150
- it("should reserve job") do
151
- @beanstalk.tubes.watch 'tube'
152
- job = @beanstalk.tubes.reserve
153
- assert_equal "foo reserve #{@time}", job.body
154
- job.delete
155
- end
156
-
157
- it("should reserve job with block") do
158
- @beanstalk.tubes.watch 'tube'
159
- job = nil
160
- @beanstalk.tubes.reserve { |j| job = j; job.delete }
161
- assert_equal "foo reserve #{@time}", job.body
162
- end
163
-
164
- it("should reserve job with block and timeout") do
165
- @beanstalk.tubes.watch 'tube'
166
- job = nil
167
- @beanstalk.tubes.reserve(0) { |j| job = j; job.delete }
168
- assert_equal "foo reserve #{@time}", job.body
169
- end
170
-
171
- it "should raise TimedOutError with timeout" do
172
- @beanstalk.tubes.watch 'tube'
173
- @beanstalk.tubes.reserve(0) { |j| job = j; job.delete }
174
- assert_raises(Beaneater::TimedOutError) { @beanstalk.tubes.reserve(0) }
175
- end
176
-
177
- it "should raise DeadlineSoonError with ttr 1" do
178
- @tube.reserve.delete
179
- @tube.put "foo reserve #{@time}", :ttr => 1
180
- @beanstalk.tubes.watch 'tube'
181
- job = @beanstalk.tubes.reserve
182
- assert_raises(Beaneater::DeadlineSoonError) { @beanstalk.tubes.reserve(0) }
183
- ensure
184
- # left reserved, the job would be released (TTR, or the socket being collected) into a
185
- # later #reserve test
186
- begin
187
- job.delete if job
188
- rescue Beaneater::NotFoundError
189
- nil
190
- end
191
- end
192
-
193
- end # reserve
194
- end # Beaneater::Tubes