Skip to content

Commit d41756c

Browse files
committed
test fixes
1 parent 3dc878c commit d41756c

File tree

4 files changed

+27
-7
lines changed

4 files changed

+27
-7
lines changed

test/integration/distributed-tracing/trace-context-cross-agent.test.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,11 @@ function forceAdaptiveSamplers(agent, forceAdaptiveSampled) {
504504
if (forceAdaptiveSampled === undefined || forceAdaptiveSampled === null) return
505505
// "Whether to force a transaction to be sampled or not when the adaptive sampler is used"
506506
// implies this affects all samplers that are adaptive samplers
507-
const samplers = [agent.transactionSampler, agent.remoteParentSampledSampler, agent.remoteParentNotSampledSampler]
507+
const samplers = [
508+
agent.sampler.root,
509+
agent.sampler.remoteParentSampled,
510+
agent.sampler.remoteParentNotSampled
511+
]
508512
for (const sampler of samplers) {
509513
if (sampler?.toString() === 'AdaptiveSampler') {
510514
// monkey patch this transaction object

test/unit/samplers/adaptive-sampler.test.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,5 +149,3 @@ test('in standard mode', async (t) => {
149149
})
150150
})
151151
})
152-
153-
// TODO: applySamplingDecision

test/unit/samplers/determine-sampler.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ test('if trace_id_ratio_based is defined but ratio is not, use adaptive sampler'
191191
}
192192
})
193193
t.nr.agent = helper.loadMockedAgent(config)
194-
const sampler = t.nr.agent.transactionSampler
194+
const sampler = t.nr.agent.sampler.root
195195
assert.ok(sampler instanceof AdaptiveSampler)
196196
})
197197

@@ -208,6 +208,6 @@ test('should use traceidratiobasedsampler if trace_id_ratio_based and ratio is d
208208
}
209209
})
210210
t.nr.agent = helper.loadMockedAgent(config)
211-
const sampler = t.nr.agent.transactionSampler
211+
const sampler = t.nr.agent.sampler.root
212212
assert.ok(sampler instanceof TraceIdRatioBasedSampler)
213213
})

test/unit/samplers/ratio-based-sampler.test.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
const test = require('node:test')
99
const assert = require('node:assert')
10-
const helper = require('../../lib/agent_helper')
10+
const helper = require('#testlib/agent_helper.js')
1111
const hashes = require('#agentlib/util/hashes.js')
1212
const TraceIdRatioBasedSampler = require('#agentlib/samplers/ratio-based-sampler.js')
1313

@@ -83,7 +83,25 @@ test('should sample approximately correct percentage of traces', (t) => {
8383
assert.ok(actualRatio > ratio - 0.01 && actualRatio < ratio + 0.01)
8484
})
8585

86-
// TODO: applySamplingDecision
86+
test('should set `sampled` and `priority` correctly on sampled transaction', (t, end) => {
87+
t.nr.agent.sampler.root = new TraceIdRatioBasedSampler({ agent: t.nr.agent, ratio: 1 })
88+
helper.runInTransaction(t.nr.agent, (txn) => {
89+
txn.end()
90+
assert.strictEqual(txn.sampled, true)
91+
assert.ok(txn.priority > 1)
92+
end()
93+
})
94+
})
95+
96+
test('should set `sampled` and `priority` correctly on not sampled transaction', (t, end) => {
97+
t.nr.agent.sampler.root = new TraceIdRatioBasedSampler({ agent: t.nr.agent, ratio: 0 })
98+
helper.runInTransaction(t.nr.agent, (txn) => {
99+
txn.end()
100+
assert.strictEqual(txn.sampled, false)
101+
assert.ok(txn.priority < 1)
102+
end()
103+
})
104+
})
87105

88106
function generateRandomTraceId() {
89107
return hashes.makeId(32)

0 commit comments

Comments
 (0)