-
Notifications
You must be signed in to change notification settings - Fork 824
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: test-utils * fix: add check,fix scripts * feat: use test-utils package in pg pool plugin * feat: include assertionUtils in test-utils package And use for redis and pg * fix: install required packages * fix: gts
- Loading branch information
1 parent
c829a9c
commit 67d2256
Showing
18 changed files
with
144 additions
and
414 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ import { | |
import * as assert from 'assert'; | ||
import * as mysql from 'mysql'; | ||
import { MysqlPlugin, plugin } from '../src'; | ||
import * as testUtils from './testUtils'; | ||
import * as testUtils from '@opentelemetry/test-utils'; | ||
import { AttributeNames } from '../src/enums'; | ||
import { CanonicalCode } from '@opentelemetry/types'; | ||
|
||
|
@@ -54,7 +54,7 @@ describe('[email protected]', () => { | |
} | ||
tracer.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); | ||
if (testMysqlLocally) { | ||
testUtils.startDocker(); | ||
testUtils.startDocker('mysql'); | ||
// wait 15 seconds for docker container to start | ||
this.timeout(20000); | ||
setTimeout(done, 15000); | ||
|
@@ -66,7 +66,7 @@ describe('[email protected]', () => { | |
after(function() { | ||
if (testMysqlLocally) { | ||
this.timeout(5000); | ||
testUtils.cleanUpDocker(); | ||
testUtils.cleanUpDocker('mysql'); | ||
} | ||
}); | ||
|
||
|
This file was deleted.
Oops, something went wrong.
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
79 changes: 0 additions & 79 deletions
79
packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg-pool/test/assertionUtils.ts
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -20,15 +20,21 @@ import { | |
InMemorySpanExporter, | ||
SimpleSpanProcessor, | ||
} from '@opentelemetry/tracing'; | ||
import { SpanKind, Attributes, TimedEvent, Span } from '@opentelemetry/types'; | ||
import { | ||
SpanKind, | ||
Attributes, | ||
TimedEvent, | ||
Span, | ||
CanonicalCode, | ||
Status, | ||
} from '@opentelemetry/types'; | ||
import { plugin as pgPlugin, PostgresPlugin } from '@opentelemetry/plugin-pg'; | ||
import { plugin, PostgresPoolPlugin } from '../src'; | ||
import { AttributeNames } from '../src/enums'; | ||
import * as assert from 'assert'; | ||
import * as pg from 'pg'; | ||
import * as pgPool from 'pg-pool'; | ||
import * as assertionUtils from './assertionUtils'; | ||
import * as testUtils from './testUtils'; | ||
import * as testUtils from '@opentelemetry/test-utils'; | ||
|
||
const memoryExporter = new InMemorySpanExporter(); | ||
|
||
|
@@ -65,18 +71,23 @@ const DEFAULT_PG_ATTRIBUTES = { | |
[AttributeNames.DB_USER]: CONFIG.user, | ||
}; | ||
|
||
const okStatus: Status = { | ||
code: CanonicalCode.OK, | ||
}; | ||
|
||
const runCallbackTest = ( | ||
parentSpan: Span, | ||
attributes: Attributes, | ||
events: TimedEvent[], | ||
status: Status = okStatus, | ||
spansLength = 1, | ||
spansIndex = 0 | ||
) => { | ||
const spans = memoryExporter.getFinishedSpans(); | ||
assert.strictEqual(spans.length, spansLength); | ||
const pgSpan = spans[spansIndex]; | ||
assertionUtils.assertSpan(pgSpan, SpanKind.CLIENT, attributes, events); | ||
assertionUtils.assertPropagation(pgSpan, parentSpan); | ||
testUtils.assertSpan(pgSpan, SpanKind.CLIENT, attributes, events, status); | ||
testUtils.assertPropagation(pgSpan, parentSpan); | ||
}; | ||
|
||
describe('[email protected]', () => { | ||
|
@@ -97,14 +108,14 @@ describe('[email protected]', () => { | |
pool = new pgPool(CONFIG); | ||
tracer.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); | ||
if (testPostgresLocally) { | ||
testUtils.startDocker(); | ||
testUtils.startDocker('postgres'); | ||
} | ||
done(); | ||
}); | ||
|
||
after(function(done) { | ||
if (testPostgresLocally) { | ||
testUtils.cleanUpDocker(); | ||
testUtils.cleanUpDocker('postgres'); | ||
} | ||
pool.end(() => { | ||
done(); | ||
|
@@ -144,11 +155,11 @@ describe('[email protected]', () => { | |
const span = tracer.startSpan('test span'); | ||
await tracer.withSpan(span, async () => { | ||
const client = await pool.connect(); | ||
runCallbackTest(span, pgPoolattributes, events, 1, 0); | ||
runCallbackTest(span, pgPoolattributes, events, okStatus, 1, 0); | ||
assert.ok(client, 'pool.connect() returns a promise'); | ||
try { | ||
await client.query('SELECT NOW()'); | ||
runCallbackTest(span, pgAttributes, events, 2, 1); | ||
runCallbackTest(span, pgAttributes, events, okStatus, 2, 1); | ||
} catch (e) { | ||
throw e; | ||
} finally { | ||
|
@@ -175,13 +186,13 @@ describe('[email protected]', () => { | |
} | ||
release(); | ||
assert.ok(client); | ||
runCallbackTest(parentSpan, pgPoolattributes, events, 1, 0); | ||
runCallbackTest(parentSpan, pgPoolattributes, events, okStatus, 1, 0); | ||
client.query('SELECT NOW()', (err, ret) => { | ||
if (err) { | ||
return done(err); | ||
} | ||
assert.ok(ret); | ||
runCallbackTest(parentSpan, pgAttributes, events, 2, 1); | ||
runCallbackTest(parentSpan, pgAttributes, events, okStatus, 2, 1); | ||
done(); | ||
}); | ||
}); | ||
|
@@ -205,8 +216,8 @@ describe('[email protected]', () => { | |
await tracer.withSpan(span, async () => { | ||
try { | ||
const result = await pool.query('SELECT NOW()'); | ||
runCallbackTest(span, pgPoolattributes, events, 2, 0); | ||
runCallbackTest(span, pgAttributes, events, 2, 1); | ||
runCallbackTest(span, pgPoolattributes, events, okStatus, 2, 0); | ||
runCallbackTest(span, pgAttributes, events, okStatus, 2, 1); | ||
assert.ok(result, 'pool.query() returns a promise'); | ||
} catch (e) { | ||
throw e; | ||
|
@@ -230,8 +241,8 @@ describe('[email protected]', () => { | |
if (err) { | ||
return done(err); | ||
} | ||
runCallbackTest(parentSpan, pgPoolattributes, events, 2, 0); | ||
runCallbackTest(parentSpan, pgAttributes, events, 2, 1); | ||
runCallbackTest(parentSpan, pgPoolattributes, events, okStatus, 2, 0); | ||
runCallbackTest(parentSpan, pgAttributes, events, okStatus, 2, 1); | ||
done(); | ||
}); | ||
assert.strictEqual(resNoPromise, undefined, 'No promise is returned'); | ||
|
54 changes: 0 additions & 54 deletions
54
packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg-pool/test/testUtils.ts
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.