Skip to content

Commit e8030f9

Browse files
committed
address feedback
1 parent b5640bd commit e8030f9

File tree

2 files changed

+24
-18
lines changed

2 files changed

+24
-18
lines changed

test/versioned/kafkajs/kafka.tap.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ tap.test('send passes along DT headers', (t) => {
121121
agent.config.primary_application_id = 'app_1'
122122
agent.config.trusted_account_key = 42
123123
let produceTx = null
124-
let consumeTx = null
124+
const consumeTxs = []
125125
let txCount = 0
126126

127127
agent.on('transactionFinished', (tx) => {
@@ -130,11 +130,11 @@ tap.test('send passes along DT headers', (t) => {
130130
if (tx.name === expectedName) {
131131
produceTx = tx
132132
} else {
133-
consumeTx = tx
133+
consumeTxs.push(tx)
134134
}
135135

136-
if (txCount === 2) {
137-
utils.verifyDistributedTrace({ t, consumeTx, produceTx })
136+
if (txCount === 3) {
137+
utils.verifyDistributedTrace({ t, consumeTxs, produceTx })
138138
t.end()
139139
}
140140
})
@@ -144,10 +144,13 @@ tap.test('send passes along DT headers', (t) => {
144144
await consumer.subscribe({ topic, fromBeginning: true })
145145

146146
const promise = new Promise((resolve) => {
147+
let msgCount = 0
147148
consumer.run({
148-
eachMessage: async ({ message: actualMessage }) => {
149-
t.equal(actualMessage.value.toString(), 'one')
150-
resolve()
149+
eachMessage: async () => {
150+
++msgCount
151+
if (msgCount === 2) {
152+
resolve()
153+
}
151154
}
152155
})
153156
})
@@ -156,7 +159,10 @@ tap.test('send passes along DT headers', (t) => {
156159
await producer.send({
157160
acks: 1,
158161
topic,
159-
messages: [{ key: 'key', value: 'one' }]
162+
messages: [
163+
{ key: 'key', value: 'one' },
164+
{ key: 'key2', value: 'two' }
165+
]
160166
})
161167

162168
await promise

test/versioned/kafkajs/utils.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,18 +104,18 @@ utils.verifyConsumeTransaction = ({ t, tx, topic, clientId }) => {
104104
* Asserts the properties on both the produce and consume transactions
105105
* @param {object} params function params
106106
* @param {object} params.t test instance
107-
* @param {object} params.consumeTx consumer transaction
107+
* @param {object} params.consumeTxs consumer transactions
108108
* @param {object} params.produceTx produce transaction
109109
*/
110-
utils.verifyDistributedTrace = ({ t, consumeTx, produceTx }) => {
110+
utils.verifyDistributedTrace = ({ t, consumeTxs, produceTx }) => {
111111
t.ok(produceTx.isDistributedTrace, 'should mark producer as distributed')
112-
t.ok(consumeTx.isDistributedTrace, 'should mark consumer as distributed')
113-
114-
t.equal(consumeTx.incomingCatId, null, 'should not set old CAT properties')
115-
116-
t.equal(produceTx.id, consumeTx.parentId, 'should have proper parent id')
117-
t.equal(produceTx.traceId, consumeTx.traceId, 'should have proper trace id')
118112
const produceSegment = produceTx.trace.root.children[3]
119-
t.equal(produceSegment.id, consumeTx.parentSpanId, 'should have proper parentSpanId')
120-
t.equal(consumeTx.parentTransportType, 'Kafka', 'should have correct transport type')
113+
consumeTxs.forEach((consumeTx) => {
114+
t.ok(consumeTx.isDistributedTrace, 'should mark consumer as distributed')
115+
t.equal(consumeTx.incomingCatId, null, 'should not set old CAT properties')
116+
t.equal(produceTx.id, consumeTx.parentId, 'should have proper parent id')
117+
t.equal(produceTx.traceId, consumeTx.traceId, 'should have proper trace id')
118+
t.equal(produceSegment.id, consumeTx.parentSpanId, 'should have proper parentSpanId')
119+
t.equal(consumeTx.parentTransportType, 'Kafka', 'should have correct transport type')
120+
})
121121
}

0 commit comments

Comments
 (0)