Skip to content

Commit 840ee2a

Browse files
authored
chore(tests): Made tests use real spans instead of plain objects (#7887)
* made test use real spans instead of plain objects and change inernal context to use context() * fix fs tests
1 parent 2dd93e2 commit 840ee2a

14 files changed

Lines changed: 41 additions & 39 deletions

File tree

packages/datadog-plugin-aerospike/test/index.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,11 @@ describe('Plugin', () => {
243243
})
244244

245245
it('should run the callback in the parent context', done => {
246-
const obj = {}
246+
const span = tracer.startSpan('test')
247247
aerospike.connect(config).then(client => {
248-
tracer.scope().activate(obj, () => {
248+
tracer.scope().activate(span, () => {
249249
client.put(key, { i: 123 }, () => {
250-
assert.strictEqual(tracer.scope().active(), obj)
250+
assert.strictEqual(tracer.scope().active(), span)
251251
client.close(false)
252252
done()
253253
})

packages/datadog-plugin-avsc/test/index.spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ describe('Plugin', () => {
8181
const buf = type.toBuffer({ name: 'Alyssa', favorite_number: 256, favorite_color: null })
8282
fs.writeFileSync(filePath, buf)
8383

84-
assert.strictEqual(span._name, 'user.serialize')
84+
assert.strictEqual(span.context()._name, 'user.serialize')
8585

8686
assert.strictEqual(compareJson(BASIC_USER_SCHEMA_DEF, span), true)
8787
assert.strictEqual(span.context()._tags[SCHEMA_TYPE], 'avro')
@@ -112,7 +112,7 @@ describe('Plugin', () => {
112112
})
113113
fs.writeFileSync(filePath, buf)
114114

115-
assert.strictEqual(span._name, 'advanced_user.serialize')
115+
assert.strictEqual(span.context()._name, 'advanced_user.serialize')
116116

117117
assert.strictEqual(compareJson(ADVANCED_USER_SCHEMA_DEF, span), true)
118118
assert.strictEqual(span.context()._tags[SCHEMA_TYPE], 'avro')
@@ -133,7 +133,7 @@ describe('Plugin', () => {
133133
tracer.trace('user.deserialize', span => {
134134
type.fromBuffer(buf)
135135

136-
assert.strictEqual(span._name, 'user.deserialize')
136+
assert.strictEqual(span.context()._name, 'user.deserialize')
137137

138138
assert.strictEqual(compareJson(BASIC_USER_SCHEMA_DEF, span), true)
139139
assert.strictEqual(span.context()._tags[SCHEMA_TYPE], 'avro')
@@ -165,7 +165,7 @@ describe('Plugin', () => {
165165
tracer.trace('advanced_user.deserialize', span => {
166166
type.fromBuffer(buf)
167167

168-
assert.strictEqual(span._name, 'advanced_user.deserialize')
168+
assert.strictEqual(span.context()._name, 'advanced_user.deserialize')
169169

170170
assert.strictEqual(compareJson(ADVANCED_USER_SCHEMA_DEF, span), true)
171171
assert.strictEqual(span.context()._tags[SCHEMA_TYPE], 'avro')

packages/datadog-plugin-aws-sdk/test/aws-sdk.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ describe('Plugin', () => {
201201
}
202202

203203
it('should bind callbacks to the correct active span', (done) => {
204-
const span = {}
204+
const span = tracer.startSpan('test')
205205

206206
tracer.scope().activate(span, () => {
207207
s3.listBuckets({}, () => {

packages/datadog-plugin-express/test/index.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1047,7 +1047,7 @@ describe('Plugin', () => {
10471047
it('should activate a span for every middleware on a route', done => {
10481048
const app = express()
10491049

1050-
const span = {}
1050+
const span = tracer.startSpan('test')
10511051

10521052
app.get(
10531053
'/user',

packages/datadog-plugin-fs/test/index.spec.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1883,7 +1883,8 @@ describe('Plugin', () => {
18831883
if (name.split('.').reduce(reducer, realFS)) {
18841884
describe(name, () => {
18851885
fn(name, (fs, args, done, withError) => {
1886-
const span = {}
1886+
const span = tracer.startSpan('test')
1887+
span.finish()
18871888
return tracer.scope().activate(span, () => {
18881889
args.push((err) => {
18891890
assert.strictEqual(tracer.scope().active(), span)
@@ -1902,7 +1903,8 @@ describe('Plugin', () => {
19021903
if (realFS.promises && name in realFS.promises) {
19031904
describe('promises.' + name, () => {
19041905
fn('promises.' + name, (fs, args, done, withError) => {
1905-
const span = {}
1906+
const span = tracer.startSpan('test')
1907+
span.finish()
19061908
return tracer.scope().activate(span, () => {
19071909
return fs.promises[name].apply(fs.promises, args)
19081910
.then(() => {

packages/datadog-plugin-google-cloud-pubsub/test/index.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ describe('Plugin', () => {
228228
sub.on('message', msg => {
229229
const activeSpan = tracer.scope().active()
230230
if (activeSpan) {
231-
const receiverSpanContext = activeSpan._spanContext
231+
const receiverSpanContext = activeSpan.context()
232232
assert.ok(typeof receiverSpanContext._parentId === 'object' && receiverSpanContext._parentId !== null)
233233
}
234234
msg.ack()

packages/datadog-plugin-grpc/test/client.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ describe('Plugin', () => {
512512
})
513513

514514
it('should propagate the parent scope to the callback', done => {
515-
const span = {}
515+
const span = tracer.startSpan('test')
516516

517517
buildClient({
518518
getUnary: (call, callback) => callback(),
@@ -527,7 +527,7 @@ describe('Plugin', () => {
527527
})
528528

529529
it('should propagate the parent scope to event listeners', done => {
530-
const span = {}
530+
const span = tracer.startSpan('test')
531531

532532
buildClient({
533533
getServerStream: stream => {

packages/datadog-plugin-http2/test/client.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ describe('Plugin', () => {
511511
.connect(`${protocol}://localhost:${port}`)
512512
.on('error', done)
513513

514-
const span = {}
514+
const span = tracer.startSpan('test')
515515

516516
tracer.scope().activate(span, () => {
517517
const req = client.request({ ':path': '/user' })

packages/datadog-plugin-ioredis/test/index.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ describe('Plugin', () => {
5656
})
5757

5858
it('should run the callback in the parent context', () => {
59-
const span = {}
59+
const span = tracer.startSpan('test')
6060

6161
return tracer.scope().activate(span, async () => {
6262
await redis.get('foo')

packages/datadog-plugin-iovalkey/test/index.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ describe('Plugin', () => {
5757
})
5858

5959
it('should run the callback in the parent context', () => {
60-
const span = {}
60+
const span = tracer.startSpan('test')
6161

6262
return tracer.scope().activate(span, async () => {
6363
await valkey.get('foo')

0 commit comments

Comments
 (0)