-
-
Notifications
You must be signed in to change notification settings - Fork 495
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #267 from codekitchen/failure-backoff
Failure backoff Close #30
- Loading branch information
Showing
5 changed files
with
131 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
require 'spec_helper' | ||
require 'timecop' | ||
|
||
describe Raven::ClientState do | ||
let(:state) { Raven::ClientState.new } | ||
|
||
it 'should try when online' do | ||
expect(state.should_try?).to eq(true) | ||
end | ||
|
||
it 'should not try with a new error' do | ||
state.failure | ||
expect(state.should_try?).to eq(false) | ||
end | ||
|
||
it 'should try again after time passes' do | ||
Timecop.freeze(-10) { state.failure } | ||
expect(state.should_try?).to eq(true) | ||
end | ||
|
||
it 'should try again after success' do | ||
state.failure | ||
state.success | ||
expect(state.should_try?).to eq(true) | ||
end | ||
|
||
it 'should try again after retry_after' do | ||
Timecop.freeze(-2) { state.failure(1) } | ||
expect(state.should_try?).to eq(true) | ||
end | ||
|
||
it 'should exponentially backoff' do | ||
Timecop.freeze do | ||
state.failure | ||
Timecop.travel(2) | ||
expect(state.should_try?).to eq(true) | ||
|
||
state.failure | ||
Timecop.travel(3) | ||
expect(state.should_try?).to eq(false) | ||
Timecop.travel(2) | ||
expect(state.should_try?).to eq(true) | ||
|
||
state.failure | ||
Timecop.travel(8) | ||
expect(state.should_try?).to eq(false) | ||
Timecop.travel(2) | ||
expect(state.should_try?).to eq(true) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters