Skip to content

Commit fb55ac7

Browse files
authoredJul 9, 2024··
test: Fixed recordMiddlewawre benchmark test (#2338)
1 parent 7069335 commit fb55ac7

File tree

5 files changed

+40
-23
lines changed

5 files changed

+40
-23
lines changed
 

‎test/benchmark/datastore-shim/shared.js

+27-14
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

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

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

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

30-
shim.recordOperation(testDatastore, 'testOp', {
31-
name: 'testOp',
32-
callback: shim.LAST
33-
})
34-
35-
shim.recordQuery(testDatastore, 'testQuery', {
36-
name: 'testQuery',
37-
callback: shim.LAST
38-
})
39-
40-
shim.recordBatchQuery(testDatastore, 'testBatch', {
41-
name: 'testBatch',
42-
callback: shim.LAST
43-
})
31+
shim.recordOperation(
32+
testDatastore,
33+
'testOp',
34+
new OperationSpec({
35+
name: 'testOp',
36+
callback: shim.LAST
37+
})
38+
)
39+
40+
shim.recordQuery(
41+
testDatastore,
42+
'testQuery',
43+
new QuerySpec({
44+
name: 'testQuery',
45+
callback: shim.LAST
46+
})
47+
)
48+
49+
shim.recordBatchQuery(
50+
testDatastore,
51+
'testBatch',
52+
new QuerySpec({
53+
name: 'testBatch',
54+
callback: shim.LAST
55+
})
56+
)
4457
}
4558
return testDatastore
4659
}

‎test/benchmark/shim/record.bench.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
const benchmark = require('../../lib/benchmark')
99
const helper = require('../../lib/agent_helper')
1010
const Shim = require('../../../lib/shim/shim')
11+
const { RecorderSpec } = require('../../../lib/shim/specs')
1112

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

3637
const wrapped = shim.record(getTest(), 'func', function () {
37-
return { name: 'foo', callback: shim.LAST }
38+
return new RecorderSpec({ name: 'foo', callback: shim.LAST })
3839
})
3940

4041
suite.add({

‎test/benchmark/shim/row-callbacks.bench.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const benchmark = require('../../lib/benchmark')
99
const EventEmitter = require('events').EventEmitter
1010
const helper = require('../../lib/agent_helper')
1111
const Shim = require('../../../lib/shim/shim')
12+
const { RecorderSpec } = require('../../../lib/shim/specs')
1213

1314
const CYCLES = 1000
1415

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

3435
suite.add({

‎test/benchmark/shim/segments.bench.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
'use strict'
77

8+
const { RecorderSpec } = require('../../../lib/shim/specs')
89
const helper = require('../../lib/agent_helper')
910
const shared = require('./shared')
1011

@@ -30,7 +31,7 @@ suite.add({
3031
fn: function () {
3132
const test = shared.getTest()
3233
shim.record(test, 'func', function (shim, fn, name, args) {
33-
return { name: name, args: args }
34+
return new RecorderSpec({ name: name, args: args })
3435
})
3536
return test
3637
}

‎test/benchmark/webframework-shim/recordMiddleware.bench.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const symbols = require('../../../lib/symbols')
1313
const agent = helper.loadMockedAgent()
1414
const contextManager = helper.getContextManager()
1515
const shim = new WebFrameworkShim(agent, 'test-module', './')
16+
const { MiddlewareSpec } = require('../../../lib/shim/specs')
1617
const suite = benchmark.createBenchmark({ name: 'recordMiddleware' })
1718

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

9596
function implicitSpec() {
96-
return {}
97+
return new MiddlewareSpec({})
9798
}
9899

99100
function partialSpec() {
100-
return {
101+
return new MiddlewareSpec({
101102
next: shim.LAST,
102103
req: shim.FIRST
103-
}
104+
})
104105
}
105106

106107
function explicitSpec() {
107-
return {
108+
return new MiddlewareSpec({
108109
req: shim.FIRST,
109110
res: shim.SECOND,
110111
next: shim.LAST,
111112
name: 'funcy_name',
112113
params: function (shim, fn, name, args) {
113114
return args[0].params
114115
}
115-
}
116+
})
116117
}
117118

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

145146
function preOptRecordMiddleware() {
146147
for (let i = 0; i < 1000; ++i) {
147-
let m = randomRecord(randomSpec)
148+
let m = randomRecord(randomSpec())
148149
m = typeof m === 'function' ? m : m.func
149150
for (let j = 0; j < 100; ++j) {
150151
m(getReqd(), {}, noop)

0 commit comments

Comments
 (0)
Please sign in to comment.