Skip to content

Commit

Permalink
test: make metrics.test.js less flaky (#1715)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelnisi authored and misterdjules committed Nov 7, 2018
1 parent 55b2db7 commit 11d6458
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
16 changes: 8 additions & 8 deletions lib/plugins/multipartBodyParser.js
Expand Up @@ -120,14 +120,14 @@ function multipartBodyParser(options) {
fs.readFile(files[f].path, function readFile(ex, data) {
barrier.done('fs' + f);
/*
* We want to stop the request here, if there's
* an error trying to read the file from disk.
* Ideally we'd like to stop the other oustanding
* file reads too, but there's no way to cancel
* in flight fs reads. So we just return an
* error, and be grudgingly let the other file
* reads finish.
*/
* We want to stop the request here, if there's
* an error trying to read the file from disk.
* Ideally we'd like to stop the other oustanding
* file reads too, but there's no way to cancel
* in flight fs reads. So we just return an
* error, and be grudgingly let the other file
* reads finish.
*/
if (ex) {
return next(
new errors.InternalError(
Expand Down
9 changes: 7 additions & 2 deletions test/plugins/metrics.test.js
Expand Up @@ -203,11 +203,16 @@ describe('request metrics plugin', function() {
// However the timeout value is 200,
// it's calculated by the client,
// but setTimeout is happening on the server, tolerate 10ms
assert.isAtLeast(metrics.preLatency, 50);

// Expected pre-latency has been adjusted from 50 to 49
// to work around timer issues in Node.js <11
// https://github.com/nodejs/node/issues/10154
assert.isAtLeast(metrics.preLatency, 49);

assert.isAtLeast(metrics.useLatency, 50);
assert.isAtLeast(metrics.routeLatency, 250);
assert.isAtLeast(metrics.latency, 200 - 10);
// latency should dbe lower as request timeouts
// latency should be lower as request timeouts
assert.isAbove(metrics.routeLatency, metrics.latency);
assert.equal(metrics.path, '/foo');
assert.equal(metrics.method, 'GET');
Expand Down

0 comments on commit 11d6458

Please sign in to comment.