-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP - first pass at percentiles #55
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -647,6 +647,61 @@ test('options.maxFailures should be deprecated', (t) => { | |
cb(passFail, options); | ||
}); | ||
|
||
test('rolling percentile enabled option defaults to true', (t) => { | ||
const breaker = cb(passFail); | ||
t.equals(breaker.status.rollingPercentilesEnabled, true, 'rollingPercentilesEnabled should default to true'); | ||
t.equals(breaker.status.stats.latencyMean, 0, 'latencyMean is starts at 0 when rollingPercentilesEnabled is true'); | ||
[0.0, 0.25, 0.5, 0.75, 0.9, 0.95, 0.99, 0.995, 1].forEach((p) => { | ||
t.equals(breaker.status.stats.percentiles[p], 0, `${p} percentile should be 0 at the start`); | ||
}); | ||
t.end(); | ||
}); | ||
|
||
test('rolling percentile enabled option set to false', (t) => { | ||
const options = { rollingPercentilesEnabled: false }; | ||
const breaker = cb(passFail, options); | ||
t.equals(breaker.status.rollingPercentilesEnabled, false, 'rollingPercentilesEnabled set to false'); | ||
t.equals(breaker.status.stats.latencyMean, -1, 'latencyMean is -1 when rollingPercentilesEnabled is false'); | ||
[0.0, 0.25, 0.5, 0.75, 0.9, 0.95, 0.99, 0.995, 1].forEach((p) => { | ||
t.equals(breaker.status.stats.percentiles[p], -1, `${p} percentile should be -1 when rollingPercentilesEnabled is false`); | ||
}); | ||
t.end(); | ||
}); | ||
|
||
test('Circuit Breaker success event emits latency', (t) => { | ||
t.plan(1); | ||
const breaker = cb(passFail); | ||
breaker.on('success', (result, latencyTime) => { | ||
t.ok(latencyTime, 'second argument is the latency'); | ||
t.end(); | ||
}); | ||
|
||
breaker.fire(1); | ||
}); | ||
|
||
test('Circuit Breaker timeout event emits latency', (t) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should say "Breaker failure event". And the one below should say "Breaker timeout event" :-) |
||
t.plan(1); | ||
const breaker = cb(passFail); | ||
breaker.on('failure', (result, latencyTime) => { | ||
t.ok(latencyTime, 'second argument is the latency'); | ||
t.end(); | ||
}); | ||
|
||
breaker.fire(-1).catch(() => {}); | ||
}); | ||
|
||
test('Circuit Breaker failure event emits latency', (t) => { | ||
t.plan(1); | ||
const breaker = cb(slowFunction, { timeout: 10 }); | ||
|
||
breaker.on('timeout', (result, latencyTime) => { | ||
t.ok(latencyTime, 'second argument is the latency'); | ||
t.end(); | ||
}); | ||
|
||
breaker.fire(-1).catch(() => {}); | ||
}); | ||
|
||
/** | ||
* Returns a promise that resolves if the parameter | ||
* 'x' evaluates to >= 0. Otherwise the returned promise fails. | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just call
push()
? What's the need forapply
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need to concatenate the values in that
latencyTimes
so if we just did push, then we would get something like this:[ [1], [2], [3], [4] ]
instead of[1,2,3,4]
. would be nice if we could use the spread syntax here, but i don't think it goes back to node 4