Skip to content

Commit cc4fbd7

Browse files
committed
Test useCPED when on Node 24
1 parent 6e06bc5 commit cc4fbd7

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

ts/test/test-time-profiler.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,15 @@ import {hrtime} from 'process';
2323
import {Label, Profile} from 'pprof-format';
2424
import {AssertionError} from 'assert';
2525
import {GenerateTimeLabelsArgs, LabelSet} from '../src/v8-types';
26+
import {satisfies} from 'semver';
27+
import { AsyncLocalStorage } from 'async_hooks';
2628

2729
const assert = require('assert');
2830

31+
const useCPED =
32+
satisfies(process.versions.node, '>=24.0.0') &&
33+
!process.execArgv.includes('--no-async-context-frame');
34+
2935
const PROFILE_OPTIONS = {
3036
durationMillis: 500,
3137
intervalMicros: 1000,
@@ -49,7 +55,14 @@ describe('Time Profiler', () => {
4955
durationMillis: PROFILE_OPTIONS.durationMillis,
5056
withContexts: true,
5157
lineNumbers: false,
58+
useCPED,
5259
});
60+
let als;
61+
if (useCPED) {
62+
// Ensure an async context frame is created to hold the profiler context.
63+
als = new AsyncLocalStorage();
64+
als.enterWith(1);
65+
}
5366
const initialContext: {[key: string]: string} = {};
5467
time.setContext(initialContext);
5568
const kSampleCount = time.constants.kSampleCount;
@@ -102,7 +115,14 @@ describe('Time Profiler', () => {
102115
durationMillis: PROFILE_OPTIONS.durationMillis,
103116
withContexts: true,
104117
lineNumbers: false,
118+
useCPED,
105119
});
120+
let als;
121+
if (useCPED) {
122+
// Ensure an async context frame is created to hold the profiler context.
123+
als = new AsyncLocalStorage();
124+
als.enterWith(1);
125+
}
106126
// By repeating the test few times, we also exercise the profiler
107127
// start-stop overlap behavior.
108128
const repeats = 3;

0 commit comments

Comments
 (0)