Skip to content

Commit

Permalink
downgrade packages and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nordfjord committed Jul 1, 2022
1 parent b4783d8 commit e894e88
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
10 changes: 5 additions & 5 deletions packages/opentelemetry-propagation-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@
"@types/mocha": "^9.1.1",
"@types/node": "16.11.21",
"@types/sinon": "^10.0.11",
"expect": "^28.1.1",
"expect": "27.4.2",
"gts": "3.1.0",
"mocha": "^10.0.0",
"nyc": "^15.1.0",
"sinon": "^14.0.0",
"ts-mocha": "^10.0.0",
"mocha": "7.2.0",
"nyc": "15.1.0",
"sinon": "13.0.1",
"ts-mocha": "10.0.0",
"typescript": "4.3.5"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
import { ROOT_CONTEXT, trace } from '@opentelemetry/api';
import expect from 'expect';

const instrumentation = registerInstrumentationTestingProvider();
registerInstrumentationTestingProvider();

const tracer = trace.getTracer('test');

Expand Down Expand Up @@ -80,6 +80,7 @@ describe('Pubsub propagation', () => {

expect(getTestSpans().length).toBe(0);

// @ts-expect-error Typescript thinks this value is used before assignment
resolve(undefined);

// We use setTimeout here to make sure our assertations run
Expand All @@ -89,4 +90,42 @@ describe('Pubsub propagation', () => {
expect(getTestSpans()[0]).toMatchObject({ name: 'test process' });
});
});

it('Span ends on promise-rejection', () => {
const messages = [{}];
utils.patchMessagesArrayToStartProcessSpans({
messages,
tracer,
parentContext: ROOT_CONTEXT,
messageToSpanDetails: () => ({
name: 'test',
parentContext: ROOT_CONTEXT,
attributes: {},
}),
});
utils.patchArrayForProcessSpans(messages, tracer, ROOT_CONTEXT);

expect(getTestSpans().length).toBe(0);

let reject: (value: unknown) => void;

messages.map(
() =>
new Promise((_, rej) => {
reject = rej;
})
);

expect(getTestSpans().length).toBe(0);

// @ts-expect-error Typescript thinks this value is used before assignment
reject(new Error('Failed'));

// We use setTimeout here to make sure our assertations run
// after the promise resolves
return new Promise(res => setTimeout(res, 0)).then(() => {
expect(getTestSpans().length).toBe(1);
expect(getTestSpans()[0]).toMatchObject({ name: 'test process' });
});
});
});

0 comments on commit e894e88

Please sign in to comment.