-
Notifications
You must be signed in to change notification settings - Fork 404
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: Replace distributed tracing tests with node:test
#2527
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,8 @@ | |
*/ | ||
|
||
'use strict' | ||
const tap = require('tap') | ||
const test = require('node:test') | ||
const assert = require('node:assert') | ||
const Exception = require('../../../lib/errors').Exception | ||
const helper = require('../../lib/agent_helper') | ||
const recorder = require('../../../lib/metrics/recorders/distributed-trace') | ||
|
@@ -14,21 +15,21 @@ const recordSupportability = require('../../../lib/agent').prototype.recordSuppo | |
|
||
const testCases = require('../../lib/cross_agent_tests/distributed_tracing/distributed_tracing.json') | ||
|
||
tap.test('distributed tracing', function (t) { | ||
t.autoend() | ||
t.beforeEach((t) => { | ||
test('distributed tracing', async function (t) { | ||
t.beforeEach((ctx) => { | ||
ctx.nr = {} | ||
const agent = helper.loadMockedAgent({ distributed_tracing: { enabled: true } }) | ||
agent.recordSupportability = recordSupportability | ||
t.context.agent = agent | ||
ctx.nr.agent = agent | ||
}) | ||
|
||
t.afterEach((t) => { | ||
helper.unloadAgent(t.context.agent) | ||
t.afterEach((ctx) => { | ||
helper.unloadAgent(ctx.nr.agent) | ||
}) | ||
|
||
testCases.forEach((testCase) => { | ||
t.test(testCase.test_name, (t) => { | ||
const { agent } = t.context | ||
for (const testCase of testCases) { | ||
await t.test(testCase.test_name, (ctx, end) => { | ||
const { agent } = ctx.nr | ||
agent.config.trusted_account_key = testCase.trusted_account_key | ||
agent.config.account_id = testCase.account_id | ||
agent.config.primary_application_id = 'test app' | ||
|
@@ -71,21 +72,21 @@ tap.test('distributed tracing', function (t) { | |
Object.keys(exact).forEach((key) => { | ||
const match = keyRegex.exec(key) | ||
if (match) { | ||
t.equal(created.d[match[1]], exact[key]) | ||
assert.equal(created.d[match[1]], exact[key]) | ||
} else { | ||
t.same(created.v, exact.v) | ||
assert.deepStrictEqual(created.v, exact.v) | ||
} | ||
}) | ||
|
||
if (outbound.expected) { | ||
outbound.expected.forEach((key) => { | ||
t.ok(created.d.hasOwnProperty(keyRegex.exec(key)[1])) | ||
assert.ok(created.d.hasOwnProperty(keyRegex.exec(key)[1])) | ||
}) | ||
} | ||
|
||
if (outbound.unexpected) { | ||
outbound.unexpected.forEach((key) => { | ||
t.notOk(created.d.hasOwnProperty(keyRegex.exec(key)[1])) | ||
assert.ok(!created.d.hasOwnProperty(keyRegex.exec(key)[1])) | ||
}) | ||
} | ||
}) | ||
|
@@ -95,7 +96,7 @@ tap.test('distributed tracing', function (t) { | |
tx.end() | ||
const intrinsics = testCase.intrinsics | ||
intrinsics.target_events.forEach((type) => { | ||
t.ok(['Transaction', 'TransactionError', 'Span'].includes(type)) | ||
assert.ok(['Transaction', 'TransactionError', 'Span'].includes(type)) | ||
|
||
const common = intrinsics.common | ||
const specific = intrinsics[type] || {} | ||
|
@@ -116,7 +117,7 @@ tap.test('distributed tracing', function (t) { | |
const arbitrary = (specific.expected || []).concat(common.expected || []) | ||
const unexpected = (specific.unexpected || []).concat(common.unexpected || []) | ||
|
||
t.ok(toCheck.length > 0) | ||
assert.ok(toCheck.length > 0) | ||
toCheck.forEach((event) => { | ||
// Span events are not payload-formatted straight out of the | ||
// aggregator. | ||
|
@@ -126,13 +127,13 @@ tap.test('distributed tracing', function (t) { | |
|
||
const attributes = event[0] | ||
arbitrary.forEach((key) => { | ||
t.ok(attributes[`${key}`], `${type} should have ${key}`) | ||
assert.ok(attributes[`${key}`], `${type} should have ${key}`) | ||
}) | ||
unexpected.forEach((key) => { | ||
t.notOk(attributes[`${key}`], `${type} should not have ${key}`) | ||
assert.ok(!attributes[`${key}`], `${type} should not have ${key}`) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see it in this list (https://nodejs.org/api/assert.html) and whenever I use it it says that assert.notOk is not a function. Maybe I have a different version? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry. I must be thinking of |
||
}) | ||
Object.keys(exact).forEach((key) => { | ||
t.equal(attributes[key], exact[key], `${type} should have equal ${key}`) | ||
assert.equal(attributes[key], exact[key], `${type} should have equal ${key}`) | ||
}) | ||
}) | ||
}) | ||
|
@@ -142,10 +143,10 @@ tap.test('distributed tracing', function (t) { | |
const metricName = metricPair[0] | ||
const callCount = metrics.getOrCreateMetric(metricName).callCount | ||
const metricCount = metricPair[1] | ||
t.equal(callCount, metricCount, `${metricName} should have ${metricCount} samples`) | ||
assert.equal(callCount, metricCount, `${metricName} should have ${metricCount} samples`) | ||
}) | ||
t.end() | ||
end() | ||
}) | ||
}) | ||
}) | ||
} | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically this is not necessary because each test will have a new scope. Thus, the
ctx.nr.eventAggregator
from test A will not be the same one in test B. But having theafterEach
clear it is not harming anything. So this comment is informational, not blocking.