Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Refactored benchmark tests to complete async functions #2334

Merged
merged 3 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions test/benchmark/datastore-shim/test-datastore.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,24 @@

class TestDatastore {
testOp(cb) {
setImmediate(cb)
if (typeof cb === 'function') {
return setImmediate(cb)
}
return cb || 'testOp'
}

testQuery(query, cb) {
setImmediate(cb)
if (typeof cb === 'function') {
return setImmediate(cb)
}
return cb || 'testQuery'
}

testBatch(query, cb) {
setImmediate(cb)
if (typeof cb === 'function') {
return setImmediate(cb)
}
return cb || 'testBatch'
}
}

Expand Down
54 changes: 46 additions & 8 deletions test/benchmark/promises/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ const tests = [
promises.push(prom.then(function first() {}))
promises.push(prom.then(function second() {}))
}
Promise.all(promises).then(cb)
Promise.all(promises).then(() => {
if (typeof cb === 'function') {
return cb()
}
return cb || true
})
}
},

Expand All @@ -37,7 +42,12 @@ const tests = [
for (let i = 0; i < NUM_PROMISES; ++i) {
prom = prom.then(function () {})
}
prom.then(cb)
prom.then(() => {
if (typeof cb === 'function') {
return cb()
}
return cb || true
})
}
},

Expand All @@ -47,7 +57,12 @@ const tests = [
for (let i = 0; i < NUM_PROMISES / 2; ++i) {
prom = prom.then(function () {}).catch(function () {})
}
prom.then(cb)
prom.then(() => {
if (typeof cb === 'function') {
return cb()
}
return cb || true
})
}
},

Expand All @@ -57,7 +72,14 @@ const tests = [
for (let i = 0; i < NUM_PROMISES - 1; ++i) {
prom = prom.then(function () {})
}
prom.catch(function () {}).then(cb)
prom
.catch(function () {})
.then(() => {
if (typeof cb === 'function') {
return cb()
}
return cb || true
})
}
},

Expand All @@ -69,7 +91,10 @@ const tests = [
res()
})
}
cb()
if (typeof cb === 'function') {
return cb()
}
return cb || true
}
},

Expand All @@ -87,7 +112,12 @@ const tests = [
})
)
}
Promise.all(promises).then(cb)
Promise.all(promises).then(() => {
if (typeof cb === 'function') {
return cb()
}
return cb || true
})
}
},

Expand All @@ -101,7 +131,12 @@ const tests = [
})
})
}
prom.then(cb)
prom.then(() => {
if (typeof cb === 'function') {
return cb()
}
return cb || true
})
}
},

Expand All @@ -110,7 +145,10 @@ const tests = [
new Promise(function () {
throw new Error('Whoops!')
}).catch(() => {})
cb()
if (typeof cb === 'function') {
return cb()
}
return cb || true
}
}
]
Expand Down
5 changes: 1 addition & 4 deletions test/lib/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@ class Benchmark {
const prevCpu = process.cpuUsage()
const testFn = test.fn

if (test.async) {
return testFn(agent, () => after(test, next, executeCb, prevCpu))
}
await testFn(agent)
return after(test, next, executeCb, prevCpu)
}
Expand Down Expand Up @@ -108,7 +105,7 @@ class Benchmark {
if (idx >= suite.tests.length) {
return true
}
return initiator(initiator, suite.tests[idx], idx)
return await initiator(initiator, suite.tests[idx], idx)
}

const afterTestRuns = (initiator, test, samples, idx) => {
Expand Down
Loading