8000 test: deflake test-perf-hooks-timerify-histogram-sync by joyeecheung · Pull Request #60639 · nodejs/node · GitHub
[go: up one dir, main page]

Skip to content
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
7 changes: 7 additions & 0 deletions test/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,12 @@ function expectRequiredTLAError(err) {
}
}

function sleepSync(ms) {
const sab = new SharedArrayBuffer(4);
const i32 = new Int32Array(sab);
Atomics.wait(i32, 0, 0, ms);
}

const common = {
allowGlobals,
buildType,
Expand Down Expand Up @@ -982,6 +988,7 @@ const common = {
skipIfInspectorDisabled,
skipIfSQLiteMissing,
spawnPromisified,
sleepSync,

get enoughTestMem() {
return require('os').totalmem() > 0x70000000; /* 1.75 Gb */
Expand Down
2 changes: 2 additions & 0 deletions test/common/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const {
skipIfInspectorDisabled,
skipIfSQLiteMissing,
spawnPromisified,
sleepSync,
} = common;

const getPort = () => common.PORT;
Expand Down Expand Up @@ -103,4 +104,5 @@ export {
skipIfInspectorDisabled,
skipIfSQLiteMissing,
spawnPromisified,
sleepSync,
};
15 changes: 6 additions & 9 deletions test/parallel/test-perf-hooks-timerify-histogram-sync.mjs
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
// Test that timerify works with histogram option for synchronous functions.

import '../common/index.mjs';
import { sleepSync } from '../common/index.mjs';
import assert from 'assert';
import { createHistogram, timerify } from 'perf_hooks';
import { setTimeout as sleep } from 'timers/promises';

let _deadCode;

const histogram = createHistogram();
const m = (a, b = 1) => {
for (let i = 0; i < 1e3; i++)
_deadCode = i;

const m = () => {
// Deterministic blocking delay (~1 millisecond). The histogram operates on
// nanosecond precision, so this should be sufficient to prevent zero timings.
sleepSync(1);
};
const n = timerify(m, { histogram });
assert.strictEqual(histogram.max, 0);
for (let i = 0; i < 10; i++) {
n();
await sleep(10);
}
assert(_deadCode >= 0);
assert.notStrictEqual(histogram.max, 0);
Loading
0