beaneater 1.1.4 → 1.3.0

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/tube_test.rb CHANGED
@@ -96,11 +96,134 @@ describe Beaneater::Tube do
96
96
  assert_equal 'hi: there! this: is a long message', @tube.peek(:ready).body['message']
97
97
  end
98
98
 
99
+ it "should keep the connection usable when the custom parser raises" do
100
+ Beaneater.configure.job_parser = lambda { |b| JSON.parse(b) }
101
+ @tube.put('not json')
102
+ socket = @beanstalk.connection.connection
103
+ assert_raises(JSON::ParserError) { @tube.peek(:ready) }
104
+ assert_same socket, @beanstalk.connection.connection
105
+ assert_equal 'baz', @beanstalk.tubes.used.name
106
+ end
107
+
99
108
  after do
100
109
  Beaneater.configure.job_parser = lambda { |b| b }
101
110
  end
102
111
  end # peek
103
112
 
113
+ describe "for a job_parser that raises on reserve" do
114
+ before do
115
+ Beaneater.configure.job_parser = lambda { |b| JSON.parse(b) }
116
+ @tube = @beanstalk.tubes.find('poison_tube')
117
+ @poison_id = @tube.put('not json', :pri => 1)[:id]
118
+ @tube.put('{"ok":1}', :pri => 2)
119
+ @beanstalk.tubes.watch!('poison_tube')
120
+ end
121
+
122
+ after do
123
+ Beaneater.configure.job_parser = lambda { |b| b }
124
+ # The bad job is still reserved by this connection, which clearing the tube can't touch;
125
+ # left alone, it would be released when the socket is collected, into a later test.
126
+ begin
127
+ @beanstalk.connection.transmit("delete #{@poison_id}")
128
+ rescue Beaneater::NotFoundError
129
+ nil
130
+ end
131
+ cleanup_tubes!(['poison_tube'])
132
+ end
133
+
134
+ it "should raise the parser's own error from reserve, tagged with the job id" do
135
+ error = assert_raises(JSON::ParserError) { @beanstalk.tubes.reserve(0) }
136
+ assert_kind_of Beaneater::JobParseFailure, error
137
+ assert_equal @poison_id, error.job_id
138
+ assert_nil error.cause # the parser's error had none
139
+ Beaneater.configure.job_parser = lambda { |b| b }
140
+ assert_equal 'reserved', @beanstalk.connection.transmit("stats-job #{error.job_id}")[:body]['state']
141
+ end
142
+
143
+ it "should keep the parser's error intact: class, message, backtrace and cause" do
144
+ original = nil
145
+ Beaneater.configure.job_parser = lambda do |b|
146
+ begin
147
+ JSON.parse(b)
148
+ rescue JSON::ParserError => ex
149
+ original = ex
150
+ raise ArgumentError, 'not a job' # its cause is the ParserError
151
+ end
152
+ end
153
+ error = assert_raises(ArgumentError) { @beanstalk.tubes.reserve(0) }
154
+ assert_equal @poison_id, error.job_id
155
+ assert_equal 'not a job', error.message
156
+ assert_same original, error.cause
157
+ assert_operator error.backtrace.first, :include?, 'tube_test.rb'
158
+ refute_nil error.backtrace_locations
159
+ end
160
+
161
+ # An exception class that can't be copied on any Ruby (clone calls initialize_copy)
162
+ class UncopyableError < StandardError
163
+ def initialize_copy(_original)
164
+ raise TypeError, "can't copy"
165
+ end
166
+ end
167
+
168
+ # An exception class whose #cause is not an exception
169
+ class OddCauseError < StandardError
170
+ def cause
171
+ 'not an exception'
172
+ end
173
+ end
174
+
175
+ it "should raise the parser's own exception, untagged, when it can't be copied" do
176
+ Beaneater.configure.job_parser = lambda { |b| raise UncopyableError, 'no copies' }
177
+ error = assert_raises(UncopyableError) { @beanstalk.tubes.reserve(0) }
178
+ assert_equal 'no copies', error.message
179
+ refute_kind_of Beaneater::JobParseFailure, error
180
+ end
181
+
182
+ it "should raise a frozen exception that can't be copied as it is" do
183
+ frozen = UncopyableError.new('frozen, no copies').freeze
184
+ Beaneater.configure.job_parser = lambda { |b| raise frozen }
185
+ error = assert_raises(UncopyableError) { @beanstalk.tubes.reserve(0) }
186
+ assert_same frozen, error
187
+ assert_nil error.cause
188
+ end
189
+
190
+ it "should tag the copy when the exception's cause is not an exception" do
191
+ Beaneater.configure.job_parser = lambda { |b| raise OddCauseError, 'odd' }
192
+ error = assert_raises(OddCauseError) { @beanstalk.tubes.reserve(0) }
193
+ assert_equal @poison_id, error.job_id
194
+ end
195
+
196
+ it "should not tag an exception the parser reuses, so a later error carries no old id" do
197
+ shared = JSON::ParserError.new('always this one')
198
+ Beaneater.configure.job_parser = lambda { |b| raise shared }
199
+ error = assert_raises(JSON::ParserError) { @beanstalk.tubes.reserve(0) }
200
+ assert_equal @poison_id, error.job_id
201
+ peeked = assert_raises(JSON::ParserError) { @tube.peek(:ready) } # not a reserve: not tagged
202
+ refute_kind_of Beaneater::JobParseFailure, peeked
203
+ refute_kind_of Beaneater::JobParseFailure, shared
204
+ end
205
+
206
+ it "should keep the connection, so the bad job stays reserved and the next job is delivered" do
207
+ socket = @beanstalk.connection.connection
208
+ assert_raises(JSON::ParserError) { @beanstalk.tubes.reserve(0) }
209
+ assert_same socket, @beanstalk.connection.connection
210
+ job = @beanstalk.tubes.reserve(0)
211
+ assert_equal({ 'ok' => 1 }, job.body)
212
+ job.delete
213
+ end
214
+
215
+ it "should keep the connection when the raising parser used the same client first" do
216
+ tube = 'poison_tube'
217
+ Beaneater.configure.job_parser = lambda { |b| @beanstalk.connection.transmit("use #{tube}"); JSON.parse(b) }
218
+ socket = @beanstalk.connection.connection
219
+ assert_raises(JSON::ParserError) { @beanstalk.tubes.reserve(0) }
220
+ assert_same socket, @beanstalk.connection.connection
221
+ job = @beanstalk.tubes.reserve(0)
222
+ assert_equal({ 'ok' => 1 }, job.body)
223
+ job.delete
224
+ end
225
+ end # job_parser that raises on reserve
226
+
104
227
  describe "for #reserve" do
