beanstalk_integration_tests 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +3 -0
- data/LICENSE +22 -0
- data/README.md +38 -0
- data/Rakefile +9 -0
- data/beanstalk_integration_tests.gemspec +26 -0
- data/lib/beanstalk_integration_tests.rb +2 -0
- data/lib/beanstalk_integration_tests/bury_test.rb +137 -0
- data/lib/beanstalk_integration_tests/delete_test.rb +160 -0
- data/lib/beanstalk_integration_tests/ignore_test.rb +127 -0
- data/lib/beanstalk_integration_tests/kick_job_test.rb +68 -0
- data/lib/beanstalk_integration_tests/kick_test.rb +207 -0
- data/lib/beanstalk_integration_tests/list_tube_used_test.rb +26 -0
- data/lib/beanstalk_integration_tests/list_tubes_test.rb +26 -0
- data/lib/beanstalk_integration_tests/list_tubes_watched_test.rb +26 -0
- data/lib/beanstalk_integration_tests/pause_tube_test.rb +166 -0
- data/lib/beanstalk_integration_tests/peek_test.rb +242 -0
- data/lib/beanstalk_integration_tests/put_test.rb +255 -0
- data/lib/beanstalk_integration_tests/quit_test.rb +24 -0
- data/lib/beanstalk_integration_tests/release_test.rb +191 -0
- data/lib/beanstalk_integration_tests/reserve_test.rb +385 -0
- data/lib/beanstalk_integration_tests/stats_job_test.rb +116 -0
- data/lib/beanstalk_integration_tests/stats_test.rb +130 -0
- data/lib/beanstalk_integration_tests/stats_tube_test.rb +141 -0
- data/lib/beanstalk_integration_tests/test_helper.rb +88 -0
- data/lib/beanstalk_integration_tests/tests.rb +4 -0
- data/lib/beanstalk_integration_tests/touch_test.rb +118 -0
- data/lib/beanstalk_integration_tests/use_test.rb +118 -0
- data/lib/beanstalk_integration_tests/version.rb +3 -0
- data/lib/beanstalk_integration_tests/watch_test.rb +128 -0
- metadata +157 -0
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'beanstalk_integration_tests/test_helper'
|
2
|
+
|
3
|
+
class KickJobTest < BeanstalkIntegrationTest
|
4
|
+
|
5
|
+
context 'kick-job' do
|
6
|
+
|
7
|
+
setup do
|
8
|
+
client.transmit("use #{tube_name}")
|
9
|
+
client.transmit("watch #{tube_name}")
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
should 'kick the specified buried job' do
|
14
|
+
message = uuid
|
15
|
+
{
|
16
|
+
'buried' => create_buried_jobs(1).first,
|
17
|
+
'delayed' => client.transmit("put 0 120 120 #{message.bytesize}\r\n#{message}")[:id],
|
18
|
+
}.each_pair do |job_state, job_id|
|
19
|
+
assert_equal job_state, client.transmit("stats-job #{job_id}")[:body]['state']
|
20
|
+
response = client.transmit("kick-job #{job_id}")
|
21
|
+
assert_equal 'KICKED', response[:status]
|
22
|
+
job_stats = client.transmit("stats-job #{job_id}")[:body]
|
23
|
+
assert_equal('ready', job_stats['state'], "Expected #{job_state} job to be ready after kick")
|
24
|
+
assert_equal(1, job_stats['kicks'], 'Expected job kicks to be incremented')
|
25
|
+
assert_equal tube_name, job_stats['tube']
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
should 'return NOT_FOUND if the job is not in a kickable state' do
|
31
|
+
message = uuid
|
32
|
+
job_id = client.transmit("put 0 0 120 #{message.bytesize}\r\n#{message}")[:id]
|
33
|
+
response = nil
|
34
|
+
assert_raises(Beaneater::NotFoundError, 'Expected kicking unkickable job to return NOT_FOUND') do
|
35
|
+
response = client.transmit("kick-job #{job_id}")
|
36
|
+
end
|
37
|
+
assert_equal(0, client.transmit("stats-job #{job_id}")[:body]['kicks'], 'Expected job kicks to be unchanged')
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
should 'return UNKNOWN_COMMAND unless command followed by space' do
|
42
|
+
assert_raises(Beaneater::UnknownCommandError, 'Expected kick-job without a space to return UNKNOWN_COMMAND') do
|
43
|
+
client.transmit('kick-job')
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
should 'return NOT_FOUND when job_id is null, negative, or non-integer' do
|
49
|
+
['', -1, 'x'].each do |job_id|
|
50
|
+
assert_raises(Beaneater::NotFoundError, 'Expected kick-job with bad job id to return NOT_FOUND') do
|
51
|
+
client.transmit("kick-job #{job_id}")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
should 'ignore trailing space, arguments, and chars' do
|
58
|
+
[' ', ' and ignore these arguments', '_and_ignore_these_letters'].each do |trailer|
|
59
|
+
job_id = create_buried_jobs(1).first
|
60
|
+
client.transmit("kick-job #{job_id}#{trailer}")
|
61
|
+
assert_equal 1, client.transmit("stats-job #{job_id}")[:body]['kicks']
|
62
|
+
client.transmit("delete #{job_id}")
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
@@ -0,0 +1,207 @@
|
|
1
|
+
require 'beanstalk_integration_tests/test_helper'
|
2
|
+
|
3
|
+
class KickTest < BeanstalkIntegrationTest
|
4
|
+
|
5
|
+
context 'kick' do
|
6
|
+
|
7
|
+
setup do
|
8
|
+
client.transmit("watch #{tube_name}")
|
9
|
+
client.transmit("use #{tube_name}")
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
should 'return UNKNOWN_COMMAND without a space following the command' do
|
14
|
+
initial_cmd_kick = client.transmit('stats')[:body]['cmd-kick']
|
15
|
+
assert_raises(Beaneater::UnknownCommandError, 'Expected kick without a space to return UNKNOWN_COMMAND') do
|
16
|
+
client.transmit('kick')
|
17
|
+
end
|
18
|
+
assert_equal(initial_cmd_kick, client.transmit('stats')[:body]['cmd-kick'], 'Expected cmd-kick to be unchanged')
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
should 'return BAD_FORMAT with a null or non-integer bound' do
|
23
|
+
initial_cmd_kick = client.transmit('stats')[:body]['cmd-kick']
|
24
|
+
['', 'foo'].each do |bound|
|
25
|
+
assert_raises(Beaneater::BadFormatError, 'Expected kick with an invalid bound to return BAD_FORMAT') do
|
26
|
+
client.transmit("kick #{bound}")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
assert_equal(initial_cmd_kick, client.transmit('stats')[:body]['cmd-kick'], 'Expected cmd-kick to be unchanged')
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
should 'kick 0 jobs if bound <= 0' do
|
34
|
+
initial_cmd_kick = client.transmit('stats')[:body]['cmd-kick']
|
35
|
+
[0, -5].each_with_index do |bound, index|
|
36
|
+
response = client.transmit("kick #{bound}")
|
37
|
+
assert_equal 'KICKED', response[:status]
|
38
|
+
assert_equal '0', response[:id]
|
39
|
+
assert_equal(initial_cmd_kick + index + 1, client.transmit('stats')[:body]['cmd-kick'], 'Expected cmd-kick to be incremented')
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
should 'kick 0 jobs if no jobs to kick' do
|
45
|
+
initial_cmd_kick = client.transmit('stats')[:body]['cmd-kick']
|
46
|
+
response = client.transmit('kick 1000')
|
47
|
+
assert_equal 'KICKED', response[:status]
|
48
|
+
assert_equal '0', response[:id]
|
49
|
+
assert_equal(initial_cmd_kick + 1, client.transmit('stats')[:body]['cmd-kick'], 'Expected cmd-kick to be incremented')
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
should 'only kick jobs in the currently used tube' do
|
54
|
+
initial_cmd_kick = client.transmit('stats')[:body]['cmd-kick']
|
55
|
+
create_buried_jobs
|
56
|
+
5.times do
|
57
|
+
message = uuid
|
58
|
+
client.transmit("put 0 120 120 #{message.bytesize}\r\n#{message}")
|
59
|
+
end
|
60
|
+
other_client = build_client
|
61
|
+
response = other_client.transmit('kick 1000')
|
62
|
+
assert_equal 'KICKED', response[:status]
|
63
|
+
assert_equal '0', response[:id]
|
64
|
+
assert_equal(initial_cmd_kick + 1, client.transmit('stats')[:body]['cmd-kick'], 'Expected cmd-kick to be incremented')
|
65
|
+
assert_equal 0, client.transmit('stats')[:body]['current-jobs-ready']
|
66
|
+
other_client.transmit("use #{tube_name}")
|
67
|
+
other_client.transmit('kick 5')
|
68
|
+
other_client.transmit('kick 5')
|
69
|
+
assert_equal 10, other_client.transmit('stats')[:body]['current-jobs-ready']
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
should 'ignore trailing space, arguments, and chars' do
|
74
|
+
create_buried_jobs
|
75
|
+
initial_cmd_kick = client.transmit('stats')[:body]['cmd-kick']
|
76
|
+
[' ', ' and ignore these arguments', '_and_ignore_these_letters'].each do |trailer|
|
77
|
+
response = client.transmit("kick 1#{trailer}")
|
78
|
+
assert_equal 'KICKED', response[:status]
|
79
|
+
assert_equal '1', response[:id]
|
80
|
+
job_id = client.transmit('peek-ready')[:id]
|
81
|
+
assert_equal 1, client.transmit("stats-job #{job_id}")[:body]['kicks']
|
82
|
+
client.transmit("delete #{job_id}")
|
83
|
+
end
|
84
|
+
assert_equal(initial_cmd_kick + 3, client.transmit('stats')[:body]['cmd-kick'], 'Expected cmd-kick to be incremented')
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
context 'buried jobs' do
|
89
|
+
should 'kick at most the requested number of jobs' do
|
90
|
+
buried_count = 9
|
91
|
+
job_ids = create_buried_jobs(buried_count)
|
92
|
+
stats = client.transmit('stats')[:body]
|
93
|
+
assert_equal buried_count, stats['current-jobs-buried']
|
94
|
+
assert_equal buried_count, client.transmit("stats-tube #{tube_name}")[:body]['current-jobs-buried']
|
95
|
+
initial_cmd_kick = stats['cmd-kick']
|
96
|
+
kicked = 0
|
97
|
+
[1, 2, 3].each do |slice_size|
|
98
|
+
client.transmit("kick #{slice_size}")
|
99
|
+
kicked += slice_size
|
100
|
+
stats = client.transmit('stats')[:body]
|
101
|
+
assert_equal buried_count - kicked, stats['current-jobs-buried']
|
102
|
+
assert_equal slice_size, stats['current-jobs-ready']
|
103
|
+
slice_size.times do
|
104
|
+
job_id = client.transmit('peek-ready')[:id]
|
105
|
+
assert_equal job_ids.shift, job_id
|
106
|
+
assert_equal(1, client.transmit("stats-job #{job_id}")[:body]['kicks'], 'Expected job kicks to be incremented')
|
107
|
+
client.transmit("delete #{job_id}")
|
108
|
+
end
|
109
|
+
end
|
110
|
+
# Kick 4 with only 3 remaining
|
111
|
+
client.transmit("kick 4")
|
112
|
+
assert_equal 0, client.transmit('stats')[:body]['current-jobs-buried']
|
113
|
+
assert_equal 3, client.transmit('stats')[:body]['current-jobs-ready']
|
114
|
+
assert_equal 0, client.transmit("stats-tube #{tube_name}")[:body]['current-jobs-buried']
|
115
|
+
3.times do
|
116
|
+
job_id = client.transmit('peek-ready')[:id]
|
117
|
+
assert_equal job_ids.shift, job_id
|
118
|
+
assert_equal(1, client.transmit("stats-job #{job_id}")[:body]['kicks'], 'Expected job kicks to be incremented')
|
119
|
+
client.transmit("delete #{job_id}")
|
120
|
+
end
|
121
|
+
|
122
|
+
assert_equal(initial_cmd_kick + 4, client.transmit('stats')[:body]['cmd-kick'], 'Expected cmd-kick to be incremented')
|
123
|
+
end
|
124
|
+
|
125
|
+
|
126
|
+
should 'kick only buried jobs if buried and delayed jobs available' do
|
127
|
+
buried_count = delayed_count = 3
|
128
|
+
buried_job_ids = create_buried_jobs(buried_count)
|
129
|
+
delayed_job_ids = []
|
130
|
+
delayed_count.times do
|
131
|
+
message = uuid
|
132
|
+
delayed_job_ids << client.transmit("put 0 120 120 #{message.bytesize}\r\n#{message}")[:id]
|
133
|
+
end
|
134
|
+
stats = client.transmit('stats')[:body]
|
135
|
+
assert_equal buried_count, stats['current-jobs-buried']
|
136
|
+
assert_equal delayed_count, stats['current-jobs-delayed']
|
137
|
+
initial_cmd_kick = stats['cmd-kick']
|
138
|
+
|
139
|
+
client.transmit("kick #{buried_count + delayed_count}")
|
140
|
+
stats = client.transmit('stats')[:body]
|
141
|
+
assert_equal 0, stats['current-jobs-buried']
|
142
|
+
assert_equal buried_count, stats['current-jobs-ready']
|
143
|
+
assert_equal delayed_count, stats['current-jobs-delayed']
|
144
|
+
buried_count.times do
|
145
|
+
job_id = client.transmit('peek-ready')[:id]
|
146
|
+
assert_equal buried_job_ids.shift, job_id
|
147
|
+
assert_equal(1, client.transmit("stats-job #{job_id}")[:body]['kicks'], 'Expected job kicks to be incremented')
|
148
|
+
client.transmit("delete #{job_id}")
|
149
|
+
end
|
150
|
+
delayed_count.times do
|
151
|
+
job_id = client.transmit('peek-delayed')[:id]
|
152
|
+
assert_equal delayed_job_ids.shift, job_id
|
153
|
+
assert_equal(0, client.transmit("stats-job #{job_id}")[:body]['kicks'], 'Expected job kicks to be unchanged')
|
154
|
+
client.transmit("delete #{job_id}")
|
155
|
+
end
|
156
|
+
|
157
|
+
assert_equal(initial_cmd_kick + 1, client.transmit('stats')[:body]['cmd-kick'], 'Expected cmd-kick to be incremented')
|
158
|
+
end
|
159
|
+
|
160
|
+
end
|
161
|
+
|
162
|
+
|
163
|
+
context 'delayed jobs' do
|
164
|
+
should 'kick at most the requested number of jobs' do
|
165
|
+
delayed_count = 9
|
166
|
+
job_ids = delayed_count.times.map do
|
167
|
+
message = uuid
|
168
|
+
client.transmit("put 0 120 120 #{message.bytesize}\r\n#{message}")[:id]
|
169
|
+
end
|
170
|
+
stats = client.transmit('stats')[:body]
|
171
|
+
assert_equal 0, stats['current-jobs-buried']
|
172
|
+
assert_equal delayed_count, stats['current-jobs-delayed']
|
173
|
+
assert_equal delayed_count, client.transmit("stats-tube #{tube_name}")[:body]['current-jobs-delayed']
|
174
|
+
initial_cmd_kick = stats['cmd-kick']
|
175
|
+
kicked = 0
|
176
|
+
[1, 2, 3].each do |slice_size|
|
177
|
+
client.transmit("kick #{slice_size}")
|
178
|
+
kicked += slice_size
|
179
|
+
stats = client.transmit('stats')[:body]
|
180
|
+
assert_equal delayed_count - kicked, stats['current-jobs-delayed']
|
181
|
+
assert_equal slice_size, stats['current-jobs-ready']
|
182
|
+
slice_size.times do
|
183
|
+
job_id = client.transmit('peek-ready')[:id]
|
184
|
+
assert_equal job_ids.shift, job_id
|
185
|
+
assert_equal(1, client.transmit("stats-job #{job_id}")[:body]['kicks'], 'Expected job kicks to be incremented')
|
186
|
+
client.transmit("delete #{job_id}")
|
187
|
+
end
|
188
|
+
end
|
189
|
+
# Kick 4 with only 3 remaining
|
190
|
+
client.transmit("kick 4")
|
191
|
+
assert_equal 0, client.transmit('stats')[:body]['current-jobs-delayed']
|
192
|
+
assert_equal 3, client.transmit('stats')[:body]['current-jobs-ready']
|
193
|
+
assert_equal 0, client.transmit("stats-tube #{tube_name}")[:body]['current-jobs-delayed']
|
194
|
+
3.times do
|
195
|
+
job_id = client.transmit('peek-ready')[:id]
|
196
|
+
assert_equal job_ids.shift, job_id
|
197
|
+
assert_equal(1, client.transmit("stats-job #{job_id}")[:body]['kicks'], 'Expected job kicks to be incremented')
|
198
|
+
client.transmit("delete #{job_id}")
|
199
|
+
end
|
200
|
+
|
201
|
+
assert_equal(initial_cmd_kick + 4, client.transmit('stats')[:body]['cmd-kick'], 'Expected cmd-kick to be incremented')
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
end
|
206
|
+
|
207
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'beanstalk_integration_tests/test_helper'
|
2
|
+
|
3
|
+
class ListTubeUsedTest < BeanstalkIntegrationTest
|
4
|
+
|
5
|
+
# Checking if tube is correctly maintained is handled by UseTest
|
6
|
+
|
7
|
+
context 'list-tube-used' do
|
8
|
+
|
9
|
+
should 'should update cmd-list-tube-used' do
|
10
|
+
initial_cmd_list_tube_used = client.transmit('stats')[:body]['cmd-list-tube-used']
|
11
|
+
client.transmit('list-tube-used')
|
12
|
+
assert_equal(initial_cmd_list_tube_used + 1, client.transmit('stats')[:body]['cmd-list-tube-used'], 'Expected cmd-list-tube-used to be incremented')
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
should 'return bad_format with trailing space or args' do
|
17
|
+
[' ', ' trailing_arg'].each do |trailer|
|
18
|
+
assert_raises(Beaneater::BadFormatError, 'Expected list-tubes with trailer to return BAD_FORMAT') do
|
19
|
+
client.transmit("list-tube-used#{trailer}")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'beanstalk_integration_tests/test_helper'
|
2
|
+
|
3
|
+
class ListTubesTest < BeanstalkIntegrationTest
|
4
|
+
|
5
|
+
# Checking if tubes are correctly added/removed is handled by UseTest and WatchTest
|
6
|
+
|
7
|
+
context 'list-tubes' do
|
8
|
+
|
9
|
+
should 'should update cmd-list-tubes' do
|
10
|
+
initial_cmd_list_tubes = client.transmit('stats')[:body]['cmd-list-tubes']
|
11
|
+
client.transmit('list-tubes')
|
12
|
+
assert_equal(initial_cmd_list_tubes + 1, client.transmit('stats')[:body]['cmd-list-tubes'], 'Expected cmd-list-tubes to be incremented')
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
should 'return bad_format with trailing space or args' do
|
17
|
+
[' ', ' trailing_arg'].each do |trailer|
|
18
|
+
assert_raises(Beaneater::BadFormatError, 'Expected list-tubes with trailer to return BAD_FORMAT') do
|
19
|
+
client.transmit("list-tubes#{trailer}")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'beanstalk_integration_tests/test_helper'
|
2
|
+
|
3
|
+
class ListTubesWatchedTest < BeanstalkIntegrationTest
|
4
|
+
|
5
|
+
# Checking if tubes are correctly added/removed is handled by WatchTest and IgnoreTest
|
6
|
+
|
7
|
+
context 'list-tubes-watched' do
|
8
|
+
|
9
|
+
should 'should update cmd-list-tubes-watched' do
|
10
|
+
initial_cmd_list_tubes_watched = client.transmit('stats')[:body]['cmd-list-tubes-watched']
|
11
|
+
client.transmit('list-tubes-watched')
|
12
|
+
assert_equal(initial_cmd_list_tubes_watched + 1, client.transmit('stats')[:body]['cmd-list-tubes-watched'], 'Expected cmd-list-tubes-watched to be incremented')
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
should 'return bad_format with trailing space or args' do
|
17
|
+
[' ', ' trailing_arg'].each do |trailer|
|
18
|
+
assert_raises(Beaneater::BadFormatError, 'Expected list-tubes-watched with trailer to return BAD_FORMAT') do
|
19
|
+
client.transmit("list-tubes-watched#{trailer}")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,166 @@
|
|
1
|
+
require 'beanstalk_integration_tests/test_helper'
|
2
|
+
|
3
|
+
class PauseTubeTest < BeanstalkIntegrationTest
|
4
|
+
|
5
|
+
context 'pause-tube' do
|
6
|
+
|
7
|
+
setup do
|
8
|
+
client.transmit("watch #{tube_name}")
|
9
|
+
client.transmit("use #{tube_name}")
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
should 'pause the provided tube for the provided delay' do
|
14
|
+
pause = 120
|
15
|
+
initial_tube_cmd_pause = client.transmit("stats-tube #{tube_name}")[:body]['cmd-pause-tube']
|
16
|
+
response = client.transmit("pause-tube #{tube_name} #{pause}")
|
17
|
+
assert_equal 'PAUSED', response[:status]
|
18
|
+
tube_stats = client.transmit("stats-tube #{tube_name}")[:body]
|
19
|
+
assert_equal pause, tube_stats['pause']
|
20
|
+
assert(tube_stats['pause-time-left'] < pause, 'Expected tube pause-time-left to be less than total pause time')
|
21
|
+
assert_equal(initial_tube_cmd_pause + 1, tube_stats['cmd-pause-tube'], 'Expected tube cmd-pause-tube to be incremented')
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
should 'should reduce large delays to mod 2**32' do
|
26
|
+
pause_overflow = 10
|
27
|
+
pause = 2**32 + pause_overflow
|
28
|
+
initial_tube_cmd_pause = client.transmit("stats-tube #{tube_name}")[:body]['cmd-pause-tube']
|
29
|
+
response = client.transmit("pause-tube #{tube_name} #{pause}")
|
30
|
+
assert_equal 'PAUSED', response[:status]
|
31
|
+
tube_stats = client.transmit("stats-tube #{tube_name}")[:body]
|
32
|
+
assert_equal pause_overflow, tube_stats['pause']
|
33
|
+
assert_equal(initial_tube_cmd_pause + 1, tube_stats['cmd-pause-tube'], 'Expected tube cmd-pause-tube to be incremented')
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
should 'activate a tube after the timeout has expired' do
|
38
|
+
pause = 1
|
39
|
+
initial_tube_cmd_pause = client.transmit("stats-tube #{tube_name}")[:body]['cmd-pause-tube']
|
40
|
+
response = client.transmit("pause-tube #{tube_name} #{pause}")
|
41
|
+
assert_equal 'PAUSED', response[:status]
|
42
|
+
sleep 1
|
43
|
+
tube_stats = client.transmit("stats-tube #{tube_name}")[:body]
|
44
|
+
assert_equal(0, tube_stats['pause'], 'Expected tube pause to reset after pause expired')
|
45
|
+
assert_equal(0, tube_stats['pause-time-left'], 'Expected tube pause-time-left to reset after pause expired')
|
46
|
+
assert_equal(initial_tube_cmd_pause + 1, tube_stats['cmd-pause-tube'], 'Expected tube cmd-pause-tube to be incremented')
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
should 'honor reservations as soon as pause expires' do
|
51
|
+
message = uuid
|
52
|
+
client.transmit("put 0 0 120 #{message.bytesize}\r\n#{message}")
|
53
|
+
client.transmit("pause-tube #{tube_name} 1")
|
54
|
+
|
55
|
+
tube_stats = client.transmit("stats-tube #{tube_name}")[:body]
|
56
|
+
assert(tube_stats['pause'] != 0, 'Expected tube to be paused')
|
57
|
+
assert_raises(Beaneater::TimedOutError, 'Expected reserve to fail while tube paused') do
|
58
|
+
client.transmit('reserve-with-timeout 0')
|
59
|
+
end
|
60
|
+
tube_stats = client.transmit("stats-tube #{tube_name}")[:body]
|
61
|
+
assert(tube_stats['pause'] != 0, 'Expected tube to be paused')
|
62
|
+
begin
|
63
|
+
job = client.transmit('reserve-with-timeout 2')
|
64
|
+
rescue Beaneater::TimedOutError => e
|
65
|
+
puts 'Tube did not honor reservation in expected period following pause'
|
66
|
+
raise e
|
67
|
+
end
|
68
|
+
assert_equal(message, job[:body], 'Did not reserve expected job')
|
69
|
+
client.transmit("delete #{job[:id]}")
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
should 'allow reservations while paused, but not reply' do
|
74
|
+
client.transmit("pause-tube #{tube_name} 120")
|
75
|
+
|
76
|
+
Thread.new do
|
77
|
+
other_client = build_client
|
78
|
+
other_client.transmit("watch #{tube_name}")
|
79
|
+
assert_raises('Beaneater::TimedOutError', 'Expected waiting for paused tube to timeout') do
|
80
|
+
other_client.transmit('reserve-with-timeout 2')
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
sleep 0.5
|
85
|
+
tube_stats = client.transmit("stats-tube #{tube_name}")[:body]
|
86
|
+
assert_equal(1, tube_stats['current-waiting'])
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
should 'accept jobs while paused' do
|
91
|
+
client.transmit("pause-tube #{tube_name} 120")
|
92
|
+
tube_stats = client.transmit("stats-tube #{tube_name}")[:body]
|
93
|
+
assert(tube_stats['pause'] != 0, 'Expected tube to be paused')
|
94
|
+
message = uuid
|
95
|
+
client.transmit("put 0 0 120 #{message.bytesize}\r\n#{message}")
|
96
|
+
assert_equal(1, client.transmit("stats-tube #{tube_name}")[:body]['current-jobs-ready'], 'Expected paused tube to accept put commands')
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
should 'return BAD_FORMAT without trailing space, tube name, or pause' do
|
101
|
+
['', ' ', " #{tube_name}"].each do |trailer|
|
102
|
+
assert_raises(Beaneater::BadFormatError, 'Expected pause-tube without space/tube name to return BAD_FORMAT') do
|
103
|
+
client.transmit("pause-tube#{trailer}")
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
|
109
|
+
should 'be able to handle tube name of maximum length' do
|
110
|
+
name = 'c' * 200
|
111
|
+
response = client.transmit("watch #{name}")
|
112
|
+
response = client.transmit("pause-tube #{name} 10")
|
113
|
+
assert_equal 'PAUSED', response[:status]
|
114
|
+
tube_stats = client.transmit("stats-tube #{name}")[:body]
|
115
|
+
assert(tube_stats['pause'] != 0, 'Expected tube to be paused')
|
116
|
+
end
|
117
|
+
|
118
|
+
|
119
|
+
should 'return BAD_FORMAT if tube name > 200 bytes' do
|
120
|
+
assert_raises Beaneater::BadFormatError do
|
121
|
+
client.transmit("pause-tube #{'x' * 201} 10")
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
|
126
|
+
should 'return BAD_FORMAT if line has a trailing space' do
|
127
|
+
initital_cmd_pause_tube = client.transmit("stats-tube #{tube_name}")[:body]['cmd-pause-tube']
|
128
|
+
assert_raises Beaneater::BadFormatError do
|
129
|
+
client.transmit("pause-tube #{tube_name} 10 ")
|
130
|
+
end
|
131
|
+
assert_equal(initital_cmd_pause_tube, client.transmit("stats-tube #{tube_name}")[:body]['cmd-pause-tube'], 'Expected cmd-pause-tube to be unchanged')
|
132
|
+
end
|
133
|
+
|
134
|
+
|
135
|
+
should 'return BAD_FORMAT if tube name includes invalid characters or starts with hyphen' do
|
136
|
+
valid_chars = ('a'..'z').to_a + ('A'..'Z').to_a + ('0'..'9').to_a + %w[- + / ; . $ _ ( )] + [' ']
|
137
|
+
# Beanstalk hangs on char 13
|
138
|
+
bad_chars = (0..12).to_a.concat((14..255).to_a).to_a.map!(&:chr) - valid_chars
|
139
|
+
|
140
|
+
assert_raises(Beaneater::BadFormatError, 'Expected tube name starting with hyphen to be invalid') do
|
141
|
+
client.transmit('pause-tube -starts-with-hyphen 10')
|
142
|
+
end
|
143
|
+
|
144
|
+
bad_chars.each do |bad_char|
|
145
|
+
assert_raises(Beaneater::BadFormatError, "Expected tube name with char #{bad_char} to be invalid") do
|
146
|
+
client.transmit("pause-tube name_with_#{bad_char}_in_it 10")
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
|
152
|
+
should 'should be able to handle tube name of max length with delay of max length' do
|
153
|
+
pause = 2**32 - 1
|
154
|
+
name = 'c' * 200
|
155
|
+
initial_tube_cmd_pause = client.transmit("stats-tube #{tube_name}")[:body]['cmd-pause-tube']
|
156
|
+
client.transmit("watch #{name}")
|
157
|
+
response = client.transmit("pause-tube #{name} #{pause}")
|
158
|
+
assert_equal 'PAUSED', response[:status]
|
159
|
+
tube_stats = client.transmit("stats-tube #{name}")[:body]
|
160
|
+
assert_equal pause, tube_stats['pause']
|
161
|
+
assert_equal(initial_tube_cmd_pause + 1, tube_stats['cmd-pause-tube'], 'Expected tube cmd-pause-tube to be incremented')
|
162
|
+
end
|
163
|
+
|
164
|
+
end
|
165
|
+
|
166
|
+
end
|