Skip to content

Commit

Permalink
Try to simplify tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nhulston committed Nov 22, 2024
1 parent 0ab6403 commit 9caba79
Showing 1 changed file with 29 additions and 49 deletions.
78 changes: 29 additions & 49 deletions packages/datadog-plugin-aws-sdk/test/dynamodb.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,58 +133,39 @@ describe('Plugin', () => {

function testSpanPointers ({ expectedLength = 1, expectedHashes, operation }) {
return (done) => {
try {
let hasCompleted = false
operation((err) => {
if (err) {
console.log('[testSpanPointers] Error while completing operation:', err)
if (!hasCompleted) {
hasCompleted = true
return done(err)
}
}
operation((err) => {
if (err) {
return done(err)
}

agent.use(traces => {
if (hasCompleted) return
try {
const span = traces[0][0]
const links = JSON.parse(span.meta?.['_dd.span_links'] || '[]')
expect(links).to.have.lengthOf(expectedLength)

if (expectedHashes) {
if (Array.isArray(expectedHashes)) {
expectedHashes.forEach((hash, i) => {
expect(links[i].attributes['ptr.hash']).to.equal(hash)
})
} else {
expect(links[0].attributes).to.deep.equal({
'ptr.kind': DYNAMODB_PTR_KIND,
'ptr.dir': SPAN_POINTER_DIRECTION.DOWNSTREAM,
'ptr.hash': expectedHashes,
'link.kind': 'span-pointer'
})
}
}
hasCompleted = true
return done()
} catch (error) {
console.log('[testSpanPointers] Test error:', error)
if (!hasCompleted) {
hasCompleted = true
return done(error)
agent.use(traces => {
try {
const span = traces[0][0]
const links = JSON.parse(span.meta?.['_dd.span_links'] || '[]')
expect(links).to.have.lengthOf(expectedLength)

if (expectedHashes) {
if (Array.isArray(expectedHashes)) {
expectedHashes.forEach((hash, i) => {
expect(links[i].attributes['ptr.hash']).to.equal(hash)
})
} else {
expect(links[0].attributes).to.deep.equal({
'ptr.kind': DYNAMODB_PTR_KIND,
'ptr.dir': SPAN_POINTER_DIRECTION.DOWNSTREAM,
'ptr.hash': expectedHashes,
'link.kind': 'span-pointer'
})
}
}
}).catch(error => {
console.log('[testSpanPointers] Caught error during agent.use:', error)
if (!hasCompleted) {
hasCompleted = true
done(error)
}
})
return done()
} catch (error) {
return done(error)
}
}).catch(error => {
done(error)
})
} catch (error) {
console.log('[testSpanPointers] Caught error:', error)
}
})
}
}

Expand Down Expand Up @@ -412,7 +393,6 @@ describe('Plugin', () => {
}
}, async function (err) {
if (err) {
console.log('MYERR:', err)
return done(err)
}
await new Promise(resolve => setTimeout(resolve, 100))
Expand Down

0 comments on commit 9caba79

Please sign in to comment.