diff --git a/test/unit/db/query-parsers/sql.test.js b/test/unit/db/query-parsers/sql.test.js index bff3b8fb3e..d9168b5549 100644 --- a/test/unit/db/query-parsers/sql.test.js +++ b/test/unit/db/query-parsers/sql.test.js @@ -5,7 +5,8 @@ 'use strict' -const { test } = require('tap') +const test = require('node:test') +const assert = require('node:assert') const parseSql = require('../../../../lib/db/query-parsers/sql') const CATs = require('../../../lib/cross_agent_tests/sql_parsing') @@ -19,38 +20,33 @@ function clean(sql) { return '"' + sql.replace(/\n/gm, '\\n').replace(/\r/gm, '\\r').replace(/\t/gm, '\\t') + '"' } -test('database query parser', function (t) { - t.autoend() - t.test('should accept query as a string', function (t) { +test('database query parser', async (t) => { + await t.test('should accept query as a string', function () { const ps = parseSql('select * from someTable') - t.equal(ps.query, 'select * from someTable') - t.end() + assert.equal(ps.query, 'select * from someTable') }) - t.test('should accept query as a sql property of an object', function (t) { + await t.test('should accept query as a sql property of an object', function () { const ps = parseSql({ sql: 'select * from someTable' }) - t.equal(ps.query, 'select * from someTable') - t.end() + assert.equal(ps.query, 'select * from someTable') }) - t.test('SELECT SQL', function (t) { - t.autoend() - t.test('should parse a simple query', function (t) { + await t.test('SELECT SQL', async (t) => { + await t.test('should parse a simple query', function () { const ps = parseSql('Select * from dude') - t.ok(ps) + assert.ok(ps) - t.ok(ps.operation) - t.equal(ps.operation, 'select') + assert.ok(ps.operation) + assert.equal(ps.operation, 'select') - t.ok(ps.collection) - t.equal(ps.collection, 'dude') - t.equal(ps.query, 'Select * from dude') - t.end() + assert.ok(ps.collection) + assert.equal(ps.collection, 'dude') + assert.equal(ps.query, 'Select * from dude') }) - t.test('should parse more interesting queries too', function (t) { + await t.test('should parse more interesting queries too', function () { const sql = [ 'SELECT P.postcode, ', 'P.suburb, ', @@ -66,121 +62,102 @@ test('database query parser', function (t) { 'LIMIT 1' ].join('\n') const ps = parseSql(sql) - t.ok(ps) - t.equal(ps.operation, 'select') - t.equal(ps.collection, 'postcodes') - t.equal(ps.query, sql) - t.end() + assert.ok(ps) + assert.equal(ps.operation, 'select') + assert.equal(ps.collection, 'postcodes') + assert.equal(ps.query, sql) }) }) - t.test('DELETE SQL', function (t) { - t.autoend() - t.test('should parse a simple command', function (t) { + await t.test('DELETE SQL', async (t) => { + await t.test('should parse a simple command', function () { const ps = parseSql('DELETE\nfrom dude') - t.ok(ps) + assert.ok(ps) - t.ok(ps.operation) - t.equal(ps.operation, 'delete') + assert.ok(ps.operation) + assert.equal(ps.operation, 'delete') - t.ok(ps.collection) - t.equal(ps.collection, 'dude') - t.equal(ps.query, 'DELETE\nfrom dude') - t.end() + assert.ok(ps.collection) + assert.equal(ps.collection, 'dude') + assert.equal(ps.query, 'DELETE\nfrom dude') }) - t.test('should parse a command with conditions', function (t) { + await t.test('should parse a command with conditions', function () { const ps = parseSql("DELETE\nfrom dude where name = 'man'") - t.ok(ps) + assert.ok(ps) - t.ok(ps.operation) - t.equal(ps.operation, 'delete') + assert.ok(ps.operation) + assert.equal(ps.operation, 'delete') - t.ok(ps.collection) - t.equal(ps.collection, 'dude') - t.equal(ps.query, "DELETE\nfrom dude where name = 'man'") - t.end() + assert.ok(ps.collection) + assert.equal(ps.collection, 'dude') + assert.equal(ps.query, "DELETE\nfrom dude where name = 'man'") }) }) - t.test('UPDATE SQL', function (t) { - t.autoend() - t.test('should parse a command with gratuitous white space and conditions', function (t) { + await t.test('UPDATE SQL', function (t) { + t.test('should parse a command with gratuitous white space and conditions', function () { const ps = parseSql(' update test set value = 1 where id = 12') - t.ok(ps) + assert.ok(ps) - t.ok(ps.operation) - t.equal(ps.operation, 'update') + assert.ok(ps.operation) + assert.equal(ps.operation, 'update') - t.ok(ps.collection) - t.equal(ps.collection, 'test') - t.equal(ps.query, 'update test set value = 1 where id = 12') - t.end() + assert.ok(ps.collection) + assert.equal(ps.collection, 'test') + assert.equal(ps.query, 'update test set value = 1 where id = 12') }) }) - t.test('INSERT SQL', function (t) { - t.autoend() - t.test('should parse a command with a subquery', function (t) { + await t.test('INSERT SQL', function (t) { + t.test('should parse a command with a subquery', function () { const ps = parseSql(' insert into\ntest\nselect * from dude') - t.ok(ps) + assert.ok(ps) - t.ok(ps.operation) - t.equal(ps.operation, 'insert') + assert.ok(ps.operation) + assert.equal(ps.operation, 'insert') - t.ok(ps.collection) - t.equal(ps.collection, 'test') - t.equal(ps.query, 'insert into\ntest\nselect * from dude') - t.end() + assert.ok(ps.collection) + assert.equal(ps.collection, 'test') + assert.equal(ps.query, 'insert into\ntest\nselect * from dude') }) }) - t.test('invalid SQL', function (t) { - t.autoend() - t.test("should return 'other' when handed garbage", function (t) { + await t.test('invalid SQL', async (t) => { + await t.test("should return 'other' when handed garbage", function () { const ps = parseSql(' bulge into\ndudes\nselect * from dude') - t.ok(ps) - t.equal(ps.operation, 'other') - t.notOk(ps.collection) - t.equal(ps.query, 'bulge into\ndudes\nselect * from dude') - t.end() + assert.ok(ps) + assert.equal(ps.operation, 'other') + assert.ok(!ps.collection) + assert.equal(ps.query, 'bulge into\ndudes\nselect * from dude') }) - t.test("should return 'other' when handed an object", function (t) { + await t.test("should return 'other' when handed an object", function () { const ps = parseSql({ key: 'value' }) - t.ok(ps) - t.equal(ps.operation, 'other') - t.notOk(ps.collection) - t.equal(ps.query, '') - t.end() + assert.ok(ps) + assert.equal(ps.operation, 'other') + assert.ok(!ps.collection) + assert.equal(ps.query, '') }) }) - t.test('CAT', function (t) { - t.autoend() - CATs.forEach(function (cat) { - t.test(clean(cat.input), function (t) { - t.autoend() + await t.test('CAT', async function (t) { + for (const cat of CATs) { + await t.test(clean(cat.input), async (t) => { const ps = parseSql(cat.input) - t.test('should parse the operation as ' + cat.operation, function (t) { - t.equal(ps.operation, cat.operation) - t.end() - }) + assert.equal(ps.operation, cat.operation, `should parse the operation as ${cat.operation}`) if (cat.table === '(subquery)') { - t.test('should parse subquery collections as ' + cat.table) + t.todo('should parse subquery collections as ' + cat.table) } else if (/\w+\.\w+/.test(ps.collection)) { - t.test('should strip database names from collection names as ' + cat.table) + t.todo('should strip database names from collection names as ' + cat.table) } else { - t.test('should parse the collection as ' + cat.table, function (t) { - t.equal(ps.collection, cat.table) - t.end() - }) + assert.equal(ps.collection, cat.table, `should parse the collection as ${cat.table}`) } }) - }) + } }) }) diff --git a/test/unit/db/query-sample.test.js b/test/unit/db/query-sample.test.js index 6db25b9ce0..93b85793b1 100644 --- a/test/unit/db/query-sample.test.js +++ b/test/unit/db/query-sample.test.js @@ -5,15 +5,14 @@ 'use strict' -const tap = require('tap') +const test = require('node:test') +const assert = require('node:assert') const sinon = require('sinon') const QuerySample = require('../../../lib/db/query-sample') const codec = require('../../../lib/util/codec') -tap.test('Query Sample', (t) => { - t.autoend() - - t.test('should set trace to query with longest duration', (t) => { +test('Query Sample', async (t) => { + await t.test('should set trace to query with longest duration', () => { const trace = { duration: 3 } @@ -25,12 +24,10 @@ tap.test('Query Sample', (t) => { const querySample = new QuerySample(tracer, trace) querySample.aggregate(slowQuery) - t.equal(querySample.trace.duration, 30) - - t.end() + assert.equal(querySample.trace.duration, 30) }) - t.test('should not set trace to query with shorter duration', (t) => { + await t.test('should not set trace to query with shorter duration', () => { const trace = { duration: 30 } @@ -42,12 +39,10 @@ tap.test('Query Sample', (t) => { const querySample = new QuerySample(tracer, trace) querySample.aggregate(slowQuery) - t.equal(querySample.trace.duration, 30) - - t.end() + assert.equal(querySample.trace.duration, 30) }) - t.test('should merge sample with longer duration', (t) => { + await t.test('should merge sample with longer duration', () => { const slowSample = { trace: { duration: 30 @@ -61,12 +56,10 @@ tap.test('Query Sample', (t) => { const querySample = new QuerySample(tracer, trace) querySample.merge(slowSample) - t.equal(querySample.trace.duration, 30) - - t.end() + assert.equal(querySample.trace.duration, 30) }) - t.test('should not merge sample with shorter duration', (t) => { + await t.test('should not merge sample with shorter duration', () => { const slowSample = { trace: { duration: 3 @@ -80,12 +73,10 @@ tap.test('Query Sample', (t) => { const querySample = new QuerySample(tracer, trace) querySample.merge(slowSample) - t.equal(querySample.trace.duration, 30) - - t.end() + assert.equal(querySample.trace.duration, 30) }) - t.test('should encode json when simple_compression is disabled', (t) => { + await t.test('should encode json when simple_compression is disabled', () => { const fakeTracer = { config: { simple_compression: false @@ -108,15 +99,13 @@ tap.test('Query Sample', (t) => { querySample.prepareJSON(() => {}) - t.ok(codecCalled) + assert.ok(codecCalled) QuerySample.prototype.getParams.restore() codec.encode.restore() - - t.end() }) - t.test('should call _getJSON when simple_compression is enabled', (t) => { + await t.test('should call _getJSON when simple_compression is enabled', () => { const fakeTracer = { config: { simple_compression: true, @@ -151,15 +140,13 @@ tap.test('Query Sample', (t) => { clock.runAll() - t.ok(getFullNameCalled) + assert.ok(getFullNameCalled) clock.restore() QuerySample.prototype.getParams.restore() - - t.end() }) - t.test('should return segment attributes as params if present', (t) => { + await t.test('should return segment attributes as params if present', () => { const expectedParams = { host: 'host', port_path_or_id: 1, @@ -187,14 +174,12 @@ tap.test('Query Sample', (t) => { const result = querySample.getParams() - t.equal(result.host, expectedParams.host) - t.equal(result.port_path_or_id, expectedParams.port_path_or_id) - t.equal(result.database_name, expectedParams.database_name) - - t.end() + assert.equal(result.host, expectedParams.host) + assert.equal(result.port_path_or_id, expectedParams.port_path_or_id) + assert.equal(result.database_name, expectedParams.database_name) }) - t.test('should add DT intrinsics when DT enabled', (t) => { + await t.test('should add DT intrinsics when DT enabled', () => { let addDtIntrinsicsCalled = false const fakeTracer = { config: { @@ -219,12 +204,10 @@ tap.test('Query Sample', (t) => { querySample.getParams() - t.equal(addDtIntrinsicsCalled, true) - - t.end() + assert.equal(addDtIntrinsicsCalled, true) }) - t.test('should not add DT intrinsics when DT disabled', (t) => { + await t.test('should not add DT intrinsics when DT disabled', () => { let addDtIntrinsicsCalled = false const fakeTracer = { config: { @@ -249,8 +232,6 @@ tap.test('Query Sample', (t) => { querySample.getParams() - t.equal(addDtIntrinsicsCalled, false) - - t.end() + assert.equal(addDtIntrinsicsCalled, false) }) }) diff --git a/test/unit/db/query-trace-aggregator.test.js b/test/unit/db/query-trace-aggregator.test.js index f2dece0450..e23ef76423 100644 --- a/test/unit/db/query-trace-aggregator.test.js +++ b/test/unit/db/query-trace-aggregator.test.js @@ -5,8 +5,8 @@ 'use strict' -const tap = require('tap') - +const test = require('node:test') +const assert = require('node:assert') const Config = require('../../../lib/config') const QueryTraceAggregator = require('../../../lib/db/query-trace-aggregator') const codec = require('../../../lib/util/codec') @@ -15,37 +15,10 @@ const sinon = require('sinon') const FAKE_STACK = 'Error\nfake stack' -tap.test('Query Trace Aggregator', (t) => { - t.autoend() - - t.test('when no queries in payload, _toPayload should exec callback with null data', (t) => { - const opts = { - config: new Config({ - slow_sql: { enabled: false }, - transaction_tracer: { record_sql: 'off', explain_threshold: 500 } - }), - method: 'sql_trace_data' - } - const harvester = { add: sinon.stub() } - const queries = new QueryTraceAggregator(opts, {}, harvester) - - let cbCalledWithNull = false - - const cb = (err, data) => { - if (data === null) { - cbCalledWithNull = true - } - } - - queries._toPayload(cb) - - t.ok(cbCalledWithNull) - t.end() - }) - - t.test('when slow_sql.enabled is false', (t) => { - t.autoend() - t.test('should not record anything when transaction_tracer.record_sql === "off"', (t) => { +test('Query Trace Aggregator', async (t) => { + await t.test( + 'when no queries in payload, _toPayload should exec callback with null data', + (t, end) => { const opts = { config: new Config({ slow_sql: { enabled: false }, @@ -56,14 +29,44 @@ tap.test('Query Trace Aggregator', (t) => { const harvester = { add: sinon.stub() } const queries = new QueryTraceAggregator(opts, {}, harvester) - const segment = addQuery(queries, 1000) - t.hasProp(queries.samples, 'size') - t.equal(queries.samples.size, 0) - t.same(segment.getAttributes(), {}, 'should not record sql in trace') - t.end() - }) + let cbCalledWithNull = false + + const cb = (err, data) => { + if (data === null) { + cbCalledWithNull = true + } + } + + queries._toPayload(cb) + + assert.ok(cbCalledWithNull) + end() + } + ) + + await t.test('when slow_sql.enabled is false', async (t) => { + await t.test( + 'should not record anything when transaction_tracer.record_sql === "off"', + (t, end) => { + const opts = { + config: new Config({ + slow_sql: { enabled: false }, + transaction_tracer: { record_sql: 'off', explain_threshold: 500 } + }), + method: 'sql_trace_data' + } + const harvester = { add: sinon.stub() } + const queries = new QueryTraceAggregator(opts, {}, harvester) + + const segment = addQuery(queries, 1000) + assert.ok('size' in queries.samples) + assert.equal(queries.samples.size, 0) + assert.deepStrictEqual(segment.getAttributes(), {}, 'should not record sql in trace') + end() + } + ) - t.test('should treat unknown value in transaction_tracer.record_sql as off', (t) => { + await t.test('should treat unknown value in transaction_tracer.record_sql as off', (t, end) => { const opts = { config: new Config({ slow_sql: { enabled: false }, @@ -75,13 +78,13 @@ tap.test('Query Trace Aggregator', (t) => { const queries = new QueryTraceAggregator(opts, {}, harvester) const segment = addQuery(queries, 1000) - t.hasProp(queries.samples, 'size') - t.equal(queries.samples.size, 0) - t.same(segment.getAttributes(), {}, 'should not record sql in trace') - t.end() + assert.ok('size' in queries.samples) + assert.equal(queries.samples.size, 0) + assert.deepStrictEqual(segment.getAttributes(), {}, 'should not record sql in trace') + end() }) - t.test('should record only in trace when record_sql === "obfuscated"', (t) => { + await t.test('should record only in trace when record_sql === "obfuscated"', (t, end) => { const opts = { config: new Config({ slow_sql: { enabled: false }, @@ -93,9 +96,9 @@ tap.test('Query Trace Aggregator', (t) => { const queries = new QueryTraceAggregator(opts, {}, harvester) const segment = addQuery(queries, 1000) - t.hasProp(queries.samples, 'size') - t.equal(queries.samples.size, 0) - t.same( + assert.ok('size' in queries.samples) + assert.equal(queries.samples.size, 0) + assert.deepStrictEqual( segment.getAttributes(), { backtrace: 'fake stack', @@ -103,10 +106,10 @@ tap.test('Query Trace Aggregator', (t) => { }, 'should record sql in trace' ) - t.end() + end() }) - t.test('should record only in trace when record_sql === "raw"', (t) => { + await t.test('should record only in trace when record_sql === "raw"', (t, end) => { const opts = { config: new Config({ slow_sql: { enabled: false }, @@ -118,9 +121,9 @@ tap.test('Query Trace Aggregator', (t) => { const queries = new QueryTraceAggregator(opts, {}, harvester) const segment = addQuery(queries, 1000) - t.hasProp(queries.samples, 'size') - t.equal(queries.samples.size, 0) - t.same( + assert.ok('size' in queries.samples) + assert.equal(queries.samples.size, 0) + assert.deepStrictEqual( segment.getAttributes(), { backtrace: 'fake stack', @@ -128,10 +131,10 @@ tap.test('Query Trace Aggregator', (t) => { }, 'should record sql in trace' ) - t.end() + end() }) - t.test('should not record if below threshold', (t) => { + await t.test('should not record if below threshold', (t, end) => { const opts = { config: new Config({ slow_sql: { enabled: false }, @@ -143,41 +146,42 @@ tap.test('Query Trace Aggregator', (t) => { const queries = new QueryTraceAggregator(opts, {}, harvester) const segment = addQuery(queries, 100) - t.hasProp(queries.samples, 'size') - t.equal(queries.samples.size, 0) - t.same( + assert.ok('size' in queries.samples) + assert.equal(queries.samples.size, 0) + assert.deepStrictEqual( segment.getAttributes(), { sql: 'select * from foo where a=2' }, 'should record sql in trace' ) - t.end() + end() }) }) - t.test('when slow_sql.enabled is true', (t) => { - t.autoend() + await t.test('when slow_sql.enabled is true', async (t) => { + await t.test( + 'should not record anything when transaction_tracer.record_sql === "off"', + (t, end) => { + const opts = { + config: new Config({ + slow_sql: { enabled: true }, + transaction_tracer: { record_sql: 'off', explain_threshold: 500 } + }), + method: 'sql_trace_data' + } + const harvester = { add: sinon.stub() } + const queries = new QueryTraceAggregator(opts, {}, harvester) - t.test('should not record anything when transaction_tracer.record_sql === "off"', (t) => { - const opts = { - config: new Config({ - slow_sql: { enabled: true }, - transaction_tracer: { record_sql: 'off', explain_threshold: 500 } - }), - method: 'sql_trace_data' + const segment = addQuery(queries, 1000) + assert.ok('size' in queries.samples) + assert.equal(queries.samples.size, 0) + assert.deepStrictEqual(segment.getAttributes(), {}, 'should not record sql in trace') + end() } - const harvester = { add: sinon.stub() } - const queries = new QueryTraceAggregator(opts, {}, harvester) - - const segment = addQuery(queries, 1000) - t.hasProp(queries.samples, 'size') - t.equal(queries.samples.size, 0) - t.same(segment.getAttributes(), {}, 'should not record sql in trace') - t.end() - }) + ) - t.test('should treat unknown value in transaction_tracer.record_sql as off', (t) => { + await t.test('should treat unknown value in transaction_tracer.record_sql as off', (t, end) => { const opts = { config: new Config({ slow_sql: { enabled: true }, @@ -189,13 +193,13 @@ tap.test('Query Trace Aggregator', (t) => { const queries = new QueryTraceAggregator(opts, {}, harvester) const segment = addQuery(queries, 1000) - t.hasProp(queries.samples, 'size') - t.equal(queries.samples.size, 0) - t.same(segment.getAttributes(), {}, 'should not record sql in trace') - t.end() + assert.ok('size' in queries.samples) + assert.equal(queries.samples.size, 0) + assert.deepStrictEqual(segment.getAttributes(), {}, 'should not record sql in trace') + end() }) - t.test('should record obfuscated trace when record_sql === "obfuscated"', (t) => { + await t.test('should record obfuscated trace when record_sql === "obfuscated"', (t, end) => { const opts = { config: new Config({ slow_sql: { enabled: true }, @@ -207,7 +211,7 @@ tap.test('Query Trace Aggregator', (t) => { const queries = new QueryTraceAggregator(opts, {}, harvester) const segment = addQuery(queries, 1000) - t.same( + assert.deepStrictEqual( segment.getAttributes(), { backtrace: 'fake stack', @@ -216,16 +220,16 @@ tap.test('Query Trace Aggregator', (t) => { 'should not record sql in trace' ) - t.hasProp(queries.samples, 'size') - t.equal(queries.samples.size, 1) - t.ok(queries.samples.has('select*fromfoowherea=?')) + assert.ok('size' in queries.samples) + assert.equal(queries.samples.size, 1) + assert.ok(queries.samples.has('select*fromfoowherea=?')) const sample = queries.samples.get('select*fromfoowherea=?') - verifySample(t, sample, 1, segment) - t.end() + verifySample(sample, 1, segment) + end() }) - t.test('should record raw when record_sql === "raw"', (t) => { + await t.test('should record raw when record_sql === "raw"', (t, end) => { const opts = { config: new Config({ slow_sql: { enabled: true }, @@ -237,7 +241,7 @@ tap.test('Query Trace Aggregator', (t) => { const queries = new QueryTraceAggregator(opts, {}, harvester) const segment = addQuery(queries, 1000) - t.same( + assert.deepStrictEqual( segment.getAttributes(), { backtrace: 'fake stack', @@ -246,16 +250,16 @@ tap.test('Query Trace Aggregator', (t) => { 'should not record sql in trace' ) - t.hasProp(queries.samples, 'size') - t.equal(queries.samples.size, 1) - t.ok(queries.samples.has('select*fromfoowherea=?')) + assert.ok('size' in queries.samples) + assert.equal(queries.samples.size, 1) + assert.ok(queries.samples.has('select*fromfoowherea=?')) const sample = queries.samples.get('select*fromfoowherea=?') - verifySample(t, sample, 1, segment) - t.end() + verifySample(sample, 1, segment) + end() }) - t.test('should not record if below threshold', (t) => { + await t.test('should not record if below threshold', (t, end) => { const opts = { config: new Config({ slow_sql: { enabled: true }, @@ -267,28 +271,22 @@ tap.test('Query Trace Aggregator', (t) => { const queries = new QueryTraceAggregator(opts, {}, harvester) const segment = addQuery(queries, 100) - t.hasProp(queries.samples, 'size') - t.equal(queries.samples.size, 0) - t.same( + assert.ok('size' in queries.samples) + assert.equal(queries.samples.size, 0) + assert.deepStrictEqual( segment.getAttributes(), { sql: 'select * from foo where a=2' }, 'should record sql in trace' ) - t.end() + end() }) }) - t.test('prepareJSON', (t) => { - t.autoend() - - t.test('webTransaction when record_sql is "raw"', (t) => { - t.autoend() - - let queries - - t.beforeEach(() => { + await t.test('prepareJSON', async (t) => { + await t.test('webTransaction when record_sql is "raw"', async (t) => { + t.beforeEach((ctx) => { const opts = { config: new Config({ slow_sql: { enabled: true }, @@ -297,43 +295,42 @@ tap.test('Query Trace Aggregator', (t) => { method: 'sql_trace_data' } const harvester = { add: sinon.stub() } - queries = new QueryTraceAggregator(opts, {}, harvester) + ctx.nr = {} + ctx.nr.queries = new QueryTraceAggregator(opts, {}, harvester) }) - t.test('and `simple_compression` is `false`', (t) => { - t.autoend() - - t.beforeEach(() => { - queries.config.simple_compression = false + await t.test('and `simple_compression` is `false`', async (t) => { + t.beforeEach((ctx) => { + ctx.nr.queries.config.simple_compression = false }) - t.test('should compress the query parameters', (t) => { + await t.test('should compress the query parameters', (t, end) => { + const { queries } = t.nr addQuery(queries, 600, '/abc') queries.prepareJSON(function preparedJSON(err, data) { const sample = data[0] codec.decode(sample[9], function decoded(error, params) { - t.equal(error, null, 'should not error') + assert.equal(error, null, 'should not error') const keys = Object.keys(params) - t.same(keys, ['backtrace']) - t.same(params.backtrace, 'fake stack', 'trace should match') - t.end() + assert.deepStrictEqual(keys, ['backtrace']) + assert.deepStrictEqual(params.backtrace, 'fake stack', 'trace should match') + end() }) }) }) }) - t.test('and `simple_compression` is `true`', (t) => { - t.autoend() - - t.beforeEach(() => { - queries.config.simple_compression = true + await t.test('and `simple_compression` is `true`', async (t) => { + t.beforeEach((ctx) => { + ctx.nr.queries.config.simple_compression = true }) - t.test('should not compress the query parameters', (t) => { + await t.test('should not compress the query parameters', (t, end) => { + const { queries } = t.nr addQuery(queries, 600, '/abc') queries.prepareJSON(function preparedJSON(err, data) { @@ -341,93 +338,97 @@ tap.test('Query Trace Aggregator', (t) => { const params = sample[9] const keys = Object.keys(params) - t.same(keys, ['backtrace']) - t.same(params.backtrace, 'fake stack', 'trace should match') - t.end() + assert.deepStrictEqual(keys, ['backtrace']) + assert.deepStrictEqual(params.backtrace, 'fake stack', 'trace should match') + end() }) }) }) - t.test('should record work when empty', (t) => { + await t.test('should record work when empty', (t, end) => { + const { queries } = t.nr queries.prepareJSON(function preparedJSON(err, data) { - t.equal(err, null, 'should not error') - t.same(data, [], 'should return empty array') - t.end() + assert.equal(err, null, 'should not error') + assert.deepStrictEqual(data, [], 'should return empty array') + end() }) }) - t.test('should record work with a single query', (t) => { + await t.test('should record work with a single query', (t, end) => { + const { queries } = t.nr addQuery(queries, 600, '/abc') queries.prepareJSON(function preparedJSON(err, data) { - t.equal(err, null, 'should not error') - t.equal(data.length, 1, 'should be 1 sample query') + assert.equal(err, null, 'should not error') + assert.equal(data.length, 1, 'should be 1 sample query') const sample = data[0] - t.equal(sample[0], 'FakeTransaction', 'should match transaction name') - t.equal(sample[1], '/abc', 'should match transaction url') - t.equal(sample[2], 374780417029088500, 'should match query id') - t.equal(sample[3], 'select * from foo where a=2', 'should match raw query') - t.equal(sample[4], 'FakeSegment', 'should match segment name') - t.equal(sample[5], 1, 'should have 1 call') - t.equal(sample[6], 600, 'should match total') - t.equal(sample[7], 600, 'should match min') - t.equal(sample[8], 600, 'should match max') + assert.equal(sample[0], 'FakeTransaction', 'should match transaction name') + assert.equal(sample[1], '/abc', 'should match transaction url') + assert.equal(sample[2], 374780417029088500, 'should match query id') + assert.equal(sample[3], 'select * from foo where a=2', 'should match raw query') + assert.equal(sample[4], 'FakeSegment', 'should match segment name') + assert.equal(sample[5], 1, 'should have 1 call') + assert.equal(sample[6], 600, 'should match total') + assert.equal(sample[7], 600, 'should match min') + assert.equal(sample[8], 600, 'should match max') codec.decode(sample[9], function decoded(error, result) { - t.equal(error, null, 'should not error') + assert.equal(error, null, 'should not error') const keys = Object.keys(result) - t.same(keys, ['backtrace']) - t.same(result.backtrace, 'fake stack', 'trace should match') - t.end() + assert.deepStrictEqual(keys, ['backtrace']) + assert.deepStrictEqual(result.backtrace, 'fake stack', 'trace should match') + end() }) }) }) - t.test('should record work with a multiple similar queries', (t) => { + await t.test('should record work with a multiple similar queries', (t, end) => { + const { queries } = t.nr addQuery(queries, 600, '/abc') addQuery(queries, 550, '/abc') queries.prepareJSON(function preparedJSON(err, data) { - t.equal(err, null, 'should not error') - t.equal(data.length, 1, 'should be 1 sample query') + assert.equal(err, null, 'should not error') + assert.equal(data.length, 1, 'should be 1 sample query') data.sort(function (lhs, rhs) { return rhs[2] - lhs[2] }) const sample = data[0] - t.equal(sample[0], 'FakeTransaction', 'should match transaction name') - t.equal(sample[1], '/abc', 'should match transaction url') - t.equal(sample[2], 374780417029088500, 'should match query id') - t.equal(sample[3], 'select * from foo where a=2', 'should match raw query') - t.equal(sample[4], 'FakeSegment', 'should match segment name') - t.equal(sample[5], 2, 'should have 1 call') - t.equal(sample[6], 1150, 'should match total') - t.equal(sample[7], 550, 'should match min') - t.equal(sample[8], 600, 'should match max') + assert.equal(sample[0], 'FakeTransaction', 'should match transaction name') + assert.equal(sample[1], '/abc', 'should match transaction url') + assert.equal(sample[2], 374780417029088500, 'should match query id') + assert.equal(sample[3], 'select * from foo where a=2', 'should match raw query') + assert.equal(sample[4], 'FakeSegment', 'should match segment name') + assert.equal(sample[5], 2, 'should have 1 call') + assert.equal(sample[6], 1150, 'should match total') + assert.equal(sample[7], 550, 'should match min') + assert.equal(sample[8], 600, 'should match max') codec.decode(sample[9], function decoded(error, result) { - t.equal(error, null, 'should not error') + assert.equal(error, null, 'should not error') const keys = Object.keys(result) - t.same(keys, ['backtrace']) - t.same(result.backtrace, 'fake stack', 'trace should match') - t.end() + assert.deepStrictEqual(keys, ['backtrace']) + assert.deepStrictEqual(result.backtrace, 'fake stack', 'trace should match') + end() }) }) }) - t.test('should record work with a multiple unique queries', (t) => { + await t.test('should record work with a multiple unique queries', (t, end) => { + const { queries } = t.nr addQuery(queries, 600, '/abc') addQuery(queries, 550, '/abc', 'drop table users') queries.prepareJSON(function preparedJSON(err, data) { - t.equal(err, null, 'should not error') - t.equal(data.length, 2, 'should be 2 sample queries') + assert.equal(err, null, 'should not error') + assert.equal(data.length, 2, 'should be 2 sample queries') data.sort(function compareTotalTimeDesc(lhs, rhs) { const rhTotal = rhs[6] @@ -437,57 +438,55 @@ tap.test('Query Trace Aggregator', (t) => { }) const sample = data[0] - t.equal(sample[0], 'FakeTransaction', 'should match transaction name') - t.equal(sample[1], '/abc', 'should match transaction url') - t.equal(sample[2], 374780417029088500, 'should match query id') - t.equal(sample[3], 'select * from foo where a=2', 'should match raw query') - t.equal(sample[4], 'FakeSegment', 'should match segment name') - t.equal(sample[5], 1, 'should have 1 call') - t.equal(sample[6], 600, 'should match total') - t.equal(sample[7], 600, 'should match min') - t.equal(sample[8], 600, 'should match max') + assert.equal(sample[0], 'FakeTransaction', 'should match transaction name') + assert.equal(sample[1], '/abc', 'should match transaction url') + assert.equal(sample[2], 374780417029088500, 'should match query id') + assert.equal(sample[3], 'select * from foo where a=2', 'should match raw query') + assert.equal(sample[4], 'FakeSegment', 'should match segment name') + assert.equal(sample[5], 1, 'should have 1 call') + assert.equal(sample[6], 600, 'should match total') + assert.equal(sample[7], 600, 'should match min') + assert.equal(sample[8], 600, 'should match max') codec.decode(sample[9], function decoded(error, result) { - t.equal(error, null, 'should not error') + assert.equal(error, null, 'should not error') const keys = Object.keys(result) - t.same(keys, ['backtrace']) - t.same(result.backtrace, 'fake stack', 'trace should match') + assert.deepStrictEqual(keys, ['backtrace']) + assert.deepStrictEqual(result.backtrace, 'fake stack', 'trace should match') nextSample() }) function nextSample() { const sample2 = data[1] - t.equal(sample2[0], 'FakeTransaction', 'should match transaction name') - t.equal(sample2[1], '/abc', 'should match transaction url') - t.equal(sample2[2], 487602586913804700, 'should match query id') - t.equal(sample2[3], 'drop table users', 'should match raw query') - t.equal(sample2[4], 'FakeSegment', 'should match segment name') - t.equal(sample2[5], 1, 'should have 1 call') - t.equal(sample2[6], 550, 'should match total') - t.equal(sample2[7], 550, 'should match min') - t.equal(sample2[8], 550, 'should match max') + assert.equal(sample2[0], 'FakeTransaction', 'should match transaction name') + assert.equal(sample2[1], '/abc', 'should match transaction url') + assert.equal(sample2[2], 487602586913804700, 'should match query id') + assert.equal(sample2[3], 'drop table users', 'should match raw query') + assert.equal(sample2[4], 'FakeSegment', 'should match segment name') + assert.equal(sample2[5], 1, 'should have 1 call') + assert.equal(sample2[6], 550, 'should match total') + assert.equal(sample2[7], 550, 'should match min') + assert.equal(sample2[8], 550, 'should match max') codec.decode(sample2[9], function decoded(error, result) { - t.equal(error, null, 'should not error') + assert.equal(error, null, 'should not error') const keys = Object.keys(result) - t.same(keys, ['backtrace']) - t.same(result.backtrace, 'fake stack', 'trace should match') - t.end() + assert.deepStrictEqual(keys, ['backtrace']) + assert.deepStrictEqual(result.backtrace, 'fake stack', 'trace should match') + end() }) } }) }) }) - t.test('webTransaction when record_sql is "obfuscated"', (t) => { - t.autoend() - - t.test('should record work when empty', (t) => { + await t.test('webTransaction when record_sql is "obfuscated"', async (t) => { + await t.test('should record work when empty', (t, end) => { const opts = { config: new Config({ slow_sql: { enabled: true }, @@ -499,13 +498,13 @@ tap.test('Query Trace Aggregator', (t) => { const queries = new QueryTraceAggregator(opts, {}, harvester) queries.prepareJSON(function preparedJSON(err, data) { - t.equal(err, null, 'should not error') - t.same(data, [], 'should return empty array') - t.end() + assert.equal(err, null, 'should not error') + assert.deepStrictEqual(data, [], 'should return empty array') + end() }) }) - t.test('should record work with a single query', (t) => { + await t.test('should record work with a single query', (t, end) => { const opts = { config: new Config({ slow_sql: { enabled: true }, @@ -519,33 +518,33 @@ tap.test('Query Trace Aggregator', (t) => { addQuery(queries, 600, '/abc') queries.prepareJSON(function preparedJSON(err, data) { - t.equal(err, null, 'should not error') - t.equal(data.length, 1, 'should be 1 sample query') + assert.equal(err, null, 'should not error') + assert.equal(data.length, 1, 'should be 1 sample query') const sample = data[0] - t.equal(sample[0], 'FakeTransaction', 'should match transaction name') - t.equal(sample[1], '/abc', 'should match transaction url') - t.equal(sample[2], 374780417029088500, 'should match query id') - t.equal(sample[3], 'select * from foo where a=?', 'should match raw query') - t.equal(sample[4], 'FakeSegment', 'should match segment name') - t.equal(sample[5], 1, 'should have 1 call') - t.equal(sample[6], 600, 'should match total') - t.equal(sample[7], 600, 'should match min') - t.equal(sample[8], 600, 'should match max') + assert.equal(sample[0], 'FakeTransaction', 'should match transaction name') + assert.equal(sample[1], '/abc', 'should match transaction url') + assert.equal(sample[2], 374780417029088500, 'should match query id') + assert.equal(sample[3], 'select * from foo where a=?', 'should match raw query') + assert.equal(sample[4], 'FakeSegment', 'should match segment name') + assert.equal(sample[5], 1, 'should have 1 call') + assert.equal(sample[6], 600, 'should match total') + assert.equal(sample[7], 600, 'should match min') + assert.equal(sample[8], 600, 'should match max') codec.decode(sample[9], function decoded(error, result) { - t.equal(error, null, 'should not error') + assert.equal(error, null, 'should not error') const keys = Object.keys(result) - t.same(keys, ['backtrace']) - t.same(result.backtrace, 'fake stack', 'trace should match') - t.end() + assert.deepStrictEqual(keys, ['backtrace']) + assert.deepStrictEqual(result.backtrace, 'fake stack', 'trace should match') + end() }) }) }) - t.test('should record work with a multiple similar queries', (t) => { + await t.test('should record work with a multiple similar queries', (t, end) => { const opts = { config: new Config({ slow_sql: { enabled: true }, @@ -560,37 +559,37 @@ tap.test('Query Trace Aggregator', (t) => { addQuery(queries, 550, '/abc') queries.prepareJSON(function preparedJSON(err, data) { - t.equal(err, null, 'should not error') - t.equal(data.length, 1, 'should be 1 sample query') + assert.equal(err, null, 'should not error') + assert.equal(data.length, 1, 'should be 1 sample query') data.sort(function (lhs, rhs) { return rhs[2] - lhs[2] }) const sample = data[0] - t.equal(sample[0], 'FakeTransaction', 'should match transaction name') - t.equal(sample[1], '/abc', 'should match transaction url') - t.equal(sample[2], 374780417029088500, 'should match query id') - t.equal(sample[3], 'select * from foo where a=?', 'should match raw query') - t.equal(sample[4], 'FakeSegment', 'should match segment name') - t.equal(sample[5], 2, 'should have 1 call') - t.equal(sample[6], 1150, 'should match total') - t.equal(sample[7], 550, 'should match min') - t.equal(sample[8], 600, 'should match max') + assert.equal(sample[0], 'FakeTransaction', 'should match transaction name') + assert.equal(sample[1], '/abc', 'should match transaction url') + assert.equal(sample[2], 374780417029088500, 'should match query id') + assert.equal(sample[3], 'select * from foo where a=?', 'should match raw query') + assert.equal(sample[4], 'FakeSegment', 'should match segment name') + assert.equal(sample[5], 2, 'should have 1 call') + assert.equal(sample[6], 1150, 'should match total') + assert.equal(sample[7], 550, 'should match min') + assert.equal(sample[8], 600, 'should match max') codec.decode(sample[9], function decoded(error, result) { - t.equal(error, null, 'should not error') + assert.equal(error, null, 'should not error') const keys = Object.keys(result) - t.same(keys, ['backtrace']) - t.same(result.backtrace, 'fake stack', 'trace should match') - t.end() + assert.deepStrictEqual(keys, ['backtrace']) + assert.deepStrictEqual(result.backtrace, 'fake stack', 'trace should match') + end() }) }) }) - t.test('should record work with a multiple unique queries', (t) => { + await t.test('should record work with a multiple unique queries', (t, end) => { const opts = { config: new Config({ slow_sql: { enabled: true }, @@ -605,8 +604,8 @@ tap.test('Query Trace Aggregator', (t) => { addQuery(queries, 550, '/abc', 'drop table users') queries.prepareJSON(function preparedJSON(err, data) { - t.equal(err, null, 'should not error') - t.equal(data.length, 2, 'should be 1 sample query') + assert.equal(err, null, 'should not error') + assert.equal(data.length, 2, 'should be 1 sample query') data.sort(function compareTotalTimeDesc(lhs, rhs) { const rhTotal = rhs[6] @@ -616,53 +615,51 @@ tap.test('Query Trace Aggregator', (t) => { }) const sample = data[0] - t.equal(sample[0], 'FakeTransaction', 'should match transaction name') - t.equal(sample[1], '/abc', 'should match transaction url') - t.equal(sample[2], 374780417029088500, 'should match query id') - t.equal(sample[3], 'select * from foo where a=?', 'should match raw query') - t.equal(sample[4], 'FakeSegment', 'should match segment name') - t.equal(sample[5], 1, 'should have 1 call') - t.equal(sample[6], 600, 'should match total') - t.equal(sample[7], 600, 'should match min') - t.equal(sample[8], 600, 'should match max') + assert.equal(sample[0], 'FakeTransaction', 'should match transaction name') + assert.equal(sample[1], '/abc', 'should match transaction url') + assert.equal(sample[2], 374780417029088500, 'should match query id') + assert.equal(sample[3], 'select * from foo where a=?', 'should match raw query') + assert.equal(sample[4], 'FakeSegment', 'should match segment name') + assert.equal(sample[5], 1, 'should have 1 call') + assert.equal(sample[6], 600, 'should match total') + assert.equal(sample[7], 600, 'should match min') + assert.equal(sample[8], 600, 'should match max') codec.decode(sample[9], function decoded(error, result) { - t.equal(error, null, 'should not error') + assert.equal(error, null, 'should not error') const keys = Object.keys(result) - t.same(keys, ['backtrace']) - t.same(result.backtrace, 'fake stack', 'trace should match') + assert.deepStrictEqual(keys, ['backtrace']) + assert.deepStrictEqual(result.backtrace, 'fake stack', 'trace should match') const sample2 = data[1] - t.equal(sample2[0], 'FakeTransaction', 'should match transaction name') - t.equal(sample2[1], '/abc', 'should match transaction url') - t.equal(sample2[2], 487602586913804700, 'should match query id') - t.equal(sample2[3], 'drop table users', 'should match raw query') - t.equal(sample2[4], 'FakeSegment', 'should match segment name') - t.equal(sample2[5], 1, 'should have 1 call') - t.equal(sample2[6], 550, 'should match total') - t.equal(sample2[7], 550, 'should match min') - t.equal(sample2[8], 550, 'should match max') + assert.equal(sample2[0], 'FakeTransaction', 'should match transaction name') + assert.equal(sample2[1], '/abc', 'should match transaction url') + assert.equal(sample2[2], 487602586913804700, 'should match query id') + assert.equal(sample2[3], 'drop table users', 'should match raw query') + assert.equal(sample2[4], 'FakeSegment', 'should match segment name') + assert.equal(sample2[5], 1, 'should have 1 call') + assert.equal(sample2[6], 550, 'should match total') + assert.equal(sample2[7], 550, 'should match min') + assert.equal(sample2[8], 550, 'should match max') codec.decode(sample2[9], function (error, nextResult) { - t.equal(error, null, 'should not error') + assert.equal(error, null, 'should not error') const nextKey = Object.keys(nextResult) - t.same(nextKey, ['backtrace']) - t.same(nextResult.backtrace, 'fake stack', 'trace should match') - t.end() + assert.deepStrictEqual(nextKey, ['backtrace']) + assert.deepStrictEqual(nextResult.backtrace, 'fake stack', 'trace should match') + end() }) }) }) }) }) - t.test('backgroundTransaction when record_sql is "raw"', (t) => { - t.autoend() - - t.test('should record work when empty', (t) => { + await t.test('backgroundTransaction when record_sql is "raw"', async (t) => { + await t.test('should record work when empty', (t, end) => { const opts = { config: new Config({ slow_sql: { enabled: true }, @@ -674,13 +671,13 @@ tap.test('Query Trace Aggregator', (t) => { const queries = new QueryTraceAggregator(opts, {}, harvester) queries.prepareJSON(function preparedJSON(err, data) { - t.equal(err, null, 'should not error') - t.same(data, [], 'should return empty array') - t.end() + assert.equal(err, null, 'should not error') + assert.deepStrictEqual(data, [], 'should return empty array') + end() }) }) - t.test('should record work with a single query', (t) => { + await t.test('should record work with a single query', (t, end) => { const opts = { config: new Config({ slow_sql: { enabled: true }, @@ -694,33 +691,33 @@ tap.test('Query Trace Aggregator', (t) => { addQuery(queries, 600, null) queries.prepareJSON(function preparedJSON(err, data) { - t.equal(err, null, 'should not error') - t.equal(data.length, 1, 'should be 1 sample query') + assert.equal(err, null, 'should not error') + assert.equal(data.length, 1, 'should be 1 sample query') const sample = data[0] - t.equal(sample[0], 'FakeTransaction', 'should match transaction name') - t.equal(sample[1], '', 'should match transaction url') - t.equal(sample[2], 374780417029088500, 'should match query id') - t.equal(sample[3], 'select * from foo where a=2', 'should match raw query') - t.equal(sample[4], 'FakeSegment', 'should match segment name') - t.equal(sample[5], 1, 'should have 1 call') - t.equal(sample[6], 600, 'should match total') - t.equal(sample[7], 600, 'should match min') - t.equal(sample[8], 600, 'should match max') + assert.equal(sample[0], 'FakeTransaction', 'should match transaction name') + assert.equal(sample[1], '', 'should match transaction url') + assert.equal(sample[2], 374780417029088500, 'should match query id') + assert.equal(sample[3], 'select * from foo where a=2', 'should match raw query') + assert.equal(sample[4], 'FakeSegment', 'should match segment name') + assert.equal(sample[5], 1, 'should have 1 call') + assert.equal(sample[6], 600, 'should match total') + assert.equal(sample[7], 600, 'should match min') + assert.equal(sample[8], 600, 'should match max') codec.decode(sample[9], function decoded(error, result) { - t.equal(error, null, 'should not error') + assert.equal(error, null, 'should not error') const keys = Object.keys(result) - t.same(keys, ['backtrace']) - t.same(result.backtrace, 'fake stack', 'trace should match') - t.end() + assert.deepStrictEqual(keys, ['backtrace']) + assert.deepStrictEqual(result.backtrace, 'fake stack', 'trace should match') + end() }) }) }) - t.test('should record work with a multiple similar queries', (t) => { + await t.test('should record work with a multiple similar queries', (t, end) => { const opts = { config: new Config({ slow_sql: { enabled: true }, @@ -735,37 +732,37 @@ tap.test('Query Trace Aggregator', (t) => { addQuery(queries, 550, null) queries.prepareJSON(function preparedJSON(err, data) { - t.equal(err, null, 'should not error') - t.equal(data.length, 1, 'should be 1 sample query') + assert.equal(err, null, 'should not error') + assert.equal(data.length, 1, 'should be 1 sample query') data.sort(function (lhs, rhs) { return rhs[2] - lhs[2] }) const sample = data[0] - t.equal(sample[0], 'FakeTransaction', 'should match transaction name') - t.equal(sample[1], '', 'should match transaction url') - t.equal(sample[2], 374780417029088500, 'should match query id') - t.equal(sample[3], 'select * from foo where a=2', 'should match raw query') - t.equal(sample[4], 'FakeSegment', 'should match segment name') - t.equal(sample[5], 2, 'should have 1 call') - t.equal(sample[6], 1150, 'should match total') - t.equal(sample[7], 550, 'should match min') - t.equal(sample[8], 600, 'should match max') + assert.equal(sample[0], 'FakeTransaction', 'should match transaction name') + assert.equal(sample[1], '', 'should match transaction url') + assert.equal(sample[2], 374780417029088500, 'should match query id') + assert.equal(sample[3], 'select * from foo where a=2', 'should match raw query') + assert.equal(sample[4], 'FakeSegment', 'should match segment name') + assert.equal(sample[5], 2, 'should have 1 call') + assert.equal(sample[6], 1150, 'should match total') + assert.equal(sample[7], 550, 'should match min') + assert.equal(sample[8], 600, 'should match max') codec.decode(sample[9], function decoded(error, result) { - t.equal(error, null, 'should not error') + assert.equal(error, null, 'should not error') const keys = Object.keys(result) - t.same(keys, ['backtrace']) - t.same(result.backtrace, 'fake stack', 'trace should match') - t.end() + assert.deepStrictEqual(keys, ['backtrace']) + assert.deepStrictEqual(result.backtrace, 'fake stack', 'trace should match') + end() }) }) }) - t.test('should record work with a multiple unique queries', (t) => { + await t.test('should record work with a multiple unique queries', (t, end) => { const opts = { config: new Config({ slow_sql: { enabled: true }, @@ -780,8 +777,8 @@ tap.test('Query Trace Aggregator', (t) => { addQuery(queries, 550, null, 'drop table users') queries.prepareJSON(function preparedJSON(err, data) { - t.equal(err, null, 'should not error') - t.equal(data.length, 2, 'should be 1 sample query') + assert.equal(err, null, 'should not error') + assert.equal(data.length, 2, 'should be 1 sample query') data.sort(function compareTotalTimeDesc(lhs, rhs) { const rhTotal = rhs[6] @@ -791,56 +788,54 @@ tap.test('Query Trace Aggregator', (t) => { }) const sample = data[0] - t.equal(sample[0], 'FakeTransaction', 'should match transaction name') - t.equal(sample[1], '', 'should match transaction url') - t.equal(sample[2], 374780417029088500, 'should match query id') - t.equal(sample[3], 'select * from foo where a=2', 'should match raw query') - t.equal(sample[4], 'FakeSegment', 'should match segment name') - t.equal(sample[5], 1, 'should have 1 call') - t.equal(sample[6], 600, 'should match total') - t.equal(sample[7], 600, 'should match min') - t.equal(sample[8], 600, 'should match max') + assert.equal(sample[0], 'FakeTransaction', 'should match transaction name') + assert.equal(sample[1], '', 'should match transaction url') + assert.equal(sample[2], 374780417029088500, 'should match query id') + assert.equal(sample[3], 'select * from foo where a=2', 'should match raw query') + assert.equal(sample[4], 'FakeSegment', 'should match segment name') + assert.equal(sample[5], 1, 'should have 1 call') + assert.equal(sample[6], 600, 'should match total') + assert.equal(sample[7], 600, 'should match min') + assert.equal(sample[8], 600, 'should match max') codec.decode(sample[9], function decoded(error, result) { - t.equal(error, null, 'should not error') + assert.equal(error, null, 'should not error') const keys = Object.keys(result) - t.same(keys, ['backtrace']) - t.same(result.backtrace, 'fake stack', 'trace should match') + assert.deepStrictEqual(keys, ['backtrace']) + assert.deepStrictEqual(result.backtrace, 'fake stack', 'trace should match') nextSample() }) function nextSample() { const sample2 = data[1] - t.equal(sample2[0], 'FakeTransaction', 'should match transaction name') - t.equal(sample2[1], '', 'should match transaction url') - t.equal(sample2[2], 487602586913804700, 'should match query id') - t.equal(sample2[3], 'drop table users', 'should match raw query') - t.equal(sample2[4], 'FakeSegment', 'should match segment name') - t.equal(sample2[5], 1, 'should have 1 call') - t.equal(sample2[6], 550, 'should match total') - t.equal(sample2[7], 550, 'should match min') - t.equal(sample2[8], 550, 'should match max') + assert.equal(sample2[0], 'FakeTransaction', 'should match transaction name') + assert.equal(sample2[1], '', 'should match transaction url') + assert.equal(sample2[2], 487602586913804700, 'should match query id') + assert.equal(sample2[3], 'drop table users', 'should match raw query') + assert.equal(sample2[4], 'FakeSegment', 'should match segment name') + assert.equal(sample2[5], 1, 'should have 1 call') + assert.equal(sample2[6], 550, 'should match total') + assert.equal(sample2[7], 550, 'should match min') + assert.equal(sample2[8], 550, 'should match max') codec.decode(sample2[9], function decoded(error, result) { - t.equal(error, null, 'should not error') + assert.equal(error, null, 'should not error') const keys = Object.keys(result) - t.same(keys, ['backtrace']) - t.same(result.backtrace, 'fake stack', 'trace should match') - t.end() + assert.deepStrictEqual(keys, ['backtrace']) + assert.deepStrictEqual(result.backtrace, 'fake stack', 'trace should match') + end() }) } }) }) }) - t.test('background when record_sql is "obfuscated"', (t) => { - t.autoend() - - t.test('should record work when empty', (t) => { + await t.test('background when record_sql is "obfuscated"', async (t) => { + await t.test('should record work when empty', (t, end) => { const opts = { config: new Config({ slow_sql: { enabled: true }, @@ -852,13 +847,13 @@ tap.test('Query Trace Aggregator', (t) => { const queries = new QueryTraceAggregator(opts, {}, harvester) queries.prepareJSON(function preparedJSON(err, data) { - t.equal(err, null, 'should not error') - t.same(data, [], 'should return empty array') - t.end() + assert.equal(err, null, 'should not error') + assert.deepStrictEqual(data, [], 'should return empty array') + end() }) }) - t.test('should record work with a single query', (t) => { + await t.test('should record work with a single query', (t, end) => { const opts = { config: new Config({ slow_sql: { enabled: true }, @@ -872,33 +867,33 @@ tap.test('Query Trace Aggregator', (t) => { addQuery(queries, 600, null) queries.prepareJSON(function preparedJSON(err, data) { - t.equal(err, null, 'should not error') - t.equal(data.length, 1, 'should be 1 sample query') + assert.equal(err, null, 'should not error') + assert.equal(data.length, 1, 'should be 1 sample query') const sample = data[0] - t.equal(sample[0], 'FakeTransaction', 'should match transaction name') - t.equal(sample[1], '', 'should match transaction url') - t.equal(sample[2], 374780417029088500, 'should match query id') - t.equal(sample[3], 'select * from foo where a=?', 'should match raw query') - t.equal(sample[4], 'FakeSegment', 'should match segment name') - t.equal(sample[5], 1, 'should have 1 call') - t.equal(sample[6], 600, 'should match total') - t.equal(sample[7], 600, 'should match min') - t.equal(sample[8], 600, 'should match max') + assert.equal(sample[0], 'FakeTransaction', 'should match transaction name') + assert.equal(sample[1], '', 'should match transaction url') + assert.equal(sample[2], 374780417029088500, 'should match query id') + assert.equal(sample[3], 'select * from foo where a=?', 'should match raw query') + assert.equal(sample[4], 'FakeSegment', 'should match segment name') + assert.equal(sample[5], 1, 'should have 1 call') + assert.equal(sample[6], 600, 'should match total') + assert.equal(sample[7], 600, 'should match min') + assert.equal(sample[8], 600, 'should match max') codec.decode(sample[9], function decoded(error, result) { - t.equal(error, null, 'should not error') + assert.equal(error, null, 'should not error') const keys = Object.keys(result) - t.same(keys, ['backtrace']) - t.same(result.backtrace, 'fake stack', 'trace should match') - t.end() + assert.deepStrictEqual(keys, ['backtrace']) + assert.deepStrictEqual(result.backtrace, 'fake stack', 'trace should match') + end() }) }) }) - t.test('should record work with a multiple similar queries', (t) => { + await t.test('should record work with a multiple similar queries', (t, end) => { const opts = { config: new Config({ slow_sql: { enabled: true }, @@ -913,37 +908,37 @@ tap.test('Query Trace Aggregator', (t) => { addQuery(queries, 550, null) queries.prepareJSON(function preparedJSON(err, data) { - t.equal(err, null, 'should not error') - t.equal(data.length, 1, 'should be 1 sample query') + assert.equal(err, null, 'should not error') + assert.equal(data.length, 1, 'should be 1 sample query') data.sort(function (lhs, rhs) { return rhs[2] - lhs[2] }) const sample = data[0] - t.equal(sample[0], 'FakeTransaction', 'should match transaction name') - t.equal(sample[1], '', 'should match transaction url') - t.equal(sample[2], 374780417029088500, 'should match query id') - t.equal(sample[3], 'select * from foo where a=?', 'should match raw query') - t.equal(sample[4], 'FakeSegment', 'should match segment name') - t.equal(sample[5], 2, 'should have 1 call') - t.equal(sample[6], 1150, 'should match total') - t.equal(sample[7], 550, 'should match min') - t.equal(sample[8], 600, 'should match max') + assert.equal(sample[0], 'FakeTransaction', 'should match transaction name') + assert.equal(sample[1], '', 'should match transaction url') + assert.equal(sample[2], 374780417029088500, 'should match query id') + assert.equal(sample[3], 'select * from foo where a=?', 'should match raw query') + assert.equal(sample[4], 'FakeSegment', 'should match segment name') + assert.equal(sample[5], 2, 'should have 1 call') + assert.equal(sample[6], 1150, 'should match total') + assert.equal(sample[7], 550, 'should match min') + assert.equal(sample[8], 600, 'should match max') codec.decode(sample[9], function decoded(error, result) { - t.equal(error, null, 'should not error') + assert.equal(error, null, 'should not error') const keys = Object.keys(result) - t.same(keys, ['backtrace']) - t.same(result.backtrace, 'fake stack', 'trace should match') - t.end() + assert.deepStrictEqual(keys, ['backtrace']) + assert.deepStrictEqual(result.backtrace, 'fake stack', 'trace should match') + end() }) }) }) - t.test('should record work with a multiple unique queries', (t) => { + await t.test('should record work with a multiple unique queries', (t, end) => { const opts = { config: new Config({ slow_sql: { enabled: true }, @@ -958,8 +953,8 @@ tap.test('Query Trace Aggregator', (t) => { addQuery(queries, 550, null, 'drop table users') queries.prepareJSON(function preparedJSON(err, data) { - t.equal(err, null, 'should not error') - t.equal(data.length, 2, 'should be 1 sample query') + assert.equal(err, null, 'should not error') + assert.equal(data.length, 2, 'should be 1 sample query') data.sort(function compareTotalTimeDesc(lhs, rhs) { const rhTotal = rhs[6] @@ -969,43 +964,43 @@ tap.test('Query Trace Aggregator', (t) => { }) const sample = data[0] - t.equal(sample[0], 'FakeTransaction', 'should match transaction name') - t.equal(sample[1], '', 'should match transaction url') - t.equal(sample[2], 374780417029088500, 'should match query id') - t.equal(sample[3], 'select * from foo where a=?', 'should match raw query') - t.equal(sample[4], 'FakeSegment', 'should match segment name') - t.equal(sample[5], 1, 'should have 1 call') - t.equal(sample[6], 600, 'should match total') - t.equal(sample[7], 600, 'should match min') - t.equal(sample[8], 600, 'should match max') + assert.equal(sample[0], 'FakeTransaction', 'should match transaction name') + assert.equal(sample[1], '', 'should match transaction url') + assert.equal(sample[2], 374780417029088500, 'should match query id') + assert.equal(sample[3], 'select * from foo where a=?', 'should match raw query') + assert.equal(sample[4], 'FakeSegment', 'should match segment name') + assert.equal(sample[5], 1, 'should have 1 call') + assert.equal(sample[6], 600, 'should match total') + assert.equal(sample[7], 600, 'should match min') + assert.equal(sample[8], 600, 'should match max') codec.decode(sample[9], function decoded(error, result) { - t.equal(error, null, 'should not error') + assert.equal(error, null, 'should not error') const keys = Object.keys(result) - t.same(keys, ['backtrace']) - t.same(result.backtrace, 'fake stack', 'trace should match') + assert.deepStrictEqual(keys, ['backtrace']) + assert.deepStrictEqual(result.backtrace, 'fake stack', 'trace should match') const sample2 = data[1] - t.equal(sample2[0], 'FakeTransaction', 'should match transaction name') - t.equal(sample2[1], '', 'should match transaction url') - t.equal(sample2[2], 487602586913804700, 'should match query id') - t.equal(sample2[3], 'drop table users', 'should match raw query') - t.equal(sample2[4], 'FakeSegment', 'should match segment name') - t.equal(sample2[5], 1, 'should have 1 call') - t.equal(sample2[6], 550, 'should match total') - t.equal(sample2[7], 550, 'should match min') - t.equal(sample2[8], 550, 'should match max') + assert.equal(sample2[0], 'FakeTransaction', 'should match transaction name') + assert.equal(sample2[1], '', 'should match transaction url') + assert.equal(sample2[2], 487602586913804700, 'should match query id') + assert.equal(sample2[3], 'drop table users', 'should match raw query') + assert.equal(sample2[4], 'FakeSegment', 'should match segment name') + assert.equal(sample2[5], 1, 'should have 1 call') + assert.equal(sample2[6], 550, 'should match total') + assert.equal(sample2[7], 550, 'should match min') + assert.equal(sample2[8], 550, 'should match max') codec.decode(sample2[9], function (error, nextResult) { - t.equal(error, null, 'should not error') + assert.equal(error, null, 'should not error') const nextKeys = Object.keys(nextResult) - t.same(nextKeys, ['backtrace']) - t.same(nextResult.backtrace, 'fake stack', 'trace should match') - t.end() + assert.deepStrictEqual(nextKeys, ['backtrace']) + assert.deepStrictEqual(nextResult.backtrace, 'fake stack', 'trace should match') + end() }) }) }) @@ -1013,10 +1008,8 @@ tap.test('Query Trace Aggregator', (t) => { }) }) - t.test('limiting to n slowest', (t) => { - t.autoend() - - t.test('should limit to this.config.max_samples', (t) => { + await t.test('limiting to n slowest', async (t) => { + await t.test('should limit to this.config.max_samples', (t, end) => { const opts = { config: new Config({ slow_sql: { enabled: true, max_samples: 2 }, @@ -1030,25 +1023,23 @@ tap.test('Query Trace Aggregator', (t) => { addQuery(queries, 600, null) addQuery(queries, 550, null, 'create table users') - t.hasProp(queries.samples, 'size') - t.equal(queries.samples.size, 2) - t.ok(queries.samples.has('select*fromfoowherea=?')) - t.ok(queries.samples.has('createtableusers')) + assert.ok('size' in queries.samples) + assert.equal(queries.samples.size, 2) + assert.ok(queries.samples.has('select*fromfoowherea=?')) + assert.ok(queries.samples.has('createtableusers')) addQuery(queries, 650, null, 'drop table users') - t.hasProp(queries.samples, 'size') - t.equal(queries.samples.size, 2) - t.ok(queries.samples.has('select*fromfoowherea=?')) - t.ok(queries.samples.has('droptableusers')) - t.end() + assert.ok('size' in queries.samples) + assert.equal(queries.samples.size, 2) + assert.ok(queries.samples.has('select*fromfoowherea=?')) + assert.ok(queries.samples.has('droptableusers')) + end() }) }) - t.test('merging query tracers', (t) => { - t.autoend() - - t.test('should merge queries correctly', (t) => { + await t.test('merging query tracers', async (t) => { + await t.test('should merge queries correctly', (t, end) => { const opts = { config: new Config({ slow_sql: { enabled: true }, @@ -1075,27 +1066,27 @@ tap.test('Query Trace Aggregator', (t) => { queries._merge(queries2.samples) - t.hasProp(queries.samples, 'size') - t.equal(queries.samples.size, 2) - t.ok(queries.samples.has('select*fromfoowherea=?')) - t.ok(queries.samples.has('createtableusers')) + assert.ok('size' in queries.samples) + assert.equal(queries.samples.size, 2) + assert.ok(queries.samples.has('select*fromfoowherea=?')) + assert.ok(queries.samples.has('createtableusers')) const select = queries.samples.get('select*fromfoowherea=?') - t.equal(select.callCount, 2, 'should have correct callCount') - t.equal(select.max, 800, 'max should be set') - t.equal(select.min, 600, 'min should be set') - t.equal(select.total, 1400, 'total should be set') - t.equal(select.trace.duration, 800, 'trace should be set') + assert.equal(select.callCount, 2, 'should have correct callCount') + assert.equal(select.max, 800, 'max should be set') + assert.equal(select.min, 600, 'min should be set') + assert.equal(select.total, 1400, 'total should be set') + assert.equal(select.trace.duration, 800, 'trace should be set') const create = queries.samples.get('createtableusers') - t.equal(create.callCount, 2, 'should have correct callCount') - t.equal(create.max, 650, 'max should be set') - t.equal(create.min, 500, 'min should be set') - t.equal(create.total, 1150, 'total should be set') - t.equal(create.trace.duration, 650, 'trace should be set') - t.end() + assert.equal(create.callCount, 2, 'should have correct callCount') + assert.equal(create.max, 650, 'max should be set') + assert.equal(create.min, 500, 'min should be set') + assert.equal(create.total, 1150, 'total should be set') + assert.equal(create.trace.duration, 650, 'trace should be set') + end() }) }) }) @@ -1109,24 +1100,24 @@ function addQuery(queries, duration, url, query) { return segment } -function verifySample(t, sample, count, segment) { - t.equal(sample.callCount, count, 'should have correct callCount') - t.ok(sample.max, 'max should be set') - t.ok(sample.min, 'min should be set') - t.ok(sample.sumOfSquares, 'sumOfSquares should be set') - t.ok(sample.total, 'total should be set') - t.ok(sample.totalExclusive, 'totalExclusive should be set') - t.ok(sample.trace, 'trace should be set') - verifyTrace(t, sample.trace, segment) +function verifySample(sample, count, segment) { + assert.equal(sample.callCount, count, 'should have correct callCount') + assert.ok(sample.max, 'max should be set') + assert.ok(sample.min, 'min should be set') + assert.ok(sample.sumOfSquares, 'sumOfSquares should be set') + assert.ok(sample.total, 'total should be set') + assert.ok(sample.totalExclusive, 'totalExclusive should be set') + assert.ok(sample.trace, 'trace should be set') + verifyTrace(sample.trace, segment) } -function verifyTrace(t, trace, segment) { - t.equal(trace.duration, segment.getDurationInMillis(), 'should save duration') - t.equal(trace.segment, segment, 'should hold onto segment') - t.equal(trace.id, 374780417029088500, 'should have correct id') - t.equal(trace.metric, segment.name, 'metric and segment name should match') - t.equal(trace.normalized, 'select*fromfoowherea=?', 'should set normalized') - t.equal(trace.obfuscated, 'select * from foo where a=?', 'should set obfuscated') - t.equal(trace.query, 'select * from foo where a=2', 'should set query') - t.equal(trace.trace, 'fake stack', 'should set trace') +function verifyTrace(trace, segment) { + assert.equal(trace.duration, segment.getDurationInMillis(), 'should save duration') + assert.equal(trace.segment, segment, 'should hold onto segment') + assert.equal(trace.id, 374780417029088500, 'should have correct id') + assert.equal(trace.metric, segment.name, 'metric and segment name should match') + assert.equal(trace.normalized, 'select*fromfoowherea=?', 'should set normalized') + assert.equal(trace.obfuscated, 'select * from foo where a=?', 'should set obfuscated') + assert.equal(trace.query, 'select * from foo where a=2', 'should set query') + assert.equal(trace.trace, 'fake stack', 'should set trace') } diff --git a/test/unit/db/trace.test.js b/test/unit/db/trace.test.js index edfa8462f3..361fa978e4 100644 --- a/test/unit/db/trace.test.js +++ b/test/unit/db/trace.test.js @@ -5,13 +5,14 @@ 'use strict' -const tap = require('tap') +const test = require('node:test') +const assert = require('node:assert') const helper = require('../../lib/agent_helper') -tap.test('SQL trace attributes', function (t) { - t.autoend() - t.beforeEach(function (t) { - t.context.agent = helper.loadMockedAgent({ +test('SQL trace attributes', async (t) => { + t.beforeEach((ctx) => { + ctx.nr = {} + ctx.nr.agent = helper.loadMockedAgent({ slow_sql: { enabled: true }, @@ -22,60 +23,63 @@ tap.test('SQL trace attributes', function (t) { }) }) - t.afterEach(function (t) { - helper.unloadAgent(t.context.agent) + t.afterEach((ctx) => { + helper.unloadAgent(ctx.nr.agent) }) - t.test('should include all DT intrinsics sans parentId and parentSpanId', function (t) { - const { agent } = t.context - agent.config.distributed_tracing.enabled = true - agent.config.primary_application_id = 'test' - agent.config.account_id = 1 - agent.config.simple_compression = true - helper.runInTransaction(agent, function (tx) { - const payload = tx._createDistributedTracePayload().text() - tx.isDistributedTrace = null - tx._acceptDistributedTracePayload(payload) - agent.queries.add(tx.trace.root, 'postgres', 'select pg_sleep(1)', 'FAKE STACK') - agent.queries.prepareJSON((err, samples) => { - const sample = samples[0] - const attributes = sample[sample.length - 1] - t.equal(attributes.traceId, tx.traceId) - t.equal(attributes.guid, tx.id) - t.equal(attributes.priority, tx.priority) - t.equal(attributes.sampled, tx.sampled) - t.equal(attributes['parent.type'], 'App') - t.equal(attributes['parent.app'], agent.config.primary_application_id) - t.equal(attributes['parent.account'], agent.config.account_id) - t.notOk(attributes.parentId) - t.notOk(attributes.parentSpanId) - t.end() + await t.test( + 'should include all DT intrinsics sans parentId and parentSpanId', + function (t, end) { + const { agent } = t.nr + agent.config.distributed_tracing.enabled = true + agent.config.primary_application_id = 'test' + agent.config.account_id = 1 + agent.config.simple_compression = true + helper.runInTransaction(agent, function (tx) { + const payload = tx._createDistributedTracePayload().text() + tx.isDistributedTrace = null + tx._acceptDistributedTracePayload(payload) + agent.queries.add(tx.trace.root, 'postgres', 'select pg_sleep(1)', 'FAKE STACK') + agent.queries.prepareJSON((err, samples) => { + const sample = samples[0] + const attributes = sample[sample.length - 1] + assert.equal(attributes.traceId, tx.traceId) + assert.equal(attributes.guid, tx.id) + assert.equal(attributes.priority, tx.priority) + assert.equal(attributes.sampled, tx.sampled) + assert.equal(attributes['parent.type'], 'App') + assert.equal(attributes['parent.app'], agent.config.primary_application_id) + assert.equal(attributes['parent.account'], agent.config.account_id) + assert.ok(!attributes.parentId) + assert.ok(!attributes.parentSpanId) + end() + }) }) - }) - }) + } + ) - t.test('should serialize properly using prepareJSONSync', function (t) { - const { agent } = t.context + await t.test('should serialize properly using prepareJSONSync', function (t, end) { + const { agent } = t.nr helper.runInTransaction(agent, function (tx) { const query = 'select pg_sleep(1)' agent.queries.add(tx.trace.root, 'postgres', query, 'FAKE STACK') const sampleObj = agent.queries.samples.values().next().value const sample = agent.queries.prepareJSONSync()[0] - t.equal(sample[0], tx.getFullName()) - t.equal(sample[1], '') - t.equal(sample[2], sampleObj.trace.id) - t.equal(sample[3], query) - t.equal(sample[4], sampleObj.trace.metric) - t.equal(sample[5], sampleObj.callCount) - t.equal(sample[6], sampleObj.total) - t.equal(sample[7], sampleObj.min) - t.equal(sample[8], sampleObj.max) - t.end() + assert.equal(sample[0], tx.getFullName()) + assert.equal(sample[1], '') + assert.equal(sample[2], sampleObj.trace.id) + assert.equal(sample[3], query) + assert.equal(sample[4], sampleObj.trace.metric) + assert.equal(sample[5], sampleObj.callCount) + assert.equal(sample[6], sampleObj.total) + assert.equal(sample[7], sampleObj.min) + assert.equal(sample[8], sampleObj.max) + end() }) }) - t.test('should include the proper priority on transaction end', function (t) { - const { agent } = t.context + await t.test('should include the proper priority on transaction end', function (t, end) { + const { agent } = t.nr agent.config.distributed_tracing.enabled = true agent.config.primary_application_id = 'test' agent.config.account_id = 1 @@ -85,15 +89,15 @@ tap.test('SQL trace attributes', function (t) { agent.queries.prepareJSON((err, samples) => { const sample = samples[0] const attributes = sample[sample.length - 1] - t.equal(attributes.traceId, tx.traceId) - t.equal(attributes.guid, tx.id) - t.equal(attributes.priority, tx.priority) - t.equal(attributes.sampled, tx.sampled) - t.notOk(attributes.parentId) - t.notOk(attributes.parentSpanId) - t.equal(tx.sampled, true) - t.ok(tx.priority > 1) - t.end() + assert.equal(attributes.traceId, tx.traceId) + assert.equal(attributes.guid, tx.id) + assert.equal(attributes.priority, tx.priority) + assert.equal(attributes.sampled, tx.sampled) + assert.ok(!attributes.parentId) + assert.ok(!attributes.parentSpanId) + assert.equal(tx.sampled, true) + assert.ok(tx.priority > 1) + end() }) }) })