Skip to content

Conversation

@dt-rush
Copy link
Contributor

@dt-rush dt-rush commented Apr 3, 2020

@dt-rush dt-rush requested a review from Page- April 3, 2020 15:41
@dt-rush
Copy link
Contributor Author

dt-rush commented Apr 10, 2020

Odd that this passed on my local:

15 passing (28ms)
  1 failing

  1) Gauge
       should track runtime of promises properly:
     TypeError: promise.finally is not a function
      at MetricsGatherer.resolve (src/metrics-gatherer.ts:125:18)
      at Context.it (test/index.spec.ts:67:11)

Comment on lines +70 to +73
setTimeout(() => {
output = metrics.output();
expect(/promise_running_gauge 0/.test(output)).to.be.true;
}, 200);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change this to

Suggested change
setTimeout(() => {
output = metrics.output();
expect(/promise_running_gauge 0/.test(output)).to.be.true;
}, 200);
await Bluebird.delay(200);
output = metrics.output();
expect(/promise_running_gauge 0/.test(output)).to.be.true;

as it's clearer and also will mean that if the expect(/promise_running_gauge 0/.test(output)).to.be.true fails then it will be handled properly. The same goes for other setTimeouts

Comment on lines +125 to +127
promise.finally(() => {
this.inc(name, -1, labels);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is better as

Suggested change
promise.finally(() => {
this.inc(name, -1, labels);
});
try {
await promise
} finally {
this.inc(name, -1, labels);
}

because it should also handle promises that don't support .finally

Comment on lines +118 to +119
await func();
this.inc(name, -1, labels);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Matching the other function this should be

Suggested change
await func();
this.inc(name, -1, labels);
try {
await func();
} finally {
this.inc(name, -1, labels);
}

and make sure we don't drop decrements

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants