beanstalk_integration_tests 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. data/.gitignore +17 -0
  2. data/Gemfile +3 -0
  3. data/LICENSE +22 -0
  4. data/README.md +38 -0
  5. data/Rakefile +9 -0
  6. data/beanstalk_integration_tests.gemspec +26 -0
  7. data/lib/beanstalk_integration_tests.rb +2 -0
  8. data/lib/beanstalk_integration_tests/bury_test.rb +137 -0
  9. data/lib/beanstalk_integration_tests/delete_test.rb +160 -0
  10. data/lib/beanstalk_integration_tests/ignore_test.rb +127 -0
  11. data/lib/beanstalk_integration_tests/kick_job_test.rb +68 -0
  12. data/lib/beanstalk_integration_tests/kick_test.rb +207 -0
  13. data/lib/beanstalk_integration_tests/list_tube_used_test.rb +26 -0
  14. data/lib/beanstalk_integration_tests/list_tubes_test.rb +26 -0
  15. data/lib/beanstalk_integration_tests/list_tubes_watched_test.rb +26 -0
  16. data/lib/beanstalk_integration_tests/pause_tube_test.rb +166 -0
  17. data/lib/beanstalk_integration_tests/peek_test.rb +242 -0
  18. data/lib/beanstalk_integration_tests/put_test.rb +255 -0
  19. data/lib/beanstalk_integration_tests/quit_test.rb +24 -0
  20. data/lib/beanstalk_integration_tests/release_test.rb +191 -0
  21. data/lib/beanstalk_integration_tests/reserve_test.rb +385 -0
  22. data/lib/beanstalk_integration_tests/stats_job_test.rb +116 -0
  23. data/lib/beanstalk_integration_tests/stats_test.rb +130 -0
  24. data/lib/beanstalk_integration_tests/stats_tube_test.rb +141 -0
  25. data/lib/beanstalk_integration_tests/test_helper.rb +88 -0
  26. data/lib/beanstalk_integration_tests/tests.rb +4 -0
  27. data/lib/beanstalk_integration_tests/touch_test.rb +118 -0
  28. data/lib/beanstalk_integration_tests/use_test.rb +118 -0
  29. data/lib/beanstalk_integration_tests/version.rb +3 -0
  30. data/lib/beanstalk_integration_tests/watch_test.rb +128 -0
  31. metadata +157 -0
