-
Notifications
You must be signed in to change notification settings - Fork 538
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
65 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,15 +73,15 @@ const DEFAULT_PG_ATTRIBUTES = { | |
[AttributeNames.DB_USER]: CONFIG.user, | ||
}; | ||
|
||
const okStatus: Status = { | ||
code: StatusCode.OK, | ||
const unsetStatus: Status = { | ||
code: StatusCode.UNSET, | ||
}; | ||
|
||
const runCallbackTest = ( | ||
parentSpan: Span, | ||
attributes: Attributes, | ||
events: TimedEvent[], | ||
status: Status = okStatus, | ||
status: Status = unsetStatus, | ||
spansLength = 1, | ||
spansIndex = 0 | ||
) => { | ||
|
@@ -97,11 +97,12 @@ describe('[email protected]', () => { | |
let contextManager: AsyncHooksContextManager; | ||
const provider = new BasicTracerProvider(); | ||
const logger = new NoopLogger(); | ||
const testPostgres = process.env.RUN_POSTGRES_TESTS; // For CI: assumes local postgres db is already available | ||
const testPostgres = process.env.RUN_POSTGRES_TESTS; // For CI: | ||
// assumes local postgres db is already available | ||
const testPostgresLocally = process.env.RUN_POSTGRES_TESTS_LOCAL; // For local: spins up local postgres db via docker | ||
const shouldTest = testPostgres || testPostgresLocally; // Skips these tests if false (default) | ||
|
||
before(function (done) { | ||
before(function () { | ||
if (!shouldTest) { | ||
// this.skip() workaround | ||
// https://github.com/mochajs/mocha/issues/2683#issuecomment-375629901 | ||
|
@@ -113,7 +114,6 @@ describe('[email protected]', () => { | |
if (testPostgresLocally) { | ||
testUtils.startDocker('postgres'); | ||
} | ||
done(); | ||
}); | ||
|
||
after(done => { | ||
|
@@ -161,11 +161,11 @@ describe('[email protected]', () => { | |
const span = provider.getTracer('test-pg-pool').startSpan('test span'); | ||
await provider.getTracer('test-pg-pool').withSpan(span, async () => { | ||
const client = await pool.connect(); | ||
runCallbackTest(span, pgPoolattributes, events, okStatus, 1, 0); | ||
runCallbackTest(span, pgPoolattributes, events, unsetStatus, 1, 0); | ||
assert.ok(client, 'pool.connect() returns a promise'); | ||
try { | ||
await client.query('SELECT NOW()'); | ||
runCallbackTest(span, pgAttributes, events, okStatus, 2, 1); | ||
runCallbackTest(span, pgAttributes, events, unsetStatus, 2, 1); | ||
} finally { | ||
client.release(); | ||
} | ||
|
@@ -197,14 +197,28 @@ describe('[email protected]', () => { | |
throw new Error('No client received'); | ||
} | ||
assert.ok(client); | ||
runCallbackTest(parentSpan, pgPoolattributes, events, okStatus, 1, 0); | ||
runCallbackTest( | ||
parentSpan, | ||
pgPoolattributes, | ||
events, | ||
unsetStatus, | ||
1, | ||
0 | ||
); | ||
client.query('SELECT NOW()', (err, ret) => { | ||
release(); | ||
if (err) { | ||
return done(err); | ||
} | ||
assert.ok(ret); | ||
runCallbackTest(parentSpan, pgAttributes, events, okStatus, 2, 1); | ||
runCallbackTest( | ||
parentSpan, | ||
pgAttributes, | ||
events, | ||
unsetStatus, | ||
2, | ||
1 | ||
); | ||
done(); | ||
}); | ||
}); | ||
|
@@ -227,8 +241,8 @@ describe('[email protected]', () => { | |
const span = provider.getTracer('test-pg-pool').startSpan('test span'); | ||
await provider.getTracer('test-pg-pool').withSpan(span, async () => { | ||
const result = await pool.query('SELECT NOW()'); | ||
runCallbackTest(span, pgPoolattributes, events, okStatus, 2, 0); | ||
runCallbackTest(span, pgAttributes, events, okStatus, 2, 1); | ||
runCallbackTest(span, pgPoolattributes, events, unsetStatus, 2, 0); | ||
runCallbackTest(span, pgAttributes, events, unsetStatus, 2, 1); | ||
assert.ok(result, 'pool.query() returns a promise'); | ||
}); | ||
}); | ||
|
@@ -251,8 +265,15 @@ describe('[email protected]', () => { | |
if (err) { | ||
return done(err); | ||
} | ||
runCallbackTest(parentSpan, pgPoolattributes, events, okStatus, 2, 0); | ||
runCallbackTest(parentSpan, pgAttributes, events, okStatus, 2, 1); | ||
runCallbackTest( | ||
parentSpan, | ||
pgPoolattributes, | ||
events, | ||
unsetStatus, | ||
2, | ||
0 | ||
); | ||
runCallbackTest(parentSpan, pgAttributes, events, unsetStatus, 2, 1); | ||
done(); | ||
}); | ||
assert.strictEqual(resNoPromise, undefined, 'No promise is returned'); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters