chore-core 1.5.10 → 1.7.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.
@@ -1,33 +1,31 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Chore::Strategy::SingleWorkerStrategy do
4
- let(:manager) { mock('Manager') }
4
+ let(:manager) { double('Manager') }
5
5
  subject { described_class.new(manager) }
6
6
 
7
7
  describe '#stop!' do
8
8
  before(:each) do
9
- subject.stub(:worker).and_return worker
9
+ expect(subject).to receive(:worker).and_return worker
10
10
  end
11
11
 
12
12
  context 'given there is no current worker' do
13
13
  let(:worker) { nil }
14
14
 
15
15
  it 'does nothing' do
16
- allow_message_expectations_on_nil
17
-
18
- worker.should_not_receive(:stop!)
16
+ expect(worker).to_not receive(:stop!)
19
17
  subject.stop!
20
18
  end
21
19
  end
22
20
 
23
21
  context 'given there is a current worker' do
24
- let(:worker) { mock('Worker') }
22
+ let(:worker) { double('Worker') }
25
23
  before(:each) do
26
- subject.stub(:worker).and_return worker
24
+ expect(subject).to receive(:worker).and_return worker
27
25
  end
28
26
 
29
27
  it 'stops the worker' do
30
- worker.should_receive(:stop!)
28
+ expect(worker).to receive(:stop!)
31
29
  subject.stop!
32
30
  end
33
31
  end
@@ -4,7 +4,9 @@ describe Chore::Worker do
4
4
 
5
5
  class SimpleJob
6
6
  include Chore::Job
7
- queue_options :name => 'test', :publisher => FakePublisher, :max_attempts => 100
7
+ queue_options :name => 'test',
8
+ :publisher => FakePublisher,
9
+ :max_attempts => 100
8
10
 
9
11
  def perform(*args)
10
12
  return args
@@ -140,4 +142,55 @@ describe Chore::Worker do
140
142
  end
141
143
  end
142
144
  end
145
+
146
+ describe 'delaying retries' do
147
+ let(:encoded_job) { Chore::Encoder::JsonEncoder.encode(job) }
148
+ let(:parsed_job) { JSON.parse(encoded_job) }
149
+ let(:work) { Chore::UnitOfWork.new(2, 'test', 60, encoded_job, 0, consumer) }
150
+
151
+ before(:each) do
152
+ SimpleJob.options[:backoff] = lambda { |work| work.current_attempt }
153
+
154
+ allow(SimpleJob).to receive(:perform).and_raise(RuntimeError)
155
+ SimpleJob.stub(:run_hooks_for).and_return(true)
156
+ end
157
+
158
+ context 'and the consumer can delay' do
159
+ before(:each) do
160
+ allow(consumer).to receive(:delay).and_return(0)
161
+ end
162
+
163
+ it 'will not complete the message' do
164
+ expect(consumer).not_to receive(:complete)
165
+ Chore::Worker.start(work)
166
+ end
167
+
168
+ it 'will delay the message' do
169
+ expect(consumer).to receive(:delay).with(work, SimpleJob.options[:backoff])
170
+ Chore::Worker.start(work)
171
+ end
172
+
173
+ it 'triggers the on_delay callback' do
174
+ expect(SimpleJob).to receive(:run_hooks_for).with(:on_delay, parsed_job)
175
+ Chore::Worker.start(work)
176
+ end
177
+ end
178
+
179
+ context 'and the consumer cannot delay' do
180
+ before(:each) do
181
+ allow(consumer).to receive(:delay).and_raise(NoMethodError)
182
+ end
183
+
184
+ it 'will not complete the item' do
185
+ expect(consumer).not_to receive(:complete)
186
+ Chore::Worker.start(work)
187
+ end
188
+
189
+ it 'triggers the failure callback' do
190
+ worker = Chore::Worker.new(work)
191
+ expect(worker).to receive(:handle_failure)
192
+ worker.start
193
+ end
194
+ end
195
+ end
143
196
  end
data/spec/chore_spec.rb CHANGED
@@ -7,7 +7,7 @@ describe Chore do
7
7
  it 'should allow you to add a hook' do
8
8
  blk = proc { true }
9
9
  Chore.add_hook(:before_perform,&blk)
10
- Chore.hooks_for(:before_perform).first.should == blk
10
+ expect(Chore.hooks_for(:before_perform).first).to be blk
11
11
  end
12
12
 
13
13
  it 'should call a hook if it exists' do
@@ -23,14 +23,14 @@ describe Chore do
23
23
 
24
24
  it 'should pass args to the block if present' do
25
25
  blk = proc {|*args| true }
26
- blk.should_receive(:call).with('1','2',3)
26
+ expect(blk).to receive(:call).with('1','2',3)
27
27
  Chore.add_hook(:an_event,&blk)