105
228
  before do
106
229
  @time = Time.now.to_i
data/test/tubes_test.rb CHANGED
@@ -46,6 +46,13 @@ describe Beaneater::Tubes do
46
46
  it 'should raise invalid name for bad tube' do
47
47
  assert_raises(Beaneater::InvalidTubeName) { @beanstalk.tubes.watch('; ') }
48
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
49
56
  end # watch! & watched
50
57
 
51
58
  describe "for #all" do
@@ -60,6 +67,13 @@ describe Beaneater::Tubes do
60
67
  assert @beanstalk.tubes.all.map(&:name).include?(t)
61
68
  end
62
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
63
77
  end # all
64
78
 
65
79
  describe "for Enumerable" do
@@ -116,6 +130,13 @@ describe Beaneater::Tubes do
116
130
  @beanstalk.tubes.ignore('foo')
117
131
  assert_equal ['default', 'bar'].sort, @beanstalk.tubes.watched.map(&:name).sort
118
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
119
140
  end # ignore
120
141
 
121
142
  describe "for #reserve" do
@@ -157,8 +178,16 @@ describe Beaneater::Tubes do
157
178
  @tube.reserve.delete
158
179
  @tube.put "foo reserve #{@time}", :ttr => 1
159
180
  @beanstalk.tubes.watch 'tube'
160
- @beanstalk.tubes.reserve
181
+ job = @beanstalk.tubes.reserve
161
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
162
191
  end
163
192
 
164
193
  end # reserve
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beaneater
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.4
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nico Taing
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-03-07 00:00:00.000000000 Z
11
+ date: 2026-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -89,7 +89,6 @@ extra_rdoc_files: []
89
89
  files:
90
90
  - ".github/workflows/ruby.yml"
91
91
  - ".gitignore"
92
- - ".travis.yml"
93
92
  - ".yardopts"
94
93
  - CHANGELOG.md
95
94
  - Gemfile
@@ -100,6 +99,7 @@ files:
100
99
  - beaneater.gemspec
101
100
  - examples/demo.rb
102
101
  - lib/beaneater.rb
102
+ - lib/beaneater/arguments.rb
103
103
  - lib/beaneater/configuration.rb
104
104
  - lib/beaneater/connection.rb
105
105
  - lib/beaneater/errors.rb
@@ -113,6 +113,7 @@ files:
113
113
  - lib/beaneater/tube/collection.rb
114
114
  - lib/beaneater/tube/record.rb
115
115
  - lib/beaneater/version.rb
116
+ - test/arguments_test.rb
116
117
  - test/beaneater_test.rb
117
118
  - test/connection_test.rb
118
119
  - test/errors_test.rb
@@ -124,10 +125,14 @@ files:
124
125
  - test/test_helper.rb
125
126
  - test/tube_test.rb
126
127
  - test/tubes_test.rb
127
- homepage: ''
128
+ homepage: https://github.com/beanstalkd/beaneater
128
129
  licenses:
129
130
  - MIT
130
- metadata: {}
131
+ metadata:
132
+ changelog_uri: https://github.com/beanstalkd/beaneater/blob/master/CHANGELOG.md
133
+ source_code_uri: https://github.com/beanstalkd/beaneater
134
+ bug_tracker_uri: https://github.com/beanstalkd/beaneater/issues
135
+ rubygems_mfa_required: 'true'
131
136
  post_install_message:
132
137
  rdoc_options: []
133
138
  require_paths:
@@ -136,7 +141,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
136
141
  requirements:
137
142
  - - ">="
138
143
  - !ruby/object:Gem::Version
139
- version: '0'
144
+ version: '2.7'
140
145
  required_rubygems_version: !ruby/object:Gem::Requirement
141
146
  requirements:
142
147
  - - ">="
@@ -148,6 +153,7 @@ signing_key:
148
153
  specification_version: 4
149
154
  summary: Simple beanstalkd client for ruby.
150
155
  test_files:
156
+ - test/arguments_test.rb
151
157
  - test/beaneater_test.rb
152
158
  - test/connection_test.rb
153
159
  - test/errors_test.rb
data/.travis.yml DELETED
@@ -1,15 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.5
4
- - 2.6
5
- - 2.7
6
- - 3.0
7
- before_install:
8
- - curl -L https://github.com/kr/beanstalkd/archive/v1.9.tar.gz | tar xz -C /tmp
9
- - cd /tmp/beanstalkd-1.9/
10
- - make
11
- - ./beanstalkd &
12
- - cd $TRAVIS_BUILD_DIR
13
- script:
14
- - bundle install
15
- - bundle exec rake test:full