Skip to content

Commit 03f1d3c

Browse files
authored
Fix flaky unit test in lib/core/usage.spec.ts (#6503)
1 parent 5307b0c commit 03f1d3c

File tree

1 file changed

+6
-19
lines changed

1 file changed

+6
-19
lines changed

packages/libraries/core/tests/usage.spec.ts

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ test('should send data to Hive (deprecated endpoint)', async () => {
333333
expect(operation.execution.ok).toBe(true);
334334
});
335335

336-
test('should not leak the exception', { retry: 3 }, async () => {
336+
test('should not leak the exception', async () => {
337337
const logger = createHiveTestingLogger();
338338

339339
const hive = createHive({
@@ -374,7 +374,7 @@ test('should not leak the exception', { retry: 3 }, async () => {
374374
`);
375375
});
376376

377-
test('sendImmediately should not stop the schedule', { retry: 3 }, async () => {
377+
test('sendImmediately should not stop the schedule', async () => {
378378
const logger = createHiveTestingLogger();
379379

380380
const token = 'Token';
@@ -431,34 +431,21 @@ test('sendImmediately should not stop the schedule', { retry: 3 }, async () => {
431431
// since we sent only 1 element, the buffer was not full,
432432
// so we should not see "Sending immediately"
433433

434-
expect(logger.getLogs()).toMatchInlineSnapshot(`
435-
[INF] [hive][usage] Sending report (queue 1)
436-
[INF] [hive][usage] POST http://localhost/200 (x-request-id=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)
437-
[INF] [hive][usage] POST http://localhost/200 (x-request-id=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx) succeeded with status 200 (666ms).
438-
[INF] [hive][usage] Report sent!
439-
`);
434+
expect(logger.getLogs()).not.toMatch('Sending immediately');
440435
logger.clear();
441436

442437
// Now we will hit the maxSize
443438
// We run collect two times
444439
await Promise.all([collect(args, {}), collect(args, {})]);
445440
await waitFor(1);
446-
expect(logger.getLogs()).toMatchInlineSnapshot(`
447-
[INF] [hive][usage] Sending immediately
448-
[INF] [hive][usage] Sending report (queue 2)
449-
[INF] [hive][usage] POST http://localhost/200 (x-request-id=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)
450-
`);
441+
expect(logger.getLogs()).toMatch('Sending immediately');
442+
expect(logger.getLogs()).toMatch('Sending report (queue 2)');
451443
logger.clear();
452444
await waitFor(100);
453445
// Let's check if the scheduled send task is still running
454446
await collect(args, {});
455447
await waitFor(40);
456-
expect(logger.getLogs()).toMatchInlineSnapshot(`
457-
[INF] [hive][usage] POST http://localhost/200 (x-request-id=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx) succeeded with status 200 (666ms).
458-
[INF] [hive][usage] Report sent!
459-
[INF] [hive][usage] Sending report (queue 1)
460-
[INF] [hive][usage] POST http://localhost/200 (x-request-id=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)
461-
`);
448+
expect(logger.getLogs()).toMatch('Sending report (queue 1)');
462449

463450
await hive.dispose();
464451
http.done();

0 commit comments

Comments
 (0)