beanstalk_integration_tests 0.0.1
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/.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
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Danny Guinther
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# BeanstalkIntegrationTests
|
2
|
+
|
3
|
+
A suite of integration tests to test adherence to the Beanstalkd protocol (https://github.com/kr/beanstalkd/blob/master/doc/protocol.md).
|
4
|
+
|
5
|
+
Some tests will fail at present (as of version 1.9+9+g157d88b or https://github.com/kr/beanstalkd/commit/157d88bf9435a23b71a1940a9afb617e52a2b9e9). I maybe incorrect, but I believe these are related to previously undiagnosed bugs in the current version of beanstalkd.
|
6
|
+
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 'beanstalk_integration_tests'
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install beanstalk_integration_tests
|
21
|
+
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Start your beanstalkd server on 127.0.0.1:11300 or localhost:11300
|
26
|
+
|
27
|
+
Run integration tests:
|
28
|
+
|
29
|
+
$ rake
|
30
|
+
|
31
|
+
|
32
|
+
## Contributing
|
33
|
+
|
34
|
+
1. Fork it
|
35
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
36
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
37
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
38
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'beanstalk_integration_tests/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'beanstalk_integration_tests'
|
8
|
+
spec.version = BeanstalkIntegrationTests::VERSION
|
9
|
+
spec.authors = ['Danny Guinther']
|
10
|
+
spec.email = ['dannyguinther@gmail.com']
|
11
|
+
spec.description = %q{Integration tests for testing adherence to the beanstalkd protocol}
|
12
|
+
spec.summary = %q{Beanstalk protocol integration tests}
|
13
|
+
spec.homepage = ''
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^lib/beanstalk_integration_tests/test/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
22
|
+
spec.add_development_dependency 'rake'
|
23
|
+
spec.add_development_dependency 'beaneater'
|
24
|
+
spec.add_development_dependency 'minitest_should'
|
25
|
+
spec.add_development_dependency 'mocha'
|
26
|
+
end
|
@@ -0,0 +1,137 @@
|
|
1
|
+
require 'beanstalk_integration_tests/test_helper'
|
2
|
+
|
3
|
+
class BuryTest < BeanstalkIntegrationTest
|
4
|
+
|
5
|
+
context 'bury of reserved job' do
|
6
|
+
|
7
|
+
setup do
|
8
|
+
message = uuid
|
9
|
+
client.transmit("use #{tube_name}")
|
10
|
+
client.transmit("watch #{tube_name}")
|
11
|
+
client.transmit("put 0 0 10 #{message.bytesize}\r\n#{message}")
|
12
|
+
timeout(2) do
|
13
|
+
@reserved_id = client.transmit('reserve')[:id]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
should 'bury a reserved job' do
|
18
|
+
response = client.transmit("bury #{@reserved_id} 0")
|
19
|
+
assert_equal 'BURIED', response[:status]
|
20
|
+
assert_equal 'buried', client.transmit("stats-job #{@reserved_id}")[:body]['state']
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
should 'bury a reserved job if the job deadline is approaching' do
|
25
|
+
message = uuid
|
26
|
+
client.transmit("delete #{@reserved_id}")
|
27
|
+
client.transmit("put 0 0 1 #{message.bytesize}\r\n#{message}")
|
28
|
+
timeout(2) do
|
29
|
+
@reserved_id = client.transmit('reserve')[:id]
|
30
|
+
end
|
31
|
+
assert_raises(Beaneater::DeadlineSoonError, 'Expected reserve to raise an error when deadline pending') do
|
32
|
+
timeout(2) do
|
33
|
+
client.transmit('reserve')
|
34
|
+
end
|
35
|
+
end
|
36
|
+
response = client.transmit("bury #{@reserved_id} 0")
|
37
|
+
assert_equal 'BURIED', response[:status]
|
38
|
+
assert_equal 'buried', client.transmit("stats-job #{@reserved_id}")[:body]['state']
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
should 'bury a reserved job with the given priority' do
|
43
|
+
pri = 1023
|
44
|
+
response = client.transmit("bury #{@reserved_id} #{pri}")
|
45
|
+
assert_equal 'BURIED', response[:status]
|
46
|
+
job_stats = client.transmit("stats-job #{@reserved_id}")[:body]
|
47
|
+
assert_equal 'buried', job_stats['state']
|
48
|
+
assert_equal pri, job_stats['pri']
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
should 'increment buries count for job, current-jobs-buried for tube and server, and server cmd-bury counts' do
|
53
|
+
initial_job_buries = client.transmit("stats-job #{@reserved_id}")[:body]['buries']
|
54
|
+
initial_tube_jobs_buried = client.transmit("stats-tube #{tube_name}")[:body]['current-jobs-buried']
|
55
|
+
server_stats = client.transmit('stats')[:body]
|
56
|
+
initial_server_cmd_bury = server_stats['cmd-bury']
|
57
|
+
initial_server_jobs_buried = server_stats['current-jobs-buried']
|
58
|
+
|
59
|
+
response = client.transmit("bury #{@reserved_id} 0")
|
60
|
+
assert_equal 'BURIED', response[:status]
|
61
|
+
assert_equal 'buried', client.transmit("stats-job #{@reserved_id}")[:body]['state']
|
62
|
+
|
63
|
+
assert_equal initial_job_buries + 1, client.transmit("stats-job #{@reserved_id}")[:body]['buries']
|
64
|
+
assert_equal initial_tube_jobs_buried + 1, client.transmit("stats-tube #{tube_name}")[:body]['current-jobs-buried']
|
65
|
+
server_stats = client.transmit('stats')[:body]
|
66
|
+
assert_equal initial_server_cmd_bury + 1, server_stats['cmd-bury']
|
67
|
+
assert_equal initial_server_jobs_buried + 1, server_stats['current-jobs-buried']
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
should 'return NOT_FOUND when burying a job that the client has not reserved' do
|
72
|
+
initial_cmd_bury = client.transmit('stats')[:body]['cmd-bury']
|
73
|
+
client.transmit("release #{@reserved_id} 0 0")
|
74
|
+
assert_raises(Beaneater::NotFoundError, 'Expected bury of unreserved job to raise error') do
|
75
|
+
client.transmit("bury #{@reserved_id} 0")
|
76
|
+
end
|
77
|
+
assert_equal(initial_cmd_bury + 1, client.transmit('stats')[:body]['cmd-bury'], 'Expected cmd-bury to be incremented')
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
should 'return NOT_FOUND when burying a job reserved by another client' do
|
82
|
+
initial_cmd_bury = client.transmit('stats')[:body]['cmd-bury']
|
83
|
+
assert_raises(Beaneater::NotFoundError, 'Expected bury of job reserved by another client to raise error') do
|
84
|
+
build_client.transmit("bury #{@reserved_id} 0")
|
85
|
+
end
|
86
|
+
client.transmit("delete #{@reserved_id}")
|
87
|
+
assert_equal(initial_cmd_bury + 1, client.transmit('stats')[:body]['cmd-bury'], 'Expected cmd-bury to be incremented')
|
88
|
+
end
|
89
|
+
|
90
|
+
|
91
|
+
should 'return BAD_FORMAT if job_id or priority are not integers' do
|
92
|
+
initial_cmd_bury = client.transmit('stats')[:body]['cmd-bury']
|
93
|
+
assert_raises(Beaneater::BadFormatError, 'Expected bury of non-integer job_id to raise error') do
|
94
|
+
client.transmit("bury foo 0")
|
95
|
+
end
|
96
|
+
|
97
|
+
assert_raises(Beaneater::BadFormatError, 'Expected bury with non-integer priority to raise error') do
|
98
|
+
client.transmit("bury #{@reserved_id} foo")
|
99
|
+
end
|
100
|
+
client.transmit("delete #{@reserved_id}")
|
101
|
+
assert_equal(initial_cmd_bury, client.transmit('stats')[:body]['cmd-bury'], 'Expected cmd-bury to remain the same')
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context 'bury not requiring reserved job' do
|
106
|
+
should 'return NOT_FOUND when burying a job with an ID <= 0' do
|
107
|
+
(-1..0).each do |job_id|
|
108
|
+
assert_raises(Beaneater::NotFoundError, "Expected bury of job_id #{job_id} to raise NOT_FOUND error") do
|
109
|
+
build_client.transmit("bury #{job_id} 0")
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
|
115
|
+
should 'return BAD_FORMAT if priority is negative' do
|
116
|
+
assert_raises(Beaneater::BadFormatError, 'Expected bury with negative timeout to raise error') do
|
117
|
+
client.transmit("bury 1 -1")
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
|
122
|
+
should 'return BAD_FORMAT if line includes trailing space' do
|
123
|
+
assert_raises(Beaneater::BadFormatError, 'Expected bury with trailing space to raise error') do
|
124
|
+
client.transmit("bury 1 1 ")
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
|
129
|
+
should 'return BAD_FORMAT if excess arguments' do
|
130
|
+
assert_raises(Beaneater::BadFormatError, 'Expected bury with excess arguments to raise error') do
|
131
|
+
client.transmit("bury 1 1 1")
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
@@ -0,0 +1,160 @@
|
|
1
|
+
require 'beanstalk_integration_tests/test_helper'
|
2
|
+
|
3
|
+
class DeleteTest < BeanstalkIntegrationTest
|
4
|
+
|
5
|
+
setup do
|
6
|
+
client.transmit("use #{tube_name}")
|
7
|
+
client.transmit("watch #{tube_name}")
|
8
|
+
@message = uuid
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
context 'delete' do
|
13
|
+
|
14
|
+
should 'delete a job that is ready' do
|
15
|
+
initial_server_cmd_delete = client.transmit('stats')[:body]['cmd-delete']
|
16
|
+
initial_tube_cmd_delete = client.transmit("stats-tube #{tube_name}")[:body]['cmd-delete']
|
17
|
+
job_id = client.transmit("put 0 0 120 #{@message.bytesize}\r\n#{@message}")[:id]
|
18
|
+
response = client.transmit("delete #{job_id}")
|
19
|
+
assert_equal 'DELETED', response[:status]
|
20
|
+
assert_equal(initial_server_cmd_delete + 1, client.transmit('stats')[:body]['cmd-delete'], 'Expected server cmd-delete to be incremented')
|
21
|
+
assert_equal(initial_tube_cmd_delete + 1, client.transmit("stats-tube #{tube_name}")[:body]['cmd-delete'], 'Expected tube cmd-delete to be incremented')
|
22
|
+
|
23
|
+
assert_raises(Beaneater::NotFoundError, 'Expected deleted job to not be found') do
|
24
|
+
client.transmit("peek #{job_id}")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
should 'delete a job that is buried' do
|
30
|
+
job_id = client.transmit("put 0 0 120 #{@message.bytesize}\r\n#{@message}")[:id]
|
31
|
+
timeout(2) do
|
32
|
+
client.transmit('reserve')
|
33
|
+
end
|
34
|
+
bury_response = client.transmit("bury #{job_id} 120")
|
35
|
+
assert_equal 'BURIED', bury_response[:status]
|
36
|
+
initial_server_cmd_delete = client.transmit('stats')[:body]['cmd-delete']
|
37
|
+
initial_tube_cmd_delete = client.transmit("stats-tube #{tube_name}")[:body]['cmd-delete']
|
38
|
+
response = client.transmit("delete #{job_id}")
|
39
|
+
assert_equal 'DELETED', response[:status]
|
40
|
+
assert_equal(initial_server_cmd_delete + 1, client.transmit('stats')[:body]['cmd-delete'], 'Expected server cmd-delete to be incremented')
|
41
|
+
assert_equal(initial_tube_cmd_delete + 1, client.transmit("stats-tube #{tube_name}")[:body]['cmd-delete'], 'Expected tube cmd-delete to be incremented')
|
42
|
+
|
43
|
+
assert_raises(Beaneater::NotFoundError, 'Expected deleted job to not be found') do
|
44
|
+
client.transmit("peek #{job_id}")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
should 'delete a job that is delayed' do
|
50
|
+
job_id = client.transmit("put 0 120 120 #{@message.bytesize}\r\n#{@message}")[:id]
|
51
|
+
initial_server_cmd_delete = client.transmit('stats')[:body]['cmd-delete']
|
52
|
+
initial_tube_cmd_delete = client.transmit("stats-tube #{tube_name}")[:body]['cmd-delete']
|
53
|
+
response = client.transmit("delete #{job_id}")
|
54
|
+
assert_equal 'DELETED', response[:status]
|
55
|
+
assert_equal(initial_server_cmd_delete + 1, client.transmit('stats')[:body]['cmd-delete'], 'Expected server cmd-delete to be incremented')
|
56
|
+
assert_equal(initial_tube_cmd_delete + 1, client.transmit("stats-tube #{tube_name}")[:body]['cmd-delete'], 'Expected tube cmd-delete to be incremented')
|
57
|
+
|
58
|
+
assert_raises(Beaneater::NotFoundError, 'Expected deleted job to not be found') do
|
59
|
+
client.transmit("peek #{job_id}")
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
should 'delete a job that is reserved by the client' do
|
65
|
+
job_id = client.transmit("put 0 0 120 #{@message.bytesize}\r\n#{@message}")[:id]
|
66
|
+
timeout(2) do
|
67
|
+
client.transmit('reserve')
|
68
|
+
end
|
69
|
+
initial_server_cmd_delete = client.transmit('stats')[:body]['cmd-delete']
|
70
|
+
initial_tube_cmd_delete = client.transmit("stats-tube #{tube_name}")[:body]['cmd-delete']
|
71
|
+
response = client.transmit("delete #{job_id}")
|
72
|
+
assert_equal 'DELETED', response[:status]
|
73
|
+
assert_equal(initial_server_cmd_delete + 1, client.transmit('stats')[:body]['cmd-delete'], 'Expected server cmd-delete to be incremented')
|
74
|
+
assert_equal(initial_tube_cmd_delete + 1, client.transmit("stats-tube #{tube_name}")[:body]['cmd-delete'], 'Expected tube cmd-delete to be incremented')
|
75
|
+
assert_raises(Beaneater::NotFoundError, 'Expected deleted job to not be found') do
|
76
|
+
client.transmit("peek #{job_id}")
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
should 'not delete a job that is deleted' do
|
82
|
+
job_id = client.transmit("put 0 0 120 #{@message.bytesize}\r\n#{@message}")[:id]
|
83
|
+
initial_server_cmd_delete = client.transmit('stats')[:body]['cmd-delete']
|
84
|
+
initial_tube_cmd_delete = client.transmit("stats-tube #{tube_name}")[:body]['cmd-delete']
|
85
|
+
response = client.transmit("delete #{job_id}")
|
86
|
+
assert_equal 'DELETED', response[:status]
|
87
|
+
assert_raises(Beaneater::NotFoundError, 'Expected deleted job to not be found') do
|
88
|
+
client.transmit("delete #{job_id}")
|
89
|
+
end
|
90
|
+
assert_equal(initial_server_cmd_delete + 2, client.transmit('stats')[:body]['cmd-delete'], 'Expected server cmd-delete to be incremented')
|
91
|
+
assert_equal(initial_tube_cmd_delete + 1, client.transmit("stats-tube #{tube_name}")[:body]['cmd-delete'], 'Expected tube cmd-delete to be incremented')
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
should 'not delete a job that is reserved by another client' do
|
96
|
+
client2 = build_client
|
97
|
+
client2.transmit("watch #{tube_name}")
|
98
|
+
job_id = client.transmit("put 0 0 120 #{@message.bytesize}\r\n#{@message}")[:id]
|
99
|
+
timeout(2) do
|
100
|
+
client2.transmit('reserve')
|
101
|
+
end
|
102
|
+
initial_server_cmd_delete = client.transmit('stats')[:body]['cmd-delete']
|
103
|
+
initial_tube_cmd_delete = client.transmit("stats-tube #{tube_name}")[:body]['cmd-delete']
|
104
|
+
assert_raises(Beaneater::NotFoundError, 'Expected deleted job to not be found') do
|
105
|
+
client.transmit("delete #{job_id}")
|
106
|
+
end
|
107
|
+
client2.transmit("delete #{job_id}")
|
108
|
+
assert_equal(initial_server_cmd_delete + 2, client.transmit('stats')[:body]['cmd-delete'], 'Expected server cmd-delete to be incremented')
|
109
|
+
assert_equal(initial_tube_cmd_delete + 1, client.transmit("stats-tube #{tube_name}")[:body]['cmd-delete'], 'Expected tube cmd-delete to be incremented')
|
110
|
+
end
|
111
|
+
|
112
|
+
|
113
|
+
should 'return UNKNOWN_COMMAND without a space and job_id' do
|
114
|
+
initial_server_cmd_delete = client.transmit('stats')[:body]['cmd-delete']
|
115
|
+
assert_raises(Beaneater::UnknownCommandError, 'Expected delete with out space and job_id to raise UNKNOWN_COMMAND') do
|
116
|
+
client.transmit('delete')
|
117
|
+
end
|
118
|
+
assert_equal(initial_server_cmd_delete, client.transmit('stats')[:body]['cmd-delete'], 'Expected server cmd-delete to be unchanged')
|
119
|
+
end
|
120
|
+
|
121
|
+
|
122
|
+
should 'return NOT_FOUND with a space but without a job_id' do
|
123
|
+
initial_server_cmd_delete = client.transmit('stats')[:body]['cmd-delete']
|
124
|
+
assert_raises(Beaneater::NotFoundError, 'Expected delete with space but without job_id to raise NOT_FOUND') do
|
125
|
+
client.transmit('delete ')
|
126
|
+
end
|
127
|
+
assert_equal(initial_server_cmd_delete + 1, client.transmit('stats')[:body]['cmd-delete'], 'Expected server cmd-delete to be incremented')
|
128
|
+
end
|
129
|
+
|
130
|
+
|
131
|
+
should 'ignore extraneous parameters' do
|
132
|
+
job_id = client.transmit("put 0 0 120 #{@message.bytesize}\r\n#{@message}")[:id]
|
133
|
+
initial_server_cmd_delete = client.transmit('stats')[:body]['cmd-delete']
|
134
|
+
initial_tube_cmd_delete = client.transmit("stats-tube #{tube_name}")[:body]['cmd-delete']
|
135
|
+
response = client.transmit("delete #{job_id} but don't care about these params")
|
136
|
+
assert_equal 'DELETED', response[:status]
|
137
|
+
assert_raises(Beaneater::NotFoundError, 'Expected delete with extraneous parameters to raise NOT_FOUND for deleted job') do
|
138
|
+
client.transmit("delete #{job_id} but ignore these params")
|
139
|
+
end
|
140
|
+
assert_equal(initial_server_cmd_delete + 2, client.transmit('stats')[:body]['cmd-delete'], 'Expected server cmd-delete to be incremented')
|
141
|
+
assert_equal(initial_tube_cmd_delete + 1, client.transmit("stats-tube #{tube_name}")[:body]['cmd-delete'], 'Expected tube cmd-delete to be incremented')
|
142
|
+
end
|
143
|
+
|
144
|
+
|
145
|
+
should 'ignore characters following a valid number' do
|
146
|
+
job_id = client.transmit("put 0 0 120 #{@message.bytesize}\r\n#{@message}")[:id]
|
147
|
+
initial_server_cmd_delete = client.transmit('stats')[:body]['cmd-delete']
|
148
|
+
initial_tube_cmd_delete = client.transmit("stats-tube #{tube_name}")[:body]['cmd-delete']
|
149
|
+
response = client.transmit("delete #{job_id}_but_ignore_these_words")
|
150
|
+
assert_equal 'DELETED', response[:status]
|
151
|
+
assert_raises(Beaneater::NotFoundError, 'Expected delete with extraneous parameters to raise NOT_FOUND for deleted job') do
|
152
|
+
client.transmit("delete #{job_id}_but_ignore_these_words")
|
153
|
+
end
|
154
|
+
assert_equal(initial_server_cmd_delete + 2, client.transmit('stats')[:body]['cmd-delete'], 'Expected server cmd-delete to be incremented')
|
155
|
+
assert_equal(initial_tube_cmd_delete + 1, client.transmit("stats-tube #{tube_name}")[:body]['cmd-delete'], 'Expected tube cmd-delete to be incremented')
|
156
|
+
end
|
157
|
+
|
158
|
+
end
|
159
|
+
|
160
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
require 'beanstalk_integration_tests/test_helper'
|
2
|
+
|
3
|
+
class IgnoreTest < BeanstalkIntegrationTest
|
4
|
+
|
5
|
+
context 'ignore' do
|
6
|
+
|
7
|
+
context 'when a tube is watched' do
|
8
|
+
|
9
|
+
setup do
|
10
|
+
client.transmit("watch #{tube_name}")
|
11
|
+
|
12
|
+
# Use a second client to keep tube open
|
13
|
+
@other_client = build_client
|
14
|
+
@other_client.transmit("watch #{tube_name}")
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
should 'ignore the provided tube' do
|
19
|
+
initial_cmd_ignore = client.transmit('stats')[:body]['cmd-ignore']
|
20
|
+
initial_tube_watching = client.transmit("stats-tube #{tube_name}")[:body]['current-watching']
|
21
|
+
assert(client.transmit('list-tubes-watched')[:body].include?(tube_name), 'Expected watched tube to be listed in list-tubes-watched')
|
22
|
+
response = client.transmit("ignore #{tube_name}")
|
23
|
+
assert_equal 'WATCHING', response[:status]
|
24
|
+
assert_equal '1', response[:id]
|
25
|
+
refute(client.transmit('list-tubes-watched')[:body].include?(tube_name), 'Expected ignore to remove tube from list-tubes-watched')
|
26
|
+
assert_equal(initial_cmd_ignore + 1, client.transmit('stats')[:body]['cmd-ignore'], 'Expected cmd-ignore to be incremented')
|
27
|
+
assert_equal(initial_tube_watching - 1, client.transmit("stats-tube #{tube_name}")[:body]['current-watching'], 'Expected tube current-watching to be decremented')
|
28
|
+
|
29
|
+
@other_client.transmit("ignore #{tube_name}")
|
30
|
+
assert_equal(initial_cmd_ignore + 2, client.transmit('stats')[:body]['cmd-ignore'], 'Expected cmd-ignore to be incremented')
|
31
|
+
assert_raises(Beaneater::NotFoundError, 'Expected unwatched tube to be destroyed') do
|
32
|
+
client.transmit("stats-tube #{tube_name}")
|
33
|
+
end
|
34
|
+
refute(client.transmit('list-tubes')[:body].include?(tube_name), 'Expected ignore to remove tube from list-tubes')
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
should 'not ignore the provided tube if no other tubes are watched' do
|
39
|
+
initial_cmd_ignore = client.transmit('stats')[:body]['cmd-ignore']
|
40
|
+
initial_tube_watching = client.transmit("stats-tube #{tube_name}")[:body]['current-watching']
|
41
|
+
client.transmit('ignore default')
|
42
|
+
assert_raises(Beaneater::NotIgnoredError, 'Expected ignoring last watched tube to return NOT_IGNORED') do
|
43
|
+
client.transmit("ignore #{tube_name}")
|
44
|
+
end
|
45
|
+
assert(client.transmit('list-tubes-watched')[:body].include?(tube_name), 'Expected watched tube to be listed in list-tubes-watched')
|
46
|
+
assert_equal(initial_cmd_ignore + 2, client.transmit('stats')[:body]['cmd-ignore'], 'Expected cmd-ignore to be incremented')
|
47
|
+
assert_equal(initial_tube_watching, client.transmit("stats-tube #{tube_name}")[:body]['current-watching'], 'Expected tube current-watching to be unchanged')
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
should 'return count of tubes watched when ignoring unwatched or non-existent tube' do
|
52
|
+
%w[unwatched non-existant].each do |name|
|
53
|
+
initial_cmd_ignore = client.transmit('stats')[:body]['cmd-ignore']
|
54
|
+
response = client.transmit("ignore #{name}")
|
55
|
+
assert_equal 'WATCHING', response[:status]
|
56
|
+
assert_equal '2', response[:id]
|
57
|
+
assert_equal(initial_cmd_ignore + 1, client.transmit('stats')[:body]['cmd-ignore'], "Expected cmd-ignore to be incremented when ignoring #{name} tube")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
should 'return UNKNOWN_COMMAND if command does not include space' do
|
63
|
+
assert_raises(Beaneater::UnknownCommandError, 'Expected ignore without space to return UNKNOWN_COMMAND') do
|
64
|
+
client.transmit('ignore')
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
should 'return BAD_FORMAT if tube name is not provided' do
|
70
|
+
assert_raises(Beaneater::BadFormatError, 'Expected ignore without tube name to return BAD_FORMAT') do
|
71
|
+
client.transmit('ignore ')
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
should 'be able to handle tube name of maximum length' do
|
77
|
+
name = 'c' * 200
|
78
|
+
initial_watch_count = client.transmit('list-tubes-watched')[:body].length
|
79
|
+
client.transmit("watch #{name}")
|
80
|
+
response = client.transmit("ignore #{name}")
|
81
|
+
assert_equal 'WATCHING', response[:status]
|
82
|
+
assert_equal initial_watch_count.to_s, response[:id]
|
83
|
+
end
|
84
|
+
|
85
|
+
|
86
|
+
should 'return BAD_FORMAT if tube name > 200 bytes' do
|
87
|
+
initital_cmd_ignore = client.transmit('stats')[:body]['cmd-ignore']
|
88
|
+
assert_raises Beaneater::BadFormatError do
|
89
|
+
client.transmit("ignore #{'x' * 201}")
|
90
|
+
end
|
91
|
+
# Use other client because extra long tube name leaves client in weird state
|
92
|
+
assert_equal(initital_cmd_ignore, build_client.transmit('stats')[:body]['cmd-ignore'], 'Expected cmd-ignore to be unchanged')
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
should 'return BAD_FORMAT if line has a trailing space' do
|
97
|
+
initital_cmd_ignore = client.transmit('stats')[:body]['cmd-ignore']
|
98
|
+
assert_raises Beaneater::BadFormatError do
|
99
|
+
client.transmit("ignore #{tube_name} ")
|
100
|
+
end
|
101
|
+
assert_equal(initital_cmd_ignore, client.transmit('stats')[:body]['cmd-ignore'], 'Expected cmd-ignore to be unchanged')
|
102
|
+
end
|
103
|
+
|
104
|
+
|
105
|
+
should 'return BAD_FORMAT if tube name includes invalid characters or starts with hyphen' do
|
106
|
+
initital_cmd_ignore = client.transmit('stats')[:body]['cmd-ignore']
|
107
|
+
valid_chars = ('a'..'z').to_a + ('A'..'Z').to_a + ('0'..'9').to_a + %w[- + / ; . $ _ ( )] + [' ']
|
108
|
+
# Beanstalk hangs on char 13
|
109
|
+
bad_chars = (0..12).to_a.concat((14..255).to_a).to_a.map!(&:chr) - valid_chars
|
110
|
+
|
111
|
+
assert_raises(Beaneater::BadFormatError, 'Expected tube name starting with hyphen to be invalid') do
|
112
|
+
client.transmit('ignore -starts-with-hyphen')
|
113
|
+
end
|
114
|
+
assert_equal(initital_cmd_ignore, client.transmit('stats')[:body]['cmd-ignore'], 'Expected cmd-ignore to be unchanged')
|
115
|
+
|
116
|
+
bad_chars.each do |bad_char|
|
117
|
+
assert_raises(Beaneater::BadFormatError, "Expected tube name with char #{bad_char} to be invalid") do
|
118
|
+
client.transmit("ignore name_with_#{bad_char}_in_it")
|
119
|
+
end
|
120
|
+
end
|
121
|
+
assert_equal(initital_cmd_ignore, client.transmit('stats')[:body]['cmd-ignore'], 'Expected cmd-ignore to be unchanged')
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|