Skip to content

Commit

Permalink
test: Fixed recordMiddlewawre benchmark test (#2338)
Browse files Browse the repository at this point in the history
bizob2828 authored Jul 9, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 7069335 commit fb55ac7
Showing 5 changed files with 40 additions and 23 deletions.
41 changes: 27 additions & 14 deletions test/benchmark/datastore-shim/shared.js
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@

const benchmark = require('../../lib/benchmark')
const DatastoreShim = require('../../../lib/shim/datastore-shim')
const { OperationSpec, QuerySpec } = require('../../../lib/shim/specs')

const TestDatastore = require('./test-datastore')

@@ -27,20 +28,32 @@ function getTestDatastore(agent, instrumented) {
}
})

shim.recordOperation(testDatastore, 'testOp', {
name: 'testOp',
callback: shim.LAST
})

shim.recordQuery(testDatastore, 'testQuery', {
name: 'testQuery',
callback: shim.LAST
})

shim.recordBatchQuery(testDatastore, 'testBatch', {
name: 'testBatch',
callback: shim.LAST
})
shim.recordOperation(
testDatastore,
'testOp',
new OperationSpec({
name: 'testOp',
callback: shim.LAST
})
)

shim.recordQuery(
testDatastore,
'testQuery',
new QuerySpec({
name: 'testQuery',
callback: shim.LAST
})
)

shim.recordBatchQuery(
testDatastore,
'testBatch',
new QuerySpec({
name: 'testBatch',
callback: shim.LAST
})
)
}
return testDatastore
}
3 changes: 2 additions & 1 deletion test/benchmark/shim/record.bench.js
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@
const benchmark = require('../../lib/benchmark')
const helper = require('../../lib/agent_helper')
const Shim = require('../../../lib/shim/shim')
const { RecorderSpec } = require('../../../lib/shim/specs')

const agent = helper.loadMockedAgent()
const contextManager = helper.getContextManager()
@@ -34,7 +35,7 @@ suite.add({
})

const wrapped = shim.record(getTest(), 'func', function () {
return { name: 'foo', callback: shim.LAST }
return new RecorderSpec({ name: 'foo', callback: shim.LAST })
})

suite.add({
3 changes: 2 additions & 1 deletion test/benchmark/shim/row-callbacks.bench.js
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ const benchmark = require('../../lib/benchmark')
const EventEmitter = require('events').EventEmitter
const helper = require('../../lib/agent_helper')
const Shim = require('../../../lib/shim/shim')
const { RecorderSpec } = require('../../../lib/shim/specs')

const CYCLES = 1000

@@ -28,7 +29,7 @@ const test = {
}
}
shim.record(test, 'streamWrapped', function () {
return { name: 'streamer', stream: 'foo' }
return new RecorderSpec({ name: 'streamer', stream: 'foo' })
})

suite.add({
3 changes: 2 additions & 1 deletion test/benchmark/shim/segments.bench.js
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@

'use strict'

const { RecorderSpec } = require('../../../lib/shim/specs')
const helper = require('../../lib/agent_helper')
const shared = require('./shared')

@@ -30,7 +31,7 @@ suite.add({
fn: function () {
const test = shared.getTest()
shim.record(test, 'func', function (shim, fn, name, args) {
return { name: name, args: args }
return new RecorderSpec({ name: name, args: args })
})
return test
}
13 changes: 7 additions & 6 deletions test/benchmark/webframework-shim/recordMiddleware.bench.js
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@ const symbols = require('../../../lib/symbols')
const agent = helper.loadMockedAgent()
const contextManager = helper.getContextManager()
const shim = new WebFrameworkShim(agent, 'test-module', './')
const { MiddlewareSpec } = require('../../../lib/shim/specs')
const suite = benchmark.createBenchmark({ name: 'recordMiddleware' })

const transaction = helper.runInTransaction(agent, function (tx) {
@@ -93,26 +94,26 @@ function getReqd() {
}

function implicitSpec() {
return {}
return new MiddlewareSpec({})
}

function partialSpec() {
return {
return new MiddlewareSpec({
next: shim.LAST,
req: shim.FIRST
}
})
}

function explicitSpec() {
return {
return new MiddlewareSpec({
req: shim.FIRST,
res: shim.SECOND,
next: shim.LAST,
name: 'funcy_name',
params: function (shim, fn, name, args) {
return args[0].params
}
}
})
}

function randomSpec() {
@@ -144,7 +145,7 @@ function noop() {}

function preOptRecordMiddleware() {
for (let i = 0; i < 1000; ++i) {
let m = randomRecord(randomSpec)
let m = randomRecord(randomSpec())
m = typeof m === 'function' ? m : m.func
for (let j = 0; j < 100; ++j) {
m(getReqd(), {}, noop)

0 comments on commit fb55ac7

Please sign in to comment.