Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 22fd621

Browse filesBrowse files
joyeecheungaduh95
authored andcommitted
test: split test-perf-hooks-timerify
This test has been flaky in the CI. It squeezes too many independent test cases into one file, so split it up so that we can mark the persistent flaky test case and leave the unproblematic ones alone. PR-URL: #60568 Refs: #54803 Refs: https://github.com/nodejs/reliability/blob/main/reports/2025-11-03.md Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 5efe4f7 commit 22fd621
Copy full SHA for 22fd621
Expand file treeCollapse file tree

9 files changed

+178
-154
lines changed
Open diff view settings
Collapse file
+25Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Test basic functionality of timerify and PerformanceObserver.
2+
'use strict';
3+
4+
const common = require('../common');
5+
const assert = require('assert');
6+
const { timerify, PerformanceObserver } = require('perf_hooks');
7+
8+
// Verifies that `performance.timerify` is an alias of `perf_hooks.timerify`.
9+
assert.strictEqual(performance.timerify, timerify);
10+
11+
// Intentional non-op. Do not wrap in common.mustCall();
12+
const n = timerify(function noop() {});
13+
14+
const obs = new PerformanceObserver(common.mustCall((list) => {
15+
const entries = list.getEntries();
16+
const entry = entries[0];
17+
assert(entry);
18+
assert.strictEqual(entry.name, 'noop');
19+
assert.strictEqual(entry.entryType, 'function');
20+
assert.strictEqual(typeof entry.duration, 'number');
21+
assert.strictEqual(typeof entry.startTime, 'number');
22+
obs.disconnect();
23+
}));
24+
obs.observe({ entryTypes: ['function'] });
25+
n();
Collapse file
+27Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Test that timerify works with class constructors and creates performance
2+
// entries with the correct name.
3+
4+
'use strict';
5+
6+
const common = require('../common');
7+
const assert = require('assert');
8+
const { timerify, PerformanceObserver } = require('perf_hooks');
9+
10+
class N {}
11+
const n = timerify(N);
12+
13+
const obs = new PerformanceObserver(common.mustCall((list) => {
14+
const entries = list.getEntries();
15+
const entry = entries[0];
16+
assert.strictEqual(entry[0], 1);
17+
assert.strictEqual(entry[1], 'abc');
18+
assert(entry);
19+
assert.strictEqual(entry.name, 'N');
20+
assert.strictEqual(entry.entryType, 'function');
21+
assert.strictEqual(typeof entry.duration, 'number');
22+
assert.strictEqual(typeof entry.startTime, 'number');
23+
obs.disconnect();
24+
}));
25+
obs.observe({ entryTypes: ['function'] });
26+
27+
new n(1, 'abc');
Collapse file
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Test that errors thrown in timerified functions bubble up without creating
2+
// performance timeline entries.
3+
4+
'use strict';
5+
6+
const common = require('../common');
7+
const assert = require('assert');
8+
const { timerify, PerformanceObserver } = require('perf_hooks');
9+
10+
const obs = new PerformanceObserver(common.mustNotCall());
11+
obs.observe({ entryTypes: ['function'] });
12+
const n = timerify(() => {
13+
throw new Error('test');
14+
});
15+
assert.throws(() => n(), /^Error: test$/);
16+
obs.disconnect();
Collapse file
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Test that timerify works with histogram option for asynchronous functions.
2+
3+
import '../common/index.mjs';
4+
import assert from 'assert';
5+
import { createHistogram, timerify } from 'perf_hooks';
6+
import { setTimeout as sleep } from 'timers/promises';
7+
8+
const histogram = createHistogram();
9+
const m = async (a, b = 1) => {
10+
await sleep(10);
11+
};
12+
const n = timerify(m, { histogram });
13+
assert.strictEqual(histogram.max, 0);
14+
for (let i = 0; i < 10; i++) {
15+
await n();
16+
}
17+
assert.notStrictEqual(histogram.max, 0);
Collapse file
+22Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Test that timerify works with histogram option for synchronous functions.
2+
3+
import '../common/index.mjs';
4+
import assert from 'assert';
5+
import { createHistogram, timerify } from 'perf_hooks';
6+
import { setTimeout as sleep } from 'timers/promises';
7+
8+
let _deadCode;
9+
10+
const histogram = createHistogram();
11+
const m = (a, b = 1) => {
12+
for (let i = 0; i < 1e3; i++)
13+
_deadCode = i;
14+
};
15+
const n = timerify(m, { histogram });
16+
assert.strictEqual(histogram.max, 0);
17+
for (let i = 0; i < 10; i++) {
18+
n();
19+
await sleep(10);
20+
}
21+
assert(_deadCode >= 0);
22+
assert.notStrictEqual(histogram.max, 0);
Collapse file
+28Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Test that timerify throws appropriate errors for invalid argument types.
2+
3+
'use strict';
4+
5+
require('../common');
6+
const assert = require('assert');
7+
const { timerify } = require('perf_hooks');
8+
9+
[1, {}, [], null, undefined, Infinity].forEach((input) => {
10+
assert.throws(() => timerify(input),
11+
{
12+
code: 'ERR_INVALID_ARG_TYPE',
13+
name: 'TypeError',
14+
message: /The "fn" argument must be of type function/
15+
});
16+
});
17+
18+
const asyncFunc = async (a, b = 1) => {};
19+
const syncFunc = (a, b = 1) => {};
20+
21+
[1, '', {}, [], false].forEach((histogram) => {
22+
assert.throws(() => timerify(asyncFunc, { histogram }), {
23+
code: 'ERR_INVALID_ARG_TYPE'
24+
});
25+
assert.throws(() => timerify(syncFunc, { histogram }), {
26+
code: 'ERR_INVALID_ARG_TYPE'
27+
});
28+
});
Collapse file
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Test that functions can be wrapped multiple times and verify length and name
2+
// properties are preserved correctly.
3+
4+
'use strict';
5+
6+
require('../common');
7+
const assert = require('assert');
8+
const { timerify } = require('perf_hooks');
9+
10+
const m = (a, b = 1) => {};
11+
const n = timerify(m);
12+
const o = timerify(m);
13+
const p = timerify(n);
14+
assert.notStrictEqual(n, o);
15+
assert.notStrictEqual(n, p);
16+
assert.notStrictEqual(o, p);
17+
assert.strictEqual(n.length, m.length);
18+
assert.strictEqual(n.name, 'timerified m');
19+
assert.strictEqual(p.name, 'timerified timerified m');
Collapse file
+24Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Regression tests for https://github.com/nodejs/node/issues/40623
2+
// Test that timerify preserves return values and class constructor behavior.
3+
4+
'use strict';
5+
6+
require('../common');
7+
const assert = require('assert');
8+
const { timerify } = require('perf_hooks');
9+
10+
assert.strictEqual(timerify(function func() {
11+
return 1;
12+
})(), 1);
13+
assert.strictEqual(timerify(function() {
14+
return 1;
15+
})(), 1);
16+
assert.strictEqual(timerify(() => {
17+
return 1;
18+
})(), 1);
19+
class C {}
20+
const wrap = timerify(C);
21+
assert.ok(new wrap() instanceof C);
22+
assert.throws(() => wrap(), {
23+
name: 'TypeError',
24+
});
Collapse file

‎test/parallel/test-perf-hooks-timerify.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-perf-hooks-timerify.js
-154Lines changed: 0 additions & 154 deletions
This file was deleted.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.