@@ -0,0 +1,242 @@
1
+ require 'beanstalk_integration_tests/test_helper'
2
+
3
+ class PeekTest < BeanstalkIntegrationTest
4
+
5
+ setup do
6
+ client.transmit("use #{tube_name}")
7
+ client.transmit("watch #{tube_name}")
8
+ end
9
+
10
+
11
+ context 'peek' do
12
+
13
+ should 'return job id and message' do
14
+ job_id, message = do_setup
15
+ response = client.transmit("peek #{job_id}")
16
+ assert_equal('FOUND', response[:status], 'Expected peek of existing job to return FOUND')
17
+ assert_equal(job_id, response[:id], 'Expected peek of existing job to return the correct job id')
18
+ assert_equal(message, response[:body], 'Expected peek of existing job to return the correct body')
19
+ end
20
+
21
+
22
+ should 'return NOT_FOUND if null, non-integer, or negative job id provided or no such job' do
23
+ relative_id = do_setup.first
24
+ ['', -1, 'foo', relative_id.to_i + 1].each do |job_id|
25
+ initial_cmd_peek = client.transmit('stats')[:body]['cmd-peek']
26
+ assert_raises(Beaneater::NotFoundError, 'Expected peeking non-existent job to return NOT_FOUND') do
27
+ response = client.transmit("peek #{job_id}")
28
+ debugger
29
+ puts "#{job_id}: #{response.inspect}"
30
+ end
31
+ assert_equal(initial_cmd_peek + 1, client.transmit('stats')[:body]['cmd-peek'], 'Expected cmd-peek to be incremented')
32
+ end
33
+ end
34
+
35
+
36
+ should 'return UNKNOWN_COMMAND if command does not include space' do
37
+ initial_cmd_peek = client.transmit('stats')[:body]['cmd-peek']
38
+ assert_raises(Beaneater::UnknownCommandError, 'Expected peek without space to return UNKNOWN_COMMAND') do
39
+ client.transmit('peek')
40
+ end
41
+ assert_equal(initial_cmd_peek, client.transmit('stats')[:body]['cmd-peek'], 'Expected cmd-peek to be unchanged')
42
+ end
43
+
44
+
45
+ should 'peek ignoring trailing space, args, and chars' do
46
+ job_id, message = do_setup
47
+ [' ', ' and ignore these arguments', '_and_ignore_these_letters'].each do |trailer|
48
+ initial_cmd_peek = client.transmit('stats')[:body]['cmd-peek']
49
+ response = client.transmit("peek #{job_id}#{trailer}")
50
+ assert_equal job_id, response[:id]
51
+ assert_equal message, response[:body]
52
+ assert_equal(initial_cmd_peek + 1, client.transmit('stats')[:body]['cmd-peek'], 'Expected cmd-peek to be unchanged')
53
+ end
54
+ end
55
+
56
+ end
57
+
58
+
59
+ context 'peek-ready' do
60
+
61
+ should 'return job id and message' do
62
+ job_id, message = do_setup
63
+ initial_cmd_peek_ready = client.transmit('stats')[:body]['cmd-peek-ready']
64
+ response = client.transmit('peek-ready')
65
+ assert_equal('FOUND', response[:status], 'Expected peek-ready to return FOUND')
66
+ assert_equal(job_id, response[:id], 'Expected peek-ready to return the correct job id')
67
+ assert_equal(message, response[:body], 'Expected peek-ready to return the correct body')
68
+ assert_equal(initial_cmd_peek_ready + 1, client.transmit('stats')[:body]['cmd-peek-ready'], 'Expected cmd-peek-ready to be incremented')
69
+ end
70
+
71
+
72
+ should 'return the correct ready job' do
73
+ initial_cmd_peek_ready = client.transmit('stats')[:body]['cmd-peek-ready']
74
+ buried_id = do_setup.first
75
+ timeout(1) do
76
+ client.transmit('reserve')
77
+ end
78
+ client.transmit("bury #{buried_id} 0")
79
+ do_setup(10)
80
+ do_setup(0, 120)
81
+ job_id, message = do_setup
82
+ response = client.transmit('peek-ready')
83
+ assert_equal('FOUND', response[:status], 'Expected peek-ready to return FOUND')
84
+ assert_equal(job_id, response[:id], 'Expected peek-ready to return the correct job id')
85
+ assert_equal(message, response[:body], 'Expected peek-ready to return the correct body')
86
+ assert_equal(initial_cmd_peek_ready + 1, client.transmit('stats')[:body]['cmd-peek-ready'], 'Expected cmd-peek-ready to be incremented')
87
+ end
88
+
89
+
90
+ should 'return NOT_FOUND if no ready jobs' do
91
+ buried_id = do_setup.first
92
+ timeout(1) do
93
+ client.transmit('reserve')
94
+ end
95
+ client.transmit("bury #{buried_id} 0")
96
+ do_setup(0, 120)
97
+ assert_raises(Beaneater::NotFoundError, 'Expected peek-ready with no ready jobs to return NOT_FOUND') do
98
+ client.transmit('peek-ready')
99
+ end
100
+ end
101
+
102
+
103
+ should 'return BAD_FORMAT with any trailing characters' do
104
+ initial_cmd_peek_ready = client.transmit('stats')[:body]['cmd-peek-ready']
105
+ assert_raises(Beaneater::BadFormatError, 'Expected peek-ready with trailing characters to return BAD_FORMAT') do
106
+ [' ', ' and other args'].each do |trailer|
107
+ client.transmit("peek-ready#{trailer}")
108
+ end
109
+ end
110
+ assert_equal(initial_cmd_peek_ready, client.transmit('stats')[:body]['cmd-peek-ready'], 'Expected cmd-peek-ready to be unchanged')
111
+ end
112
+
113
+ end
114
+
115
+
116
+ context 'peek-delayed' do
117
+
118
+ should 'return job id and message' do
119
+ job_id, message = do_setup(0, 120)
120
+ assert_equal('delayed', client.transmit("stats-job #{job_id}")[:body]['state'], 'Expected job enqueued with delay to be delayed')
121
+ initial_cmd_peek_delayed = client.transmit('stats')[:body]['cmd-peek-delayed']
122
+ response = client.transmit('peek-delayed')
123
+ assert_equal('FOUND', response[:status], 'Expected peek-delayed of existing job to return FOUND')
124
+ assert_equal(job_id, response[:id], 'Expected peek-delayed to return the correct job id')
125
+ assert_equal(message, response[:body], 'Expected peek-delayed to return the correct body')
126
+ assert_equal(initial_cmd_peek_delayed + 1, client.transmit('stats')[:body]['cmd-peek-delayed'], 'Expected cmd-peek-delayed to be incremented')
127
+ end
128
+
129
+
130
+ should 'return the correct delayed job' do
131
+ initial_cmd_peek_delayed = client.transmit('stats')[:body]['cmd-peek-delayed']
132
+ buried_id = do_setup.first
133
+ timeout(1) do
134
+ client.transmit('reserve')
135
+ end
136
+ client.transmit("bury #{buried_id} 0")
137
+ do_setup(10)
138
+ do_setup(0, 120)
139
+ do_setup(0, 60)
140
+ job_id, message = do_setup(10, 30)
141
+ response = client.transmit('peek-delayed')
142
+ assert_equal('FOUND', response[:status], 'Expected peek-delayed to return FOUND')
143
+ assert_equal(job_id, response[:id], 'Expected peek-delayed to return the correct job id')
144
+ assert_equal(message, response[:body], 'Expected peek-delayed to return the correct body')
145
+ assert_equal(initial_cmd_peek_delayed + 1, client.transmit('stats')[:body]['cmd-peek-delayed'], 'Expected cmd-peek-delayed to be incremented')
146
+ end
147
+
148
+
149
+ should 'return NOT_FOUND if no delayed jobs' do
150
+ buried_id = do_setup.first
151
+ timeout(1) do
152
+ client.transmit('reserve')
153
+ end
154
+ client.transmit("bury #{buried_id} 0")
155
+ do_setup
156
+ assert_raises(Beaneater::NotFoundError, 'Expected peek-delayed with no delayed jobs to return NOT_FOUND') do
157
+ client.transmit('peek-delayed')
158
+ end
159
+ end
160
+
161
+
162
+ should 'return BAD_FORMAT with any trailing characters' do
163
+ initial_cmd_peek_delayed = client.transmit('stats')[:body]['cmd-peek-delayed']
164
+ assert_raises(Beaneater::BadFormatError, 'Expected peek-delayed with trailing characters to return BAD_FORMAT') do
165
+ [' ', ' and other args'].each do |trailer|
166
+ client.transmit("peek-delayed#{trailer}")
167
+ end
168
+ end
169
+ assert_equal(initial_cmd_peek_delayed, client.transmit('stats')[:body]['cmd-peek-delayed'], 'Expected cmd-peek-delayed to be unchanged')
170
+ end
171
+
172
+ end
173
+
174
+
175
+ context 'peek-buried' do
176
+
177
+ should 'return job id and message' do
178
+ job_id, message = do_setup
179
+ timeout(1) do
180
+ client.transmit('reserve')
181
+ end
182
+ client.transmit("bury #{job_id} 0")
183
+ assert_equal('buried', client.transmit("stats-job #{job_id}")[:body]['state'], 'Expected job enqueued with delay to be delayed')
184
+ initial_cmd_peek_buried = client.transmit('stats')[:body]['cmd-peek-buried']
185
+ response = client.transmit('peek-buried')
186
+ assert_equal('FOUND', response[:status], 'Expected peek-buried of existing job to return FOUND')
187
+ assert_equal(job_id, response[:id], 'Expected peek-buried to return the correct job id')
188
+ assert_equal(message, response[:body], 'Expected peek-buried to return the correct body')
189
+ assert_equal(initial_cmd_peek_buried + 1, client.transmit('stats')[:body]['cmd-peek-buried'], 'Expected cmd-peek-buried to be incremented')
190
+ end
191
+
192
+
193
+ should 'return the correct buried job' do
194
+ initial_cmd_peek_buried = client.transmit('stats')[:body]['cmd-peek-buried']
195
+ do_setup(10)
196
+ do_setup(0, 120)
197
+ job_id, message = do_setup
198
+ timeout(1) do
199
+ client.transmit('reserve')
200
+ end
201
+ client.transmit("bury #{job_id} 0")
202
+ buried_id = do_setup.first
203
+ timeout(1) do
204
+ client.transmit('reserve')
205
+ end
206
+ client.transmit("bury #{buried_id} 0")
207
+ response = client.transmit('peek-buried')
208
+ assert_equal('FOUND', response[:status], 'Expected peek-buried to return FOUND')
209
+ assert_equal(job_id, response[:id], 'Expected peek-buried to return the correct job id')
210
+ assert_equal(message, response[:body], 'Expected peek-buried to return the correct body')
211
+ assert_equal(initial_cmd_peek_buried + 1, client.transmit('stats')[:body]['cmd-peek-buried'], 'Expected cmd-peek-buried to be incremented')
212
+ end
213
+
214
+
215
+ should 'return NOT_FOUND if no buried jobs' do
216
+ do_setup(0, 120)
217
+ do_setup
218
+ assert_raises(Beaneater::NotFoundError, 'Expected peek-buried with no buried jobs to return NOT_FOUND') do
219
+ client.transmit('peek-buried')
220
+ end
221
+ end
222
+
223
+
224
+ should 'return BAD_FORMAT with any trailing characters' do
225
+ initial_cmd_peek_buried = client.transmit('stats')[:body]['cmd-peek-buried']
226
+ assert_raises(Beaneater::BadFormatError, 'Expected peek-buried with trailing characters to return BAD_FORMAT') do
227
+ [' ', ' and other args'].each do |trailer|
228
+ client.transmit("peek-buried#{trailer}")
229
+ end
230
+ end
231
+ assert_equal(initial_cmd_peek_buried, client.transmit('stats')[:body]['cmd-peek-buried'], 'Expected cmd-peek-buried to be unchanged')
232
+ end
233
+
234
+ end
235
+
236
+
237
+ def do_setup(pri = 0, delay = 0, ttr = 120, message = uuid)
238
+ job_id = client.transmit("put #{pri} #{delay} #{ttr} #{message.bytesize}\r\n#{message}")[:id]
239
+ return [job_id, message]
240
+ end
241
+
242
+ end
@@ -0,0 +1,255 @@
1
+ require 'beanstalk_integration_tests/test_helper'
2
+
3
+ class PutTest < BeanstalkIntegrationTest
4
+
5
+ context 'put' do
6
+
7
+ setup do
8
+ client.transmit("use #{tube_name}")
9
+ @message = uuid
10
+ end
11
+
12
+
13
+ should "insert a job into the connection's currently used tube" do
14
+ assert_equal tube_name, client.transmit('list-tube-used')[:id]
15
+
16
+ stats = client.transmit('stats')[:body]
17
+ initial_current_producers = stats['current-producers']
18
+ initial_cmd_put = stats['cmd-put']
19
+ response = client.transmit("put 1 0 120 #{@message.bytesize}\r\n#{@message}")
20
+ job_tube = client.transmit("stats-job #{response[:id]}")[:body]['tube']
21
+ stats = client.transmit('stats')[:body]
22
+ assert_equal initial_cmd_put + 1, stats['cmd-put']
23
+ assert_equal initial_current_producers + 1, stats['current-producers']
24
+ assert_equal tube_name, job_tube
25
+ end
26
+
27
+
28
+ should 'insert a job with the given priority' do
29
+ pri = rand(2**32) - 1
30
+ response = client.transmit("put #{pri} 0 120 #{@message.bytesize}\r\n#{@message}")
31
+ job_pri = client.transmit("stats-job #{response[:id]}")[:body]['pri']
32
+
33
+ assert_equal pri, job_pri
34
+ end
35
+
36
+
37
+ should 'should reduce excessive priorities to their modulus' do
38
+ overture = rand(10)
39
+ pri = 2**32 + overture
40
+ response = client.transmit("put #{pri} 0 120 #{@message.bytesize}\r\n#{@message}")
41
+ job_pri = client.transmit("stats-job #{response[:id]}")[:body]['pri']
42
+
43
+ assert_equal overture, job_pri
44
+ end
45
+
46
+
47
+ should 'return BAD_FORMAT for negative priority, delay, ttr, or size' do
48
+ initial_cmd_put = client.transmit('stats')[:body]['cmd-put']
49
+ args = [-1, 1, 1, 1]
50
+ 4.times do |index|
51
+ assert_raises Beaneater::BadFormatError do
52
+ client.transmit("put #{args[0]} #{args[1]} #{args[2]} #{args[3]}")
53
+ assert_equal initial_cmd_put + 1 + index, client.transmit('stats')[:body]['cmd-put']
54
+ args.cycle
55
+ end
56
+ end
57
+ end
58
+
59
+
60
+ should 'insert a job with the given delay and a state of delayed' do
61
+ delay = 10
62
+
63
+ response = client.transmit("put 0 #{delay} 10 #{@message.bytesize}\r\n#{@message}")
64
+ job_stats = client.transmit("stats-job #{response[:id]}")[:body]
65
+
66
+ assert_equal delay, job_stats['delay']
67
+ assert_equal 'delayed', job_stats['state']
68
+ sleep 1
69
+ time_left = client.transmit("stats-job #{response[:id]}")[:body]['time-left']
70
+ assert(time_left < job_stats['time-left'], 'Expected time-left to decrement after a second')
71
+ end
72
+
73
+
74
+ should 'insert a delayed job which becomes ready after the timeout' do
75
+ delay = 1
76
+
77
+ response = client.transmit("put 0 #{delay} 10 #{@message.bytesize}\r\n#{@message}")
78
+ sleep 1
79
+ job_stats = client.transmit("stats-job #{response[:id]}")[:body]
80
+ assert_equal 'ready', job_stats['state']
81
+
82
+ stats = client.transmit('stats')[:body]
83
+ tube_stats = client.transmit("stats-tube #{tube_name}")[:body]
84
+ assert_equal(1, stats['current-jobs-urgent'])
85
+ assert_equal(1, stats['current-jobs-ready'])
86
+ assert_equal(1, tube_stats['current-jobs-urgent'])
87
+ assert_equal(1, tube_stats['current-jobs-ready'])
88
+ end
89
+
90
+
91
+ should 'only update current-jobs-delayed counter on tube and server for delayed job' do
92
+ tube_stats = client.transmit("stats-tube #{tube_name}")[:body]
93
+ tube_initial_jobs_ready = tube_stats['current-jobs-ready'].to_i
94
+ tube_initial_jobs_urgent = tube_stats['current-jobs-urgent'].to_i
95
+ tube_initial_jobs_delayed = tube_stats['current-jobs-delayed'].to_i
96
+ tube_initial_jobs_total = tube_stats['total-jobs'].to_i
97
+ server_stats = client.transmit('stats')[:body]
98
+ server_initial_jobs_ready = server_stats['current-jobs-ready'].to_i
99
+ server_initial_jobs_urgent = server_stats['current-jobs-urgent'].to_i
100
+ server_initial_jobs_delayed = server_stats['current-jobs-delayed'].to_i
101
+ server_initial_jobs_total = server_stats['total-jobs'].to_i
102
+
103
+ client.transmit("put 0 120 10 #{@message.bytesize}\r\n#{@message}")
104
+
105
+ tube_stats = client.transmit("stats-tube #{tube_name}")[:body]
106
+ assert_equal tube_initial_jobs_ready, tube_stats['current-jobs-ready'].to_i
107
+ assert_equal tube_initial_jobs_urgent, tube_stats['current-jobs-urgent'].to_i
108
+ assert_equal tube_initial_jobs_delayed + 1, tube_stats['current-jobs-delayed'].to_i
109
+ assert_equal tube_initial_jobs_total + 1, tube_stats['total-jobs'].to_i
110
+ server_stats = client.transmit('stats')[:body]
111
+ assert_equal server_initial_jobs_ready, server_stats['current-jobs-ready'].to_i
112
+ assert_equal server_initial_jobs_urgent, server_stats['current-jobs-urgent'].to_i
113
+ assert_equal server_initial_jobs_delayed + 1, server_stats['current-jobs-delayed'].to_i
114
+ assert_equal server_initial_jobs_total + 1, server_stats['total-jobs'].to_i
115
+ end
116
+
117
+
118
+ should 'insert a job with the given ttr' do
119
+ ttr = 10
120
+
121
+ response = client.transmit("put 0 0 #{ttr} #{@message.bytesize}\r\n#{@message}")
122
+ job_ttr = client.transmit("stats-job #{response[:id]}")[:body]['ttr']
123
+
124
+ assert_equal ttr, job_ttr
125
+ end
126
+
127
+
128
+ should 'increase TTR to 1 if 0 given' do
129
+ response = client.transmit("put 0 0 0 #{@message.bytesize}\r\n#{@message}")
130
+ job_ttr = client.transmit("stats-job #{response[:id]}")[:body]['ttr']
131
+
132
+ assert_equal 1, job_ttr
133
+ end
134
+
135
+
136
+ should 'raise EXPECTED_CRLF if job exceeds declared size but still increment cmd-job' do
137
+ stats = client.transmit('stats')[:body]
138
+ assert_raises Beaneater::ExpectedCrlfError do
139
+ client.transmit("put 0 0 10 #{@message.bytesize - 1}\r\n#{@message}")
140
+ end
141
+ assert_equal stats['cmd-put'] + 1, build_client.transmit('stats')[:body]['cmd-put']
142
+ end
143
+
144
+
145
+ should 'should be able to handle job of max-job-size' do
146
+ stats = client.transmit('stats')[:body]
147
+ max_job_size = stats['max-job-size']
148
+ dec_mod = max_job_size % 10
149
+ message = SecureRandom.base64(8)[0, 10] * ((max_job_size - dec_mod) / 10)
150
+ message += SecureRandom.base64(dec_mod)[0, dec_mod]
151
+
152
+ response = nil
153
+ begin
154
+ response = client.transmit("put 123 0 10 #{message.bytesize}\r\n#{message}")
155
+ rescue Beaneater::JobTooBigError => e
156
+ puts 'Either max-job-size is incorrect or server cannot handle max job size'
157
+ raise e
158
+ end
159
+ assert_equal 'INSERTED', response[:status]
160
+ assert_equal stats['cmd-put'] + 1, client.transmit('stats')[:body]['cmd-put']
161
+ assert_equal message, client.transmit("peek #{response[:id]}")[:body]
162
+ end
163
+
164
+
165
+ should 'raise JOB_TOO_BIG if job larger than max job size but still increment cmd-job' do
166
+ stats = client.transmit('stats')[:body]
167
+ max_job_size = stats['max-job-size']
168
+ dec_mod = max_job_size % 10
169
+ message = SecureRandom.base64(8)[0, 10] * ((max_job_size - dec_mod) / 10)
170
+ message += SecureRandom.base64(dec_mod)[0, dec_mod + 1]
171
+
172
+ assert_raises Beaneater::JobTooBigError do
173
+ client.transmit("put 123 0 10 #{message.bytesize}\r\n#{message}")
174
+ end
175
+ assert_equal stats['cmd-put'] + 1, client.transmit('stats')[:body]['cmd-put']
176
+ end
177
+
178
+
179
+ should 'insert a job with the given body' do
180
+ response = client.transmit("put 0 0 10 #{@message.bytesize}\r\n#{@message}")
181
+ assert_equal @message, client.transmit("peek #{response[:id]}")[:body]
182
+ end
183
+
184
+
185
+ should 'handle any byte value and incur no length weirdness' do
186
+ bytes = (0..255).to_a.pack("c*")
187
+ response = client.transmit("put 0 0 100 256\r\n#{bytes}")
188
+ assert_equal bytes, client.transmit("peek #{response[:id]}")[:body]
189
+ end
190
+
191
+
192
+ should 'pass non-terminal \r\n through without modification or length weirdness' do
193
+ message = "\r\n" * 10
194
+ response = client.transmit("put 0 0 100 20\r\n#{message}")
195
+ assert_equal message, client.transmit("peek #{response[:id]}")[:body]
196
+ end
197
+
198
+
199
+ should 'increment current-jobs-ready and current-jobs-urgent counters on server and tube if priority < 1024' do
200
+ tube_stats = client.transmit("stats-tube #{tube_name}")[:body]
201
+ tube_initial_jobs_ready = tube_stats['current-jobs-ready'].to_i
202
+ tube_initial_jobs_urgent = tube_stats['current-jobs-urgent'].to_i
203
+ tube_initial_jobs_total = tube_stats['total-jobs'].to_i
204
+ server_stats = client.transmit('stats')[:body]
205
+ server_initial_jobs_ready = server_stats['current-jobs-ready'].to_i
206
+ server_initial_jobs_urgent = server_stats['current-jobs-urgent'].to_i
207
+ server_initial_jobs_total = server_stats['total-jobs'].to_i
208
+
209
+ client.transmit("put 1023 0 100 #{@message.bytesize}\r\n#{@message}")
210
+
211
+ tube_stats = client.transmit("stats-tube #{tube_name}")[:body]
212
+ assert_equal tube_initial_jobs_ready + 1, tube_stats['current-jobs-ready'].to_i
213
+ assert_equal tube_initial_jobs_urgent + 1, tube_stats['current-jobs-urgent'].to_i
214
+ assert_equal tube_initial_jobs_total + 1, tube_stats['total-jobs'].to_i
215
+ server_stats = client.transmit('stats')[:body]
216
+ assert_equal server_initial_jobs_ready + 1, server_stats['current-jobs-ready'].to_i
217
+ assert_equal server_initial_jobs_urgent + 1, server_stats['current-jobs-urgent'].to_i
218
+ assert_equal server_initial_jobs_total + 1, server_stats['total-jobs'].to_i
219
+ end
220
+
221
+
222
+ should 'not update current-jobs-urgent counters on server and tube if priority >= 1024' do
223
+ tube_stats = client.transmit("stats-tube #{tube_name}")[:body]
224
+ tube_initial_jobs_ready = tube_stats['current-jobs-ready'].to_i
225
+ tube_initial_jobs_urgent = tube_stats['current-jobs-urgent'].to_i
226
+ tube_initial_jobs_total = tube_stats['total-jobs'].to_i
227
+ server_stats = client.transmit('stats')[:body]
228
+ server_initial_jobs_ready = server_stats['current-jobs-ready'].to_i
229
+ server_initial_jobs_urgent = server_stats['current-jobs-urgent'].to_i
230
+ server_initial_jobs_total = server_stats['total-jobs'].to_i
231
+
232
+ client.transmit("put 1024 0 100 #{@message.bytesize}\r\n#{@message}")
233
+
234
+ tube_stats = client.transmit("stats-tube #{tube_name}")[:body]
235
+ assert_equal tube_initial_jobs_ready + 1, tube_stats['current-jobs-ready'].to_i
236
+ assert_equal tube_initial_jobs_urgent, tube_stats['current-jobs-urgent'].to_i
237
+ assert_equal tube_initial_jobs_total + 1, tube_stats['total-jobs'].to_i
238
+ server_stats = client.transmit('stats')[:body]
239
+ assert_equal server_initial_jobs_ready + 1, server_stats['current-jobs-ready'].to_i
240
+ assert_equal server_initial_jobs_urgent, server_stats['current-jobs-urgent'].to_i
241
+ assert_equal server_initial_jobs_total + 1, server_stats['total-jobs'].to_i
242
+ end
243
+
244
+
245
+ should 'raise BAD_FORMAT with trailing_space but still increment cmd-put' do
246
+ initial_cmd_put = client.transmit('stats')[:body]['cmd-put']
247
+ assert_raises(Beaneater::BadFormatError, 'Expected put with trailing space to return BAD_FORMAT') do
248
+ client.transmit("put 0 0 120 2 \r\nxx")
249
+ end
250
+ assert_equal initial_cmd_put + 1, build_client.transmit('stats')[:body]['cmd-put']
251
+ end
252
+
253
+ end
254
+
255
+ end