test(sdk-metrics): fix multiple problematic assertRejects() calls (#5611)

This commit is contained in:
Colin Ihrig 2025-04-14 05:32:53 -04:00 committed by GitHub
parent 37fe1e495b
commit c89cb38d0f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 3 deletions

View File

@ -25,6 +25,8 @@ For notes on migrating to 2.x / 0.200.x see [the upgrade guide](doc/upgrade-to-2
### :house: Internal
* test(sdk-metrics): fix multiple problematic assertRejects() calls [#5611](https://github.com/open-telemetry/opentelemetry-js/pull/5611) @cjihrig
## 2.0.0
### Summary

View File

@ -119,7 +119,7 @@ describe('MetricReader', () => {
reader.setMetricProducer(new TestMetricProducer());
await reader.shutdown();
assertRejects(reader.collect(), /MetricReader is shutdown/);
await assertRejects(reader.collect(), /MetricReader is shutdown/);
});
it('should call MetricProducer.collect with timeout', async () => {

View File

@ -32,11 +32,16 @@ describe('utils', () => {
describe('callWithTimeout', () => {
it('should reject if given promise not settled before timeout', async () => {
sinon.useFakeTimers();
const clock = sinon.useFakeTimers();
const promise = new Promise(() => {
/** promise never settles */
});
assertRejects(callWithTimeout(promise, 100), TimeoutError);
const assertion = assertRejects(
callWithTimeout(promise, 100),
TimeoutError
);
clock.tick(101);
await assertion;
});
});