Skip to content

Commit 22fd621

Browse 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

9 files changed

Lines changed: 178 additions & 154 deletions
Lines 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+
constcommon=require('../common');
5+
constassert=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+
constn=timerify(functionnoop(){});
13+
14+
constobs=newPerformanceObserver(common.mustCall((list)=>{
15+
constentries=list.getEntries();
16+
constentry=entries[0];
17+
assert(entry);
18+
assert.strictEqual(entry.name,'noop');
19+
assert.strictEqual(entry.entryType,'function');
20+
assert.strictEqual(typeofentry.duration,'number');
21+
assert.strictEqual(typeofentry.startTime,'number');
22+
obs.disconnect();
23+
}));
24+
obs.observe({entryTypes: ['function']});
25+
n();
Lines 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+
constcommon=require('../common');
7+
constassert=require('assert');
8+
const{ timerify, PerformanceObserver }=require('perf_hooks');
9+
10+
classN{}
11+
constn=timerify(N);
12+
13+
constobs=newPerformanceObserver(common.mustCall((list)=>{
14+
constentries=list.getEntries();
15+
constentry=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(typeofentry.duration,'number');
22+
assert.strictEqual(typeofentry.startTime,'number');
23+
obs.disconnect();
24+
}));
25+
obs.observe({entryTypes: ['function']});
26+
27+
newn(1,'abc');
Lines 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+
constcommon=require('../common');
7+
constassert=require('assert');
8+
const{ timerify, PerformanceObserver }=require('perf_hooks');
9+
10+
constobs=newPerformanceObserver(common.mustNotCall());
11+
obs.observe({entryTypes: ['function']});
12+
constn=timerify(()=>{
13+
thrownewError('test');
14+
});
15+
assert.throws(()=>n(),/^Error:test$/);
16+
obs.disconnect();
Lines 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+
importassertfrom'assert';
5+
import{createHistogram,timerify}from'perf_hooks';
6+
import{setTimeoutassleep}from'timers/promises';
7+
8+
consthistogram=createHistogram();
9+
constm=async(a,b=1)=>{
10+
awaitsleep(10);
11+
};
12+
constn=timerify(m,{ histogram });
13+
assert.strictEqual(histogram.max,0);
14+
for(leti=0;i<10;i++){
15+
awaitn();
16+
}
17+
assert.notStrictEqual(histogram.max,0);
Lines 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+
importassertfrom'assert';
5+
import{createHistogram,timerify}from'perf_hooks';
6+
import{setTimeoutassleep}from'timers/promises';
7+
8+
let_deadCode;
9+
10+
consthistogram=createHistogram();
11+
constm=(a,b=1)=>{
12+
for(leti=0;i<1e3;i++)
13+
_deadCode=i;
14+
};
15+
constn=timerify(m,{ histogram });
16+
assert.strictEqual(histogram.max,0);
17+
for(leti=0;i<10;i++){
18+
n();
19+
awaitsleep(10);
20+
}
21+
assert(_deadCode>=0);
22+
assert.notStrictEqual(histogram.max,0);
Lines 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+
constassert=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"argumentmustbeoftypefunction/
15+
});
16+
});
17+
18+
constasyncFunc=async(a,b=1)=>{};
19+
constsyncFunc=(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+
});
Lines 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+
constassert=require('assert');
8+
const{ timerify }=require('perf_hooks');
9+
10+
constm=(a,b=1)=>{};
11+
constn=timerify(m);
12+
consto=timerify(m);
13+
constp=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');
Lines 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+
constassert=require('assert');
8+
const{ timerify }=require('perf_hooks');
9+
10+
assert.strictEqual(timerify(functionfunc(){
11+
return1;
12+
})(),1);
13+
assert.strictEqual(timerify(function(){
14+
return1;
15+
})(),1);
16+
assert.strictEqual(timerify(()=>{
17+
return1;
18+
})(),1);
19+
classC{}
20+
constwrap=timerify(C);
21+
assert.ok(newwrap()instanceofC);
22+
assert.throws(()=>wrap(),{
23+
name: 'TypeError',
24+
});

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

Lines changed: 0 additions & 154 deletions
This file was deleted.

0 commit comments

Comments
 (0)