28
28
  Chore.run_hooks_for(:an_event, '1','2',3)
29
29
  end
30
30
 
31
31
  it 'should support multiple hooks for an event' do
32
32
  blk = proc { true }
33
- blk.should_receive(:call).twice
33
+ expect(blk).to receive(:call).twice
34
34
  Chore.add_hook(:before_perform,&blk)
35
35
  Chore.add_hook(:before_perform,&blk)
36
36
 
@@ -41,8 +41,8 @@ describe Chore do
41
41
  runner = proc { }
42
42
 
43
43
  blk = proc { true }
44
- blk.should_receive(:call) do |&arg1|
45
- arg1.should_not be_nil
44
+ expect(blk).to receive(:call) do |&arg1|
45
+ expect(arg1).to_not be nil
46
46
  end
47
47
  Chore.add_hook(:around_perform,&blk)
48
48
 
@@ -56,51 +56,51 @@ describe Chore do
56
56
 
57
57
  run = false
58
58
  Chore.run_hooks_for(:around_perform) { run = true }
59
- run.should be_true
59
+ expect(run).to be true
60
60
  end
61
61
 
62
62
  it 'should call passed blocks even if there are no hooks' do
63
63
  run = false
64
64
  Chore.run_hooks_for(:around_perform) { run = true }
65
- run.should be_true
65
+ expect(run).to be true
66
66
  end
67
67
 
68
68
  it 'should set configuration' do
69
69
  Chore.configure {|c| c.test_config_option = 'howdy' }
70
- Chore.config.test_config_option.should == 'howdy'
70
+ expect(Chore.config.test_config_option).to eq 'howdy'
71
71
  end
72
72
 
73
73
  describe 'reopen_logs' do
74
74
  let(:open_files) do
75
75
  [
76
- mock('file', :closed? => false, :reopen => nil, :sync= => nil, :path => '/a'),
77
- mock('file2', :closed? => false, :reopen => nil, :sync= => nil, :path => '/b')
76
+ double('file', :closed? => false, :reopen => nil, :sync= => nil, :path => '/a'),
77
+ double('file2', :closed? => false, :reopen => nil, :sync= => nil, :path => '/b')
78
78
  ]
79
79
  end
80
80
  let(:closed_files) do
81
- [mock('file3', :closed? => true)]
81
+ [double('file3', :closed? => true)]
82
82
  end
83
83
  let(:files) { open_files + closed_files }
84
84
 
85
85
  before(:each) do
86
- ObjectSpace.stub(:each_object).and_yield(open_files[0]).and_yield(open_files[1])
86
+ allow(ObjectSpace).to receive(:each_object).and_yield(open_files[0]).and_yield(open_files[1])
87
87
  end
88
88
 
89
89
  it 'should look up all instances of files' do
90
- ObjectSpace.should_receive(:each_object).with(File)
90
+ expect(ObjectSpace).to receive(:each_object).with(File)
91
91
  Chore.reopen_logs
92
92
  end
93
93
 
94
94
  it 'should reopen files that are not closed' do
95
95
  open_files.each do |file|
96
- file.should_receive(:reopen).with(file.path, 'a+')
96
+ expect(file).to receive(:reopen).with(file.path, 'a+')
97
97
  end
98
98
  Chore.reopen_logs
99
99
  end
100
100
 
101
101
  it 'should sync files' do
102
102
  open_files.each do |file|
103
- file.should_receive(:sync=).with(true)
103
+ expect(file).to receive(:sync=).with(true)
104
104
  end
105
105
  Chore.reopen_logs
106
106
  end
data/spec/spec_helper.rb CHANGED
@@ -26,7 +26,7 @@ class FakePublisher < Chore::Publisher
26
26
  end
27
27
  end
28
28
 
29
- TestMessage = Struct.new(:handle,:queue,:body,:receive_count) do
29
+ TestMessage = Struct.new(:handle, :queue, :body, :receive_count) do
30
30
  def empty?
31
31
  false
32
32
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chore-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.10
4
+ version: 1.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tapjoy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-08 00:00:00.000000000 Z
11
+ date: 2015-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: aws-sdk
28
+ name: aws-sdk-v1
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
@@ -64,14 +64,14 @@ dependencies:
64
64
  requirements:
65
65
  - - "~>"
66
66
  - !ruby/object:Gem::Version
67
- version: 2.12.0
67
+ version: 3.3.0
68
68
  type: :development
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
72
  - - "~>"
73
73
  - !ruby/object:Gem::Version
74
- version: 2.12.0
74
+ version: 3.3.0
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: rdoc
77
77
  requirement: !ruby/object:Gem::Requirement