Skip to content

Commit 81e05a4

Browse files
committed
test: Correct maxRSS units for Node 18 on macOS
Node 18 on macOS reports resourceUsage().maxRSS in bytes, so the RSS growth check read about 14 MB as 14 GB.
1 parent 4f6224c commit 81e05a4

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

‎test/bounded-harness.mjs‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ import { registerThread } from '@sentry/node-native-stacktrace';
1414

1515
export const MAX_BLOCK_MS = 10000;
1616

17+
// Node 18 on macOS reports maxRSS in bytes instead of kilobytes.
18+
const MAX_RSS_DIVISOR =
19+
process.platform === 'darwin' && Number(process.versions.node.split('.')[0]) < 20 ? 1024 : 1;
20+
21+
function maxRssKb() {
22+
return process.resourceUsage().maxRSS / MAX_RSS_DIVISOR;
23+
}
24+
1725
/**
1826
* Busy-waits inside the current AsyncLocalStorage store until flags[1] is set.
1927
* Sets flags[0] first, which starts the capture in bounded-watchdog.mjs.
@@ -66,7 +74,7 @@ export function captureWhileBlocked({ store, stateLookup, beforeBlock, afterBloc
6674
// flags[0]: main thread is blocked inside the store, flags[1]: capture is done
6775
const flags = new Int32Array(new SharedArrayBuffer(8));
6876
const watchdog = startWatchdog(flags);
69-
const maxRssBeforeKb = process.resourceUsage().maxRSS;
77+
const maxRssBeforeKb = maxRssKb();
7078

7179
let setupError = null;
7280
try {
@@ -87,7 +95,7 @@ export function captureWhileBlocked({ store, stateLookup, beforeBlock, afterBloc
8795
afterBlock?.();
8896

8997
watchdog.once('message', result => {
90-
const maxRssGrowthMb = (process.resourceUsage().maxRSS - maxRssBeforeKb) / 1024;
98+
const maxRssGrowthMb = (maxRssKb() - maxRssBeforeKb) / 1024;
9199
printResult({ ...result, appError, setupError, timedOut, maxRssGrowthMb, ...report?.() });
92100
});
93101
}

0 commit comments

Comments
 (0)