Skip to content

Commit

Permalink
Update memory test to improve stability and add note for future enhan…
Browse files Browse the repository at this point in the history
…cements
  • Loading branch information
mceachen committed Dec 17, 2024
1 parent 915e058 commit bc90999
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/memory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import { validateHidden } from "./test-utils/hidden-tests.js";
import { tmpDirNotHidden } from "./test-utils/platform.js";
import { fmtBytes, MiB } from "./units.js";

// THIS IS ALL A HORRIBLE HACK. THIS "test" SHOULD BE REPLACED WITH AN ACTUAL
// MEMORY LEAK TESTER (like with valgrind). PULL REQUESTS ARE WELCOME.

// Enable garbage collection access
declare const global: {
gc: () => void;
Expand All @@ -32,6 +35,7 @@ describeMemory("Memory Tests", () => {

// Helper to get memory usage after GC
async function getMemoryUsage(): Promise<number> {
// Give things a bit to fall out of scope. delay(1) should be enough.
await delay(100);
global.gc();
await delay(100);
Expand All @@ -41,7 +45,7 @@ describeMemory("Memory Tests", () => {
// Helper to check if memory usage is stable
async function checkMemoryUsage(
operation: () => Promise<unknown>,
errorMarginBytes: number = 5 * MiB,
errorMarginBytes: number = 6.5 * MiB, // Alpine docker had a 5MB variance
) {
// warm up memory consumption:
await operation();
Expand Down

0 comments on commit bc90999

Please sign in to comment.