Skip to content

Commit

Permalink
tests(e2e): Unflake nest cron tests (#13218)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicohrubec authored Aug 5, 2024
1 parent ba370fc commit e6642a7
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@ import { waitForEnvelopeItem } from '@sentry-internal/test-utils';

test('Cron job triggers send of in_progress envelope', async ({ baseURL }) => {
const inProgressEnvelopePromise = waitForEnvelopeItem('nestjs', envelope => {
return envelope[0].type === 'check_in';
return envelope[0].type === 'check_in' && envelope[1]['status'] === 'in_progress';
});

const okEnvelopePromise = waitForEnvelopeItem('nestjs', envelope => {
return envelope[0].type === 'check_in' && envelope[1]['status'] === 'ok';
});

const inProgressEnvelope = await inProgressEnvelopePromise;
const okEnvelope = await okEnvelopePromise;

expect(inProgressEnvelope[1]).toEqual(
expect.objectContaining({
Expand All @@ -29,6 +34,22 @@ test('Cron job triggers send of in_progress envelope', async ({ baseURL }) => {
}),
);

expect(okEnvelope[1]).toEqual(
expect.objectContaining({
check_in_id: expect.any(String),
monitor_slug: 'test-cron-slug',
status: 'ok',
environment: 'qa',
duration: expect.any(Number),
contexts: {
trace: {
span_id: expect.any(String),
trace_id: expect.any(String),
},
},
}),
);

// kill cron so tests don't get stuck
await fetch(`${baseURL}/kill-test-cron`);
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@ import { waitForEnvelopeItem } from '@sentry-internal/test-utils';

test('Cron job triggers send of in_progress envelope', async ({ baseURL }) => {
const inProgressEnvelopePromise = waitForEnvelopeItem('nestjs', envelope => {
return envelope[0].type === 'check_in';
return envelope[0].type === 'check_in' && envelope[1]['status'] === 'in_progress';
});

const okEnvelopePromise = waitForEnvelopeItem('nestjs', envelope => {
return envelope[0].type === 'check_in' && envelope[1]['status'] === 'ok';
});

const inProgressEnvelope = await inProgressEnvelopePromise;
const okEnvelope = await okEnvelopePromise;

expect(inProgressEnvelope[1]).toEqual(
expect.objectContaining({
Expand All @@ -29,6 +34,22 @@ test('Cron job triggers send of in_progress envelope', async ({ baseURL }) => {
}),
);

expect(okEnvelope[1]).toEqual(
expect.objectContaining({
check_in_id: expect.any(String),
monitor_slug: 'test-cron-slug',
status: 'ok',
environment: 'qa',
duration: expect.any(Number),
contexts: {
trace: {
span_id: expect.any(String),
trace_id: expect.any(String),
},
},
}),
);

// kill cron so tests don't get stuck
await fetch(`${baseURL}/kill-test-cron`);
});

0 comments on commit e6642a7

Please sign in to comment.