From dd3bdc0aa2ff41227ac12738cabeb1b4e296f772 Mon Sep 17 00:00:00 2001 From: Amy Chisholm Date: Fri, 23 Aug 2024 13:25:15 -0700 Subject: [PATCH 1/7] refactor: replaced tap with node:test --- test/unit/db/query-parsers/sql.test.js | 179 +++-- test/unit/db/query-sample.test.js | 77 +- test/unit/db/query-trace-aggregator.test.js | 773 ++++++++++---------- test/unit/db/trace.test.js | 81 +- 4 files changed, 542 insertions(+), 568 deletions(-) diff --git a/test/unit/db/query-parsers/sql.test.js b/test/unit/db/query-parsers/sql.test.js index bff3b8fb3e..a68c05b465 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,38 @@ 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 +67,117 @@ 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() + await t.test('should parse the operation as ' + cat.operation, function (t) { + assert.equal(ps.operation, cat.operation) }) if (cat.table === '(subquery)') { - t.test('should parse subquery collections as ' + cat.table) + await t.test('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) + await t.test('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() + await t.test('should parse the collection as ' + cat.table, function (t) { + assert.equal(ps.collection, cat.table) }) } }) - }) + } }) }) diff --git a/test/unit/db/query-sample.test.js b/test/unit/db/query-sample.test.js index 6db25b9ce0..49b76bfa7d 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 @@ -102,21 +93,19 @@ tap.test('Query Sample', (t) => { codecCalled = true } sinon.stub(codec, 'encode').callsFake(fakeCodec) - sinon.stub(QuerySample.prototype, 'getParams').callsFake(() => {}) + sinon.stub(QuerySample.prototype, 'getParams').callsFake(() => { }) const querySample = new QuerySample(fakeTracer, fakeSample) - querySample.prepareJSON(() => {}) + 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, @@ -141,25 +130,23 @@ tap.test('Query Sample', (t) => { const clock = sinon.useFakeTimers({ toFake: ['nextTick'] }) - process.nextTick(() => {}) + process.nextTick(() => { }) - sinon.stub(QuerySample.prototype, 'getParams').callsFake(() => {}) + sinon.stub(QuerySample.prototype, 'getParams').callsFake(() => { }) const querySample = new QuerySample(fakeTracer, fakeSample) - querySample.prepareJSON(() => {}) + querySample.prepareJSON(() => { }) 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, @@ -178,7 +165,7 @@ tap.test('Query Sample', (t) => { segment: { getAttributes: fakeGetAttributes, transaction: { - addDistributedTraceIntrinsics: () => {} + addDistributedTraceIntrinsics: () => { } } } } @@ -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..0529217715 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,10 +15,8 @@ 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) => { +test('Query Trace Aggregator', async (t) => { + await t.test('when no queries in payload, _toPayload should exec callback with null data', () => { const opts = { config: new Config({ slow_sql: { enabled: false }, @@ -39,13 +37,12 @@ tap.test('Query Trace Aggregator', (t) => { queries._toPayload(cb) - t.ok(cbCalledWithNull) - t.end() + assert.ok(cbCalledWithNull) }) - t.test('when slow_sql.enabled is false', (t) => { - t.autoend() - t.test('should not record anything when transaction_tracer.record_sql === "off"', (t) => { + await t.test('when slow_sql.enabled is false', async (t) => { + + await t.test('should not record anything when transaction_tracer.record_sql === "off"', () => { const opts = { config: new Config({ slow_sql: { enabled: false }, @@ -57,13 +54,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') + }) - 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', () => { const opts = { config: new Config({ slow_sql: { enabled: false }, @@ -75,13 +72,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') + }) - t.test('should record only in trace when record_sql === "obfuscated"', (t) => { + await t.test('should record only in trace when record_sql === "obfuscated"', () => { const opts = { config: new Config({ slow_sql: { enabled: false }, @@ -93,9 +90,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 +100,10 @@ tap.test('Query Trace Aggregator', (t) => { }, 'should record sql in trace' ) - t.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"', () => { const opts = { config: new Config({ slow_sql: { enabled: false }, @@ -118,9 +115,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 +125,10 @@ tap.test('Query Trace Aggregator', (t) => { }, 'should record sql in trace' ) - t.end() + }) - t.test('should not record if below threshold', (t) => { + await t.test('should not record if below threshold', () => { const opts = { config: new Config({ slow_sql: { enabled: false }, @@ -143,23 +140,21 @@ 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() + }) }) - t.test('when slow_sql.enabled is true', (t) => { - t.autoend() - - t.test('should not record anything when transaction_tracer.record_sql === "off"', (t) => { + await t.test('when slow_sql.enabled is true', async (t) => { + await t.test('should not record anything when transaction_tracer.record_sql === "off"', () => { const opts = { config: new Config({ slow_sql: { enabled: true }, @@ -171,13 +166,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') + }) - 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', () => { const opts = { config: new Config({ slow_sql: { enabled: true }, @@ -189,13 +184,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') + }) - t.test('should record obfuscated trace when record_sql === "obfuscated"', (t) => { + await t.test('should record obfuscated trace when record_sql === "obfuscated"', (t) => { const opts = { config: new Config({ slow_sql: { enabled: true }, @@ -207,7 +202,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 +211,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() + }) - t.test('should record raw when record_sql === "raw"', (t) => { + await t.test('should record raw when record_sql === "raw"', (t) => { const opts = { config: new Config({ slow_sql: { enabled: true }, @@ -237,7 +232,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 +241,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() + }) - t.test('should not record if below threshold', (t) => { + await t.test('should not record if below threshold', () => { const opts = { config: new Config({ slow_sql: { enabled: true }, @@ -267,24 +262,24 @@ 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() + }) }) - t.test('prepareJSON', (t) => { - t.autoend() + await t.test('prepareJSON', async (t) => { + - t.test('webTransaction when record_sql is "raw"', (t) => { - t.autoend() + await t.test('webTransaction when record_sql is "raw"', async (t) => { + let queries @@ -300,40 +295,40 @@ tap.test('Query Trace Aggregator', (t) => { queries = new QueryTraceAggregator(opts, {}, harvester) }) - t.test('and `simple_compression` is `false`', (t) => { - t.autoend() + await t.test('and `simple_compression` is `false`', async (t) => { + t.beforeEach(() => { queries.config.simple_compression = false }) - t.test('should compress the query parameters', (t) => { + await t.test('should compress the query parameters', () => { 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') + }) }) }) }) - t.test('and `simple_compression` is `true`', (t) => { - t.autoend() + await t.test('and `simple_compression` is `true`', async (t) => { + t.beforeEach(() => { queries.config.simple_compression = true }) - t.test('should not compress the query parameters', (t) => { + await t.test('should not compress the query parameters', (t) => { addQuery(queries, 600, '/abc') queries.prepareJSON(function preparedJSON(err, data) { @@ -341,93 +336,93 @@ 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') + }) }) }) - t.test('should record work when empty', (t) => { + await t.test('should record work when empty', () => { 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') + }) }) - t.test('should record work with a single query', (t) => { + await t.test('should record work with a single query', () => { 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') + }) }) }) - t.test('should record work with a multiple similar queries', (t) => { + await t.test('should record work with a multiple similar queries', () => { 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') + }) }) }) - t.test('should record work with a multiple unique queries', (t) => { + await t.test('should record work with a multiple unique queries', () => { 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 +432,57 @@ 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') + }) } }) }) }) - t.test('webTransaction when record_sql is "obfuscated"', (t) => { - t.autoend() + await t.test('webTransaction when record_sql is "obfuscated"', async (t) => { + - t.test('should record work when empty', (t) => { + await t.test('should record work when empty', () => { const opts = { config: new Config({ slow_sql: { enabled: true }, @@ -499,13 +494,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') + }) }) - t.test('should record work with a single query', (t) => { + await t.test('should record work with a single query', () => { const opts = { config: new Config({ slow_sql: { enabled: true }, @@ -519,33 +514,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') + }) }) }) - t.test('should record work with a multiple similar queries', (t) => { + await t.test('should record work with a multiple similar queries', () => { const opts = { config: new Config({ slow_sql: { enabled: true }, @@ -560,37 +555,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') + }) }) }) - t.test('should record work with a multiple unique queries', (t) => { + await t.test('should record work with a multiple unique queries', () => { const opts = { config: new Config({ slow_sql: { enabled: true }, @@ -605,8 +600,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 +611,53 @@ 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') + }) }) }) }) }) - t.test('backgroundTransaction when record_sql is "raw"', (t) => { - t.autoend() + await t.test('backgroundTransaction when record_sql is "raw"', async (t) => { + - t.test('should record work when empty', (t) => { + await t.test('should record work when empty', () => { const opts = { config: new Config({ slow_sql: { enabled: true }, @@ -674,13 +669,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') + }) }) - t.test('should record work with a single query', (t) => { + await t.test('should record work with a single query', () => { const opts = { config: new Config({ slow_sql: { enabled: true }, @@ -694,33 +689,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') + }) }) }) - t.test('should record work with a multiple similar queries', (t) => { + await t.test('should record work with a multiple similar queries', () => { const opts = { config: new Config({ slow_sql: { enabled: true }, @@ -735,37 +730,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') + }) }) }) - t.test('should record work with a multiple unique queries', (t) => { + await t.test('should record work with a multiple unique queries', () => { const opts = { config: new Config({ slow_sql: { enabled: true }, @@ -780,8 +775,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 +786,56 @@ 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') + }) } }) }) }) - t.test('background when record_sql is "obfuscated"', (t) => { - t.autoend() + await t.test('background when record_sql is "obfuscated"', async (t) => { + - t.test('should record work when empty', (t) => { + await t.test('should record work when empty', () => { 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') + }) }) - t.test('should record work with a single query', (t) => { + await t.test('should record work with a single query', () => { 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') + }) }) }) - t.test('should record work with a multiple similar queries', (t) => { + await t.test('should record work with a multiple similar queries', () => { 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') + }) }) }) - t.test('should record work with a multiple unique queries', (t) => { + await t.test('should record work with a multiple unique queries', () => { 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') + }) }) }) @@ -1013,10 +1008,10 @@ tap.test('Query Trace Aggregator', (t) => { }) }) - t.test('limiting to n slowest', (t) => { - t.autoend() + await t.test('limiting to n slowest', async (t) => { + - t.test('should limit to this.config.max_samples', (t) => { + await t.test('should limit to this.config.max_samples', () => { const opts = { config: new Config({ slow_sql: { enabled: true, max_samples: 2 }, @@ -1030,25 +1025,25 @@ 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')) + }) }) - t.test('merging query tracers', (t) => { - t.autoend() + await t.test('merging query tracers', async (t) => { + - t.test('should merge queries correctly', (t) => { + await t.test('should merge queries correctly', () => { const opts = { config: new Config({ slow_sql: { enabled: true }, @@ -1075,27 +1070,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') + }) }) }) @@ -1110,23 +1105,23 @@ function addQuery(queries, duration, url, query) { } 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') + 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(t, 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') + 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..ae3d8c22bd 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() +test('SQL trace attributes', async (t) => { + t.beforeEach(function (t) { - t.context.agent = helper.loadMockedAgent({ + t.mock.agent = helper.loadMockedAgent({ slow_sql: { enabled: true }, @@ -23,11 +24,11 @@ tap.test('SQL trace attributes', function (t) { }) t.afterEach(function (t) { - helper.unloadAgent(t.context.agent) + helper.unloadAgent(t.mock.agent) }) - t.test('should include all DT intrinsics sans parentId and parentSpanId', function (t) { - const { agent } = t.context + await t.test('should include all DT intrinsics sans parentId and parentSpanId', function (t) { + const { agent } = t.mock agent.config.distributed_tracing.enabled = true agent.config.primary_application_id = 'test' agent.config.account_id = 1 @@ -40,42 +41,42 @@ 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.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() + 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) + }) }) }) - t.test('should serialize properly using prepareJSONSync', function (t) { - const { agent } = t.context + await t.test('should serialize properly using prepareJSONSync', function (t) { + const { agent } = t.mock 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) + }) }) - 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) { + const { agent } = t.mock agent.config.distributed_tracing.enabled = true agent.config.primary_application_id = 'test' agent.config.account_id = 1 @@ -85,15 +86,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) + }) }) }) From 96fed49309e090714bad53bb4de7622a3ccfbd6e Mon Sep 17 00:00:00 2001 From: Amy Chisholm Date: Fri, 23 Aug 2024 13:54:58 -0700 Subject: [PATCH 2/7] fix: linting --- test/unit/db/query-parsers/sql.test.js | 20 +------- test/unit/db/query-sample.test.js | 12 ++--- test/unit/db/query-trace-aggregator.test.js | 53 +-------------------- test/unit/db/trace.test.js | 4 -- 4 files changed, 10 insertions(+), 79 deletions(-) diff --git a/test/unit/db/query-parsers/sql.test.js b/test/unit/db/query-parsers/sql.test.js index a68c05b465..801b4a3e4e 100644 --- a/test/unit/db/query-parsers/sql.test.js +++ b/test/unit/db/query-parsers/sql.test.js @@ -21,11 +21,9 @@ function clean(sql) { } test('database query parser', async (t) => { - await t.test('should accept query as a string', function () { const ps = parseSql('select * from someTable') assert.equal(ps.query, 'select * from someTable') - }) await t.test('should accept query as a sql property of an object', function () { @@ -33,11 +31,9 @@ test('database query parser', async (t) => { sql: 'select * from someTable' }) assert.equal(ps.query, 'select * from someTable') - }) await t.test('SELECT SQL', async (t) => { - await t.test('should parse a simple query', function () { const ps = parseSql('Select * from dude') assert.ok(ps) @@ -48,7 +44,6 @@ test('database query parser', async (t) => { assert.ok(ps.collection) assert.equal(ps.collection, 'dude') assert.equal(ps.query, 'Select * from dude') - }) await t.test('should parse more interesting queries too', function () { @@ -71,12 +66,10 @@ test('database query parser', async (t) => { assert.equal(ps.operation, 'select') assert.equal(ps.collection, 'postcodes') assert.equal(ps.query, sql) - }) }) await t.test('DELETE SQL', async (t) => { - await t.test('should parse a simple command', function () { const ps = parseSql('DELETE\nfrom dude') assert.ok(ps) @@ -87,7 +80,6 @@ test('database query parser', async (t) => { assert.ok(ps.collection) assert.equal(ps.collection, 'dude') assert.equal(ps.query, 'DELETE\nfrom dude') - }) await t.test('should parse a command with conditions', function () { @@ -100,12 +92,10 @@ test('database query parser', async (t) => { assert.ok(ps.collection) assert.equal(ps.collection, 'dude') assert.equal(ps.query, "DELETE\nfrom dude where name = 'man'") - }) }) 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') assert.ok(ps) @@ -116,12 +106,10 @@ test('database query parser', async (t) => { assert.ok(ps.collection) assert.equal(ps.collection, 'test') assert.equal(ps.query, 'update test set value = 1 where id = 12') - }) }) 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') assert.ok(ps) @@ -132,19 +120,16 @@ test('database query parser', async (t) => { assert.ok(ps.collection) assert.equal(ps.collection, 'test') assert.equal(ps.query, 'insert into\ntest\nselect * from dude') - }) }) 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') assert.ok(ps) assert.equal(ps.operation, 'other') assert.ok(!ps.collection) assert.equal(ps.query, 'bulge into\ndudes\nselect * from dude') - }) await t.test("should return 'other' when handed an object", function () { @@ -155,7 +140,6 @@ test('database query parser', async (t) => { assert.equal(ps.operation, 'other') assert.ok(!ps.collection) assert.equal(ps.query, '') - }) }) @@ -164,7 +148,7 @@ test('database query parser', async (t) => { await t.test(clean(cat.input), async (t) => { const ps = parseSql(cat.input) - await t.test('should parse the operation as ' + cat.operation, function (t) { + await t.test('should parse the operation as ' + cat.operation, function () { assert.equal(ps.operation, cat.operation) }) @@ -173,7 +157,7 @@ test('database query parser', async (t) => { } else if (/\w+\.\w+/.test(ps.collection)) { await t.test('should strip database names from collection names as ' + cat.table) } else { - await t.test('should parse the collection as ' + cat.table, function (t) { + await t.test('should parse the collection as ' + cat.table, function () { assert.equal(ps.collection, cat.table) }) } diff --git a/test/unit/db/query-sample.test.js b/test/unit/db/query-sample.test.js index 49b76bfa7d..93b85793b1 100644 --- a/test/unit/db/query-sample.test.js +++ b/test/unit/db/query-sample.test.js @@ -93,11 +93,11 @@ test('Query Sample', async (t) => { codecCalled = true } sinon.stub(codec, 'encode').callsFake(fakeCodec) - sinon.stub(QuerySample.prototype, 'getParams').callsFake(() => { }) + sinon.stub(QuerySample.prototype, 'getParams').callsFake(() => {}) const querySample = new QuerySample(fakeTracer, fakeSample) - querySample.prepareJSON(() => { }) + querySample.prepareJSON(() => {}) assert.ok(codecCalled) @@ -130,13 +130,13 @@ test('Query Sample', async (t) => { const clock = sinon.useFakeTimers({ toFake: ['nextTick'] }) - process.nextTick(() => { }) + process.nextTick(() => {}) - sinon.stub(QuerySample.prototype, 'getParams').callsFake(() => { }) + sinon.stub(QuerySample.prototype, 'getParams').callsFake(() => {}) const querySample = new QuerySample(fakeTracer, fakeSample) - querySample.prepareJSON(() => { }) + querySample.prepareJSON(() => {}) clock.runAll() @@ -165,7 +165,7 @@ test('Query Sample', async (t) => { segment: { getAttributes: fakeGetAttributes, transaction: { - addDistributedTraceIntrinsics: () => { } + addDistributedTraceIntrinsics: () => {} } } } diff --git a/test/unit/db/query-trace-aggregator.test.js b/test/unit/db/query-trace-aggregator.test.js index 0529217715..c237a9225b 100644 --- a/test/unit/db/query-trace-aggregator.test.js +++ b/test/unit/db/query-trace-aggregator.test.js @@ -41,8 +41,7 @@ test('Query Trace Aggregator', async (t) => { }) await t.test('when slow_sql.enabled is false', async (t) => { - - await t.test('should not record anything when transaction_tracer.record_sql === "off"', () => { + await t.test('should not record anything when transaction_tracer.record_sql === "off"', () => { const opts = { config: new Config({ slow_sql: { enabled: false }, @@ -57,7 +56,6 @@ test('Query Trace Aggregator', async (t) => { assert.ok('size' in queries.samples) assert.equal(queries.samples.size, 0) assert.deepStrictEqual(segment.getAttributes(), {}, 'should not record sql in trace') - }) await t.test('should treat unknown value in transaction_tracer.record_sql as off', () => { @@ -75,7 +73,6 @@ test('Query Trace Aggregator', async (t) => { assert.ok('size' in queries.samples) assert.equal(queries.samples.size, 0) assert.deepStrictEqual(segment.getAttributes(), {}, 'should not record sql in trace') - }) await t.test('should record only in trace when record_sql === "obfuscated"', () => { @@ -100,7 +97,6 @@ test('Query Trace Aggregator', async (t) => { }, 'should record sql in trace' ) - }) await t.test('should record only in trace when record_sql === "raw"', () => { @@ -125,7 +121,6 @@ test('Query Trace Aggregator', async (t) => { }, 'should record sql in trace' ) - }) await t.test('should not record if below threshold', () => { @@ -149,7 +144,6 @@ test('Query Trace Aggregator', async (t) => { }, 'should record sql in trace' ) - }) }) @@ -169,7 +163,6 @@ test('Query Trace Aggregator', async (t) => { assert.ok('size' in queries.samples) assert.equal(queries.samples.size, 0) assert.deepStrictEqual(segment.getAttributes(), {}, 'should not record sql in trace') - }) await t.test('should treat unknown value in transaction_tracer.record_sql as off', () => { @@ -187,7 +180,6 @@ test('Query Trace Aggregator', async (t) => { assert.ok('size' in queries.samples) assert.equal(queries.samples.size, 0) assert.deepStrictEqual(segment.getAttributes(), {}, 'should not record sql in trace') - }) await t.test('should record obfuscated trace when record_sql === "obfuscated"', (t) => { @@ -217,7 +209,6 @@ test('Query Trace Aggregator', async (t) => { const sample = queries.samples.get('select*fromfoowherea=?') verifySample(t, sample, 1, segment) - }) await t.test('should record raw when record_sql === "raw"', (t) => { @@ -247,7 +238,6 @@ test('Query Trace Aggregator', async (t) => { const sample = queries.samples.get('select*fromfoowherea=?') verifySample(t, sample, 1, segment) - }) await t.test('should not record if below threshold', () => { @@ -271,16 +261,11 @@ test('Query Trace Aggregator', async (t) => { }, 'should record sql in trace' ) - }) }) await t.test('prepareJSON', async (t) => { - - await t.test('webTransaction when record_sql is "raw"', async (t) => { - - let queries t.beforeEach(() => { @@ -296,8 +281,6 @@ test('Query Trace Aggregator', async (t) => { }) await t.test('and `simple_compression` is `false`', async (t) => { - - t.beforeEach(() => { queries.config.simple_compression = false }) @@ -315,20 +298,17 @@ test('Query Trace Aggregator', async (t) => { assert.deepStrictEqual(keys, ['backtrace']) assert.deepStrictEqual(params.backtrace, 'fake stack', 'trace should match') - }) }) }) }) await t.test('and `simple_compression` is `true`', async (t) => { - - t.beforeEach(() => { queries.config.simple_compression = true }) - await t.test('should not compress the query parameters', (t) => { + await t.test('should not compress the query parameters', () => { addQuery(queries, 600, '/abc') queries.prepareJSON(function preparedJSON(err, data) { @@ -338,7 +318,6 @@ test('Query Trace Aggregator', async (t) => { assert.deepStrictEqual(keys, ['backtrace']) assert.deepStrictEqual(params.backtrace, 'fake stack', 'trace should match') - }) }) }) @@ -347,7 +326,6 @@ test('Query Trace Aggregator', async (t) => { queries.prepareJSON(function preparedJSON(err, data) { assert.equal(err, null, 'should not error') assert.deepStrictEqual(data, [], 'should return empty array') - }) }) @@ -376,7 +354,6 @@ test('Query Trace Aggregator', async (t) => { assert.deepStrictEqual(keys, ['backtrace']) assert.deepStrictEqual(result.backtrace, 'fake stack', 'trace should match') - }) }) }) @@ -411,7 +388,6 @@ test('Query Trace Aggregator', async (t) => { assert.deepStrictEqual(keys, ['backtrace']) assert.deepStrictEqual(result.backtrace, 'fake stack', 'trace should match') - }) }) }) @@ -472,7 +448,6 @@ test('Query Trace Aggregator', async (t) => { assert.deepStrictEqual(keys, ['backtrace']) assert.deepStrictEqual(result.backtrace, 'fake stack', 'trace should match') - }) } }) @@ -480,8 +455,6 @@ test('Query Trace Aggregator', async (t) => { }) await t.test('webTransaction when record_sql is "obfuscated"', async (t) => { - - await t.test('should record work when empty', () => { const opts = { config: new Config({ @@ -496,7 +469,6 @@ test('Query Trace Aggregator', async (t) => { queries.prepareJSON(function preparedJSON(err, data) { assert.equal(err, null, 'should not error') assert.deepStrictEqual(data, [], 'should return empty array') - }) }) @@ -535,7 +507,6 @@ test('Query Trace Aggregator', async (t) => { assert.deepStrictEqual(keys, ['backtrace']) assert.deepStrictEqual(result.backtrace, 'fake stack', 'trace should match') - }) }) }) @@ -580,7 +551,6 @@ test('Query Trace Aggregator', async (t) => { assert.deepStrictEqual(keys, ['backtrace']) assert.deepStrictEqual(result.backtrace, 'fake stack', 'trace should match') - }) }) }) @@ -647,7 +617,6 @@ test('Query Trace Aggregator', async (t) => { assert.deepStrictEqual(nextKey, ['backtrace']) assert.deepStrictEqual(nextResult.backtrace, 'fake stack', 'trace should match') - }) }) }) @@ -655,8 +624,6 @@ test('Query Trace Aggregator', async (t) => { }) await t.test('backgroundTransaction when record_sql is "raw"', async (t) => { - - await t.test('should record work when empty', () => { const opts = { config: new Config({ @@ -671,7 +638,6 @@ test('Query Trace Aggregator', async (t) => { queries.prepareJSON(function preparedJSON(err, data) { assert.equal(err, null, 'should not error') assert.deepStrictEqual(data, [], 'should return empty array') - }) }) @@ -710,7 +676,6 @@ test('Query Trace Aggregator', async (t) => { assert.deepStrictEqual(keys, ['backtrace']) assert.deepStrictEqual(result.backtrace, 'fake stack', 'trace should match') - }) }) }) @@ -755,7 +720,6 @@ test('Query Trace Aggregator', async (t) => { assert.deepStrictEqual(keys, ['backtrace']) assert.deepStrictEqual(result.backtrace, 'fake stack', 'trace should match') - }) }) }) @@ -825,7 +789,6 @@ test('Query Trace Aggregator', async (t) => { assert.deepStrictEqual(keys, ['backtrace']) assert.deepStrictEqual(result.backtrace, 'fake stack', 'trace should match') - }) } }) @@ -833,8 +796,6 @@ test('Query Trace Aggregator', async (t) => { }) await t.test('background when record_sql is "obfuscated"', async (t) => { - - await t.test('should record work when empty', () => { const opts = { config: new Config({ @@ -849,7 +810,6 @@ test('Query Trace Aggregator', async (t) => { queries.prepareJSON(function preparedJSON(err, data) { assert.equal(err, null, 'should not error') assert.deepStrictEqual(data, [], 'should return empty array') - }) }) @@ -888,7 +848,6 @@ test('Query Trace Aggregator', async (t) => { assert.deepStrictEqual(keys, ['backtrace']) assert.deepStrictEqual(result.backtrace, 'fake stack', 'trace should match') - }) }) }) @@ -933,7 +892,6 @@ test('Query Trace Aggregator', async (t) => { assert.deepStrictEqual(keys, ['backtrace']) assert.deepStrictEqual(result.backtrace, 'fake stack', 'trace should match') - }) }) }) @@ -1000,7 +958,6 @@ test('Query Trace Aggregator', async (t) => { assert.deepStrictEqual(nextKeys, ['backtrace']) assert.deepStrictEqual(nextResult.backtrace, 'fake stack', 'trace should match') - }) }) }) @@ -1009,8 +966,6 @@ test('Query Trace Aggregator', async (t) => { }) await t.test('limiting to n slowest', async (t) => { - - await t.test('should limit to this.config.max_samples', () => { const opts = { config: new Config({ @@ -1036,13 +991,10 @@ test('Query Trace Aggregator', async (t) => { assert.equal(queries.samples.size, 2) assert.ok(queries.samples.has('select*fromfoowherea=?')) assert.ok(queries.samples.has('droptableusers')) - }) }) await t.test('merging query tracers', async (t) => { - - await t.test('should merge queries correctly', () => { const opts = { config: new Config({ @@ -1090,7 +1042,6 @@ test('Query Trace Aggregator', async (t) => { 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') - }) }) }) diff --git a/test/unit/db/trace.test.js b/test/unit/db/trace.test.js index ae3d8c22bd..e6da9d8d5f 100644 --- a/test/unit/db/trace.test.js +++ b/test/unit/db/trace.test.js @@ -10,7 +10,6 @@ const assert = require('node:assert') const helper = require('../../lib/agent_helper') test('SQL trace attributes', async (t) => { - t.beforeEach(function (t) { t.mock.agent = helper.loadMockedAgent({ slow_sql: { @@ -50,7 +49,6 @@ test('SQL trace attributes', async (t) => { assert.equal(attributes['parent.account'], agent.config.account_id) assert.ok(!attributes.parentId) assert.ok(!attributes.parentSpanId) - }) }) }) @@ -71,7 +69,6 @@ test('SQL trace attributes', async (t) => { assert.equal(sample[6], sampleObj.total) assert.equal(sample[7], sampleObj.min) assert.equal(sample[8], sampleObj.max) - }) }) @@ -94,7 +91,6 @@ test('SQL trace attributes', async (t) => { assert.ok(!attributes.parentSpanId) assert.equal(tx.sampled, true) assert.ok(tx.priority > 1) - }) }) }) From 99338dc9a4de2ae82e2adba5d3c7ee971a1704f3 Mon Sep 17 00:00:00 2001 From: Amy Chisholm Date: Tue, 27 Aug 2024 07:26:46 -0700 Subject: [PATCH 3/7] fix: ending tests properly --- test/unit/db/query-parsers/sql.test.js | 4 +- test/unit/db/query-trace-aggregator.test.js | 198 ++++++++++++-------- test/unit/db/trace.test.js | 73 ++++---- 3 files changed, 161 insertions(+), 114 deletions(-) diff --git a/test/unit/db/query-parsers/sql.test.js b/test/unit/db/query-parsers/sql.test.js index 801b4a3e4e..c4dc90db16 100644 --- a/test/unit/db/query-parsers/sql.test.js +++ b/test/unit/db/query-parsers/sql.test.js @@ -153,9 +153,9 @@ test('database query parser', async (t) => { }) if (cat.table === '(subquery)') { - await 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)) { - await 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 { await t.test('should parse the collection as ' + cat.table, function () { assert.equal(ps.collection, cat.table) diff --git a/test/unit/db/query-trace-aggregator.test.js b/test/unit/db/query-trace-aggregator.test.js index c237a9225b..cd9ad32f1c 100644 --- a/test/unit/db/query-trace-aggregator.test.js +++ b/test/unit/db/query-trace-aggregator.test.js @@ -16,32 +16,9 @@ const sinon = require('sinon') const FAKE_STACK = 'Error\nfake stack' test('Query Trace Aggregator', async (t) => { - await t.test('when no queries in payload, _toPayload should exec callback with null data', () => { - 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) - - assert.ok(cbCalledWithNull) - }) - - await t.test('when slow_sql.enabled is false', async (t) => { - await t.test('should not record anything when transaction_tracer.record_sql === "off"', () => { + 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 }, @@ -52,13 +29,44 @@ test('Query Trace Aggregator', async (t) => { 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') - }) + let cbCalledWithNull = false + + const cb = (err, data) => { + if (data === null) { + cbCalledWithNull = true + } + } + + queries._toPayload(cb) + + assert.ok(cbCalledWithNull) + end() + } + ) - await t.test('should treat unknown value in transaction_tracer.record_sql as off', () => { + 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() + } + ) + + 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 }, @@ -73,9 +81,10 @@ test('Query Trace Aggregator', async (t) => { assert.ok('size' in queries.samples) assert.equal(queries.samples.size, 0) assert.deepStrictEqual(segment.getAttributes(), {}, 'should not record sql in trace') + end() }) - await t.test('should record only in trace when record_sql === "obfuscated"', () => { + await t.test('should record only in trace when record_sql === "obfuscated"', (t, end) => { const opts = { config: new Config({ slow_sql: { enabled: false }, @@ -97,9 +106,10 @@ test('Query Trace Aggregator', async (t) => { }, 'should record sql in trace' ) + end() }) - await t.test('should record only in trace when record_sql === "raw"', () => { + await t.test('should record only in trace when record_sql === "raw"', (t, end) => { const opts = { config: new Config({ slow_sql: { enabled: false }, @@ -121,9 +131,10 @@ test('Query Trace Aggregator', async (t) => { }, 'should record sql in trace' ) + end() }) - await t.test('should not record if below threshold', () => { + await t.test('should not record if below threshold', (t, end) => { const opts = { config: new Config({ slow_sql: { enabled: false }, @@ -144,28 +155,33 @@ test('Query Trace Aggregator', async (t) => { }, 'should record sql in trace' ) + end() }) }) await t.test('when slow_sql.enabled is true', async (t) => { - await t.test('should not record anything when transaction_tracer.record_sql === "off"', () => { - 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) + 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) - 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') - }) + 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() + } + ) - await t.test('should treat unknown value in transaction_tracer.record_sql as off', () => { + 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 }, @@ -180,9 +196,10 @@ test('Query Trace Aggregator', async (t) => { assert.ok('size' in queries.samples) assert.equal(queries.samples.size, 0) assert.deepStrictEqual(segment.getAttributes(), {}, 'should not record sql in trace') + end() }) - await 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 }, @@ -208,10 +225,11 @@ test('Query Trace Aggregator', async (t) => { assert.ok(queries.samples.has('select*fromfoowherea=?')) const sample = queries.samples.get('select*fromfoowherea=?') - verifySample(t, sample, 1, segment) + verifySample(sample, 1, segment) + end() }) - await 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,10 +255,11 @@ test('Query Trace Aggregator', async (t) => { assert.ok(queries.samples.has('select*fromfoowherea=?')) const sample = queries.samples.get('select*fromfoowherea=?') - verifySample(t, sample, 1, segment) + verifySample(sample, 1, segment) + end() }) - await t.test('should not record if below threshold', () => { + await t.test('should not record if below threshold', (t, end) => { const opts = { config: new Config({ slow_sql: { enabled: true }, @@ -261,6 +280,7 @@ test('Query Trace Aggregator', async (t) => { }, 'should record sql in trace' ) + end() }) }) @@ -285,7 +305,7 @@ test('Query Trace Aggregator', async (t) => { queries.config.simple_compression = false }) - await t.test('should compress the query parameters', () => { + await t.test('should compress the query parameters', (t, end) => { addQuery(queries, 600, '/abc') queries.prepareJSON(function preparedJSON(err, data) { @@ -298,6 +318,7 @@ test('Query Trace Aggregator', async (t) => { assert.deepStrictEqual(keys, ['backtrace']) assert.deepStrictEqual(params.backtrace, 'fake stack', 'trace should match') + end() }) }) }) @@ -308,7 +329,7 @@ test('Query Trace Aggregator', async (t) => { queries.config.simple_compression = true }) - await t.test('should not compress the query parameters', () => { + await t.test('should not compress the query parameters', (t, end) => { addQuery(queries, 600, '/abc') queries.prepareJSON(function preparedJSON(err, data) { @@ -318,18 +339,20 @@ test('Query Trace Aggregator', async (t) => { assert.deepStrictEqual(keys, ['backtrace']) assert.deepStrictEqual(params.backtrace, 'fake stack', 'trace should match') + end() }) }) }) - await t.test('should record work when empty', () => { + await t.test('should record work when empty', (t, end) => { queries.prepareJSON(function preparedJSON(err, data) { assert.equal(err, null, 'should not error') assert.deepStrictEqual(data, [], 'should return empty array') + end() }) }) - await t.test('should record work with a single query', () => { + await t.test('should record work with a single query', (t, end) => { addQuery(queries, 600, '/abc') queries.prepareJSON(function preparedJSON(err, data) { @@ -354,11 +377,12 @@ test('Query Trace Aggregator', async (t) => { assert.deepStrictEqual(keys, ['backtrace']) assert.deepStrictEqual(result.backtrace, 'fake stack', 'trace should match') + end() }) }) }) - await t.test('should record work with a multiple similar queries', () => { + await t.test('should record work with a multiple similar queries', (t, end) => { addQuery(queries, 600, '/abc') addQuery(queries, 550, '/abc') @@ -388,11 +412,12 @@ test('Query Trace Aggregator', async (t) => { assert.deepStrictEqual(keys, ['backtrace']) assert.deepStrictEqual(result.backtrace, 'fake stack', 'trace should match') + end() }) }) }) - await t.test('should record work with a multiple unique queries', () => { + await t.test('should record work with a multiple unique queries', (t, end) => { addQuery(queries, 600, '/abc') addQuery(queries, 550, '/abc', 'drop table users') @@ -448,6 +473,7 @@ test('Query Trace Aggregator', async (t) => { assert.deepStrictEqual(keys, ['backtrace']) assert.deepStrictEqual(result.backtrace, 'fake stack', 'trace should match') + end() }) } }) @@ -455,7 +481,7 @@ test('Query Trace Aggregator', async (t) => { }) await t.test('webTransaction when record_sql is "obfuscated"', async (t) => { - await t.test('should record work when empty', () => { + await t.test('should record work when empty', (t, end) => { const opts = { config: new Config({ slow_sql: { enabled: true }, @@ -469,10 +495,11 @@ test('Query Trace Aggregator', async (t) => { queries.prepareJSON(function preparedJSON(err, data) { assert.equal(err, null, 'should not error') assert.deepStrictEqual(data, [], 'should return empty array') + end() }) }) - await t.test('should record work with a single query', () => { + await t.test('should record work with a single query', (t, end) => { const opts = { config: new Config({ slow_sql: { enabled: true }, @@ -507,11 +534,12 @@ test('Query Trace Aggregator', async (t) => { assert.deepStrictEqual(keys, ['backtrace']) assert.deepStrictEqual(result.backtrace, 'fake stack', 'trace should match') + end() }) }) }) - await t.test('should record work with a multiple similar queries', () => { + await t.test('should record work with a multiple similar queries', (t, end) => { const opts = { config: new Config({ slow_sql: { enabled: true }, @@ -551,11 +579,12 @@ test('Query Trace Aggregator', async (t) => { assert.deepStrictEqual(keys, ['backtrace']) assert.deepStrictEqual(result.backtrace, 'fake stack', 'trace should match') + end() }) }) }) - await t.test('should record work with a multiple unique queries', () => { + await t.test('should record work with a multiple unique queries', (t, end) => { const opts = { config: new Config({ slow_sql: { enabled: true }, @@ -617,6 +646,7 @@ test('Query Trace Aggregator', async (t) => { assert.deepStrictEqual(nextKey, ['backtrace']) assert.deepStrictEqual(nextResult.backtrace, 'fake stack', 'trace should match') + end() }) }) }) @@ -624,7 +654,7 @@ test('Query Trace Aggregator', async (t) => { }) await t.test('backgroundTransaction when record_sql is "raw"', async (t) => { - await t.test('should record work when empty', () => { + await t.test('should record work when empty', (t, end) => { const opts = { config: new Config({ slow_sql: { enabled: true }, @@ -638,10 +668,11 @@ test('Query Trace Aggregator', async (t) => { queries.prepareJSON(function preparedJSON(err, data) { assert.equal(err, null, 'should not error') assert.deepStrictEqual(data, [], 'should return empty array') + end() }) }) - await t.test('should record work with a single query', () => { + await t.test('should record work with a single query', (t, end) => { const opts = { config: new Config({ slow_sql: { enabled: true }, @@ -676,11 +707,12 @@ test('Query Trace Aggregator', async (t) => { assert.deepStrictEqual(keys, ['backtrace']) assert.deepStrictEqual(result.backtrace, 'fake stack', 'trace should match') + end() }) }) }) - await t.test('should record work with a multiple similar queries', () => { + await t.test('should record work with a multiple similar queries', (t, end) => { const opts = { config: new Config({ slow_sql: { enabled: true }, @@ -720,11 +752,12 @@ test('Query Trace Aggregator', async (t) => { assert.deepStrictEqual(keys, ['backtrace']) assert.deepStrictEqual(result.backtrace, 'fake stack', 'trace should match') + end() }) }) }) - await t.test('should record work with a multiple unique queries', () => { + await t.test('should record work with a multiple unique queries', (t, end) => { const opts = { config: new Config({ slow_sql: { enabled: true }, @@ -789,6 +822,7 @@ test('Query Trace Aggregator', async (t) => { assert.deepStrictEqual(keys, ['backtrace']) assert.deepStrictEqual(result.backtrace, 'fake stack', 'trace should match') + end() }) } }) @@ -796,7 +830,7 @@ test('Query Trace Aggregator', async (t) => { }) await t.test('background when record_sql is "obfuscated"', async (t) => { - await t.test('should record work when empty', () => { + await t.test('should record work when empty', (t, end) => { const opts = { config: new Config({ slow_sql: { enabled: true }, @@ -810,10 +844,11 @@ test('Query Trace Aggregator', async (t) => { queries.prepareJSON(function preparedJSON(err, data) { assert.equal(err, null, 'should not error') assert.deepStrictEqual(data, [], 'should return empty array') + end() }) }) - await t.test('should record work with a single query', () => { + await t.test('should record work with a single query', (t, end) => { const opts = { config: new Config({ slow_sql: { enabled: true }, @@ -848,11 +883,12 @@ test('Query Trace Aggregator', async (t) => { assert.deepStrictEqual(keys, ['backtrace']) assert.deepStrictEqual(result.backtrace, 'fake stack', 'trace should match') + end() }) }) }) - await t.test('should record work with a multiple similar queries', () => { + await t.test('should record work with a multiple similar queries', (t, end) => { const opts = { config: new Config({ slow_sql: { enabled: true }, @@ -892,11 +928,12 @@ test('Query Trace Aggregator', async (t) => { assert.deepStrictEqual(keys, ['backtrace']) assert.deepStrictEqual(result.backtrace, 'fake stack', 'trace should match') + end() }) }) }) - await t.test('should record work with a multiple unique queries', () => { + await t.test('should record work with a multiple unique queries', (t, end) => { const opts = { config: new Config({ slow_sql: { enabled: true }, @@ -958,6 +995,7 @@ test('Query Trace Aggregator', async (t) => { assert.deepStrictEqual(nextKeys, ['backtrace']) assert.deepStrictEqual(nextResult.backtrace, 'fake stack', 'trace should match') + end() }) }) }) @@ -966,7 +1004,7 @@ test('Query Trace Aggregator', async (t) => { }) await t.test('limiting to n slowest', async (t) => { - await t.test('should limit to this.config.max_samples', () => { + await t.test('should limit to this.config.max_samples', (t, end) => { const opts = { config: new Config({ slow_sql: { enabled: true, max_samples: 2 }, @@ -991,11 +1029,12 @@ test('Query Trace Aggregator', async (t) => { assert.equal(queries.samples.size, 2) assert.ok(queries.samples.has('select*fromfoowherea=?')) assert.ok(queries.samples.has('droptableusers')) + end() }) }) await t.test('merging query tracers', async (t) => { - await t.test('should merge queries correctly', () => { + await t.test('should merge queries correctly', (t, end) => { const opts = { config: new Config({ slow_sql: { enabled: true }, @@ -1042,6 +1081,7 @@ test('Query Trace Aggregator', async (t) => { 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() }) }) }) @@ -1055,7 +1095,7 @@ function addQuery(queries, duration, url, query) { return segment } -function verifySample(t, sample, count, 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') @@ -1063,10 +1103,10 @@ function verifySample(t, sample, count, segment) { 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(t, sample.trace, segment) + verifyTrace(sample.trace, segment) } -function verifyTrace(t, trace, segment) { +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') diff --git a/test/unit/db/trace.test.js b/test/unit/db/trace.test.js index e6da9d8d5f..361fa978e4 100644 --- a/test/unit/db/trace.test.js +++ b/test/unit/db/trace.test.js @@ -10,8 +10,9 @@ const assert = require('node:assert') const helper = require('../../lib/agent_helper') test('SQL trace attributes', async (t) => { - t.beforeEach(function (t) { - t.mock.agent = helper.loadMockedAgent({ + t.beforeEach((ctx) => { + ctx.nr = {} + ctx.nr.agent = helper.loadMockedAgent({ slow_sql: { enabled: true }, @@ -22,39 +23,43 @@ test('SQL trace attributes', async (t) => { }) }) - t.afterEach(function (t) { - helper.unloadAgent(t.mock.agent) + t.afterEach((ctx) => { + helper.unloadAgent(ctx.nr.agent) }) - await t.test('should include all DT intrinsics sans parentId and parentSpanId', function (t) { - const { agent } = t.mock - 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) + 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() + }) }) - }) - }) + } + ) - await t.test('should serialize properly using prepareJSONSync', function (t) { - const { agent } = t.mock + 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') @@ -69,11 +74,12 @@ test('SQL trace attributes', async (t) => { assert.equal(sample[6], sampleObj.total) assert.equal(sample[7], sampleObj.min) assert.equal(sample[8], sampleObj.max) + end() }) }) - await t.test('should include the proper priority on transaction end', function (t) { - const { agent } = t.mock + 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 @@ -91,6 +97,7 @@ test('SQL trace attributes', async (t) => { assert.ok(!attributes.parentSpanId) assert.equal(tx.sampled, true) assert.ok(tx.priority > 1) + end() }) }) }) From b14da5313fd6038ccd0fbbf53465635ac73a435e Mon Sep 17 00:00:00 2001 From: Amy Chisholm Date: Tue, 27 Aug 2024 10:28:20 -0700 Subject: [PATCH 4/7] fix: context --- test/unit/db/query-parsers/sql.test.js | 2 +- test/unit/db/query-trace-aggregator.test.js | 21 +++++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/test/unit/db/query-parsers/sql.test.js b/test/unit/db/query-parsers/sql.test.js index c4dc90db16..1c6e738257 100644 --- a/test/unit/db/query-parsers/sql.test.js +++ b/test/unit/db/query-parsers/sql.test.js @@ -158,7 +158,7 @@ test('database query parser', async (t) => { t.todo('should strip database names from collection names as ' + cat.table) } else { await t.test('should parse the collection as ' + cat.table, function () { - assert.equal(ps.collection, cat.table) + assert.equal(ps.collection, cat.table, `should parse the collection as ${cat.table}`) }) } }) diff --git a/test/unit/db/query-trace-aggregator.test.js b/test/unit/db/query-trace-aggregator.test.js index cd9ad32f1c..e23ef76423 100644 --- a/test/unit/db/query-trace-aggregator.test.js +++ b/test/unit/db/query-trace-aggregator.test.js @@ -286,9 +286,7 @@ test('Query Trace Aggregator', async (t) => { await t.test('prepareJSON', async (t) => { await t.test('webTransaction when record_sql is "raw"', async (t) => { - let queries - - t.beforeEach(() => { + t.beforeEach((ctx) => { const opts = { config: new Config({ slow_sql: { enabled: true }, @@ -297,15 +295,17 @@ test('Query Trace Aggregator', async (t) => { method: 'sql_trace_data' } const harvester = { add: sinon.stub() } - queries = new QueryTraceAggregator(opts, {}, harvester) + ctx.nr = {} + ctx.nr.queries = new QueryTraceAggregator(opts, {}, harvester) }) await t.test('and `simple_compression` is `false`', async (t) => { - t.beforeEach(() => { - queries.config.simple_compression = false + t.beforeEach((ctx) => { + ctx.nr.queries.config.simple_compression = false }) await t.test('should compress the query parameters', (t, end) => { + const { queries } = t.nr addQuery(queries, 600, '/abc') queries.prepareJSON(function preparedJSON(err, data) { @@ -325,11 +325,12 @@ test('Query Trace Aggregator', async (t) => { }) await t.test('and `simple_compression` is `true`', async (t) => { - t.beforeEach(() => { - queries.config.simple_compression = true + t.beforeEach((ctx) => { + ctx.nr.queries.config.simple_compression = true }) 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) { @@ -345,6 +346,7 @@ test('Query Trace Aggregator', async (t) => { }) await t.test('should record work when empty', (t, end) => { + const { queries } = t.nr queries.prepareJSON(function preparedJSON(err, data) { assert.equal(err, null, 'should not error') assert.deepStrictEqual(data, [], 'should return empty array') @@ -353,6 +355,7 @@ test('Query Trace Aggregator', async (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) { @@ -383,6 +386,7 @@ test('Query Trace Aggregator', async (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') @@ -418,6 +422,7 @@ test('Query Trace Aggregator', async (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') From 09cee084a78df7dee2deaaca2080b0b349840858 Mon Sep 17 00:00:00 2001 From: Amy Chisholm Date: Tue, 27 Aug 2024 12:27:45 -0700 Subject: [PATCH 5/7] fix: get rid of unnecessary subtest --- test/unit/db/query-parsers/sql.test.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/test/unit/db/query-parsers/sql.test.js b/test/unit/db/query-parsers/sql.test.js index 1c6e738257..46898ba873 100644 --- a/test/unit/db/query-parsers/sql.test.js +++ b/test/unit/db/query-parsers/sql.test.js @@ -156,11 +156,7 @@ test('database query parser', async (t) => { t.todo('should parse subquery collections as ' + cat.table) } else if (/\w+\.\w+/.test(ps.collection)) { t.todo('should strip database names from collection names as ' + cat.table) - } else { - await t.test('should parse the collection as ' + cat.table, function () { - assert.equal(ps.collection, cat.table, `should parse the collection as ${cat.table}`) - }) - } + } }) } }) From 75b49f0df2f447a9f703e12a941d91db66d0b070 Mon Sep 17 00:00:00 2001 From: Amy Chisholm Date: Tue, 27 Aug 2024 12:30:43 -0700 Subject: [PATCH 6/7] fix: linting --- test/unit/db/query-parsers/sql.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/db/query-parsers/sql.test.js b/test/unit/db/query-parsers/sql.test.js index 46898ba873..fba0f3b2d1 100644 --- a/test/unit/db/query-parsers/sql.test.js +++ b/test/unit/db/query-parsers/sql.test.js @@ -156,7 +156,7 @@ test('database query parser', async (t) => { t.todo('should parse subquery collections as ' + cat.table) } else if (/\w+\.\w+/.test(ps.collection)) { t.todo('should strip database names from collection names as ' + cat.table) - } + } }) } }) From bc9e3ef1d6d0a4df98c8924acfe6fdf08903d05f Mon Sep 17 00:00:00 2001 From: Amy Chisholm Date: Tue, 27 Aug 2024 12:44:52 -0700 Subject: [PATCH 7/7] fix: remove t.test in CAT --- test/unit/db/query-parsers/sql.test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/unit/db/query-parsers/sql.test.js b/test/unit/db/query-parsers/sql.test.js index fba0f3b2d1..d9168b5549 100644 --- a/test/unit/db/query-parsers/sql.test.js +++ b/test/unit/db/query-parsers/sql.test.js @@ -148,14 +148,14 @@ test('database query parser', async (t) => { await t.test(clean(cat.input), async (t) => { const ps = parseSql(cat.input) - await t.test('should parse the operation as ' + cat.operation, function () { - assert.equal(ps.operation, cat.operation) - }) + assert.equal(ps.operation, cat.operation, `should parse the operation as ${cat.operation}`) if (cat.table === '(subquery)') { t.todo('should parse subquery collections as ' + cat.table) } else if (/\w+\.\w+/.test(ps.collection)) { t.todo('should strip database names from collection names as ' + cat.table) + } else { + assert.equal(ps.collection, cat.table, `should parse the collection as ${cat.table}`) } }) }