Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions packages/node/test/handlers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,8 @@ describe('tracingHandler', () => {
});
});

it('lets all spans being finished before calling `finish` itself, despite being registered to `res.finish` event first', done => {
const transaction = new Transaction({ name: 'mockTransaction' });
it('waits to finish transaction until all spans are finished, even though `transaction.finish()` is registered on `res.finish` event first', done => {
const transaction = new Transaction({ name: 'mockTransaction', sampled: true });
transaction.initSpanRecorder();
const span = transaction.startChild({
description: 'reallyCoolHandler',
Expand All @@ -319,6 +319,11 @@ describe('tracingHandler', () => {
const finishSpan = jest.spyOn(span, 'finish');
const finishTransaction = jest.spyOn(transaction, 'finish');

let sentEvent: Event;
jest.spyOn((transaction as any)._hub, 'captureEvent').mockImplementation(event => {
sentEvent = event as Event;
});

sentryTracingMiddleware(req, res, next);
res.once('finish', () => {
span.finish();
Expand All @@ -328,7 +333,9 @@ describe('tracingHandler', () => {
setImmediate(() => {
expect(finishSpan).toHaveBeenCalled();
expect(finishTransaction).toHaveBeenCalled();
expect(span.endTimestamp).toBeLessThan(transaction.endTimestamp!);
expect(span.endTimestamp).toBeLessThanOrEqual(transaction.endTimestamp!);
expect(sentEvent.spans?.length).toEqual(1);
expect(sentEvent.spans?.[0].spanId).toEqual(span.spanId);
done();
});
});
Expand Down