Skip to content

Commit

Permalink
test(ext/node): compare free memory in log scale (denoland#21475)
Browse files Browse the repository at this point in the history
  • Loading branch information
kt3k committed Dec 6, 2023
1 parent 1ac3706 commit f75eb12
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions cli/tests/unit_node/os_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,13 +290,18 @@ Deno.test({
},
});

// Gets the diff in log_10 scale
function diffLog10(a: number, b: number): number {
return Math.abs(Math.log10(a) - Math.log10(b));
}

Deno.test({
name:
"os.freemem() is equivalent of Deno.systemMemoryInfo().free except on linux",
ignore: Deno.build.os === "linux",
fn() {
const diff = Math.abs(os.freemem() - Deno.systemMemoryInfo().free);
assert(diff < 10_000);
const diff = diffLog10(os.freemem(), Deno.systemMemoryInfo().free);
assert(diff < 1);
},
});

Expand All @@ -305,7 +310,7 @@ Deno.test({
"os.freemem() is equivalent of Deno.systemMemoryInfo().available on linux",
ignore: Deno.build.os !== "linux",
fn() {
const diff = Math.abs(os.freemem() - Deno.systemMemoryInfo().available);
assert(diff < 10_000);
const diff = diffLog10(os.freemem(), Deno.systemMemoryInfo().available);
assert(diff < 1);
},
});

0 comments on commit f75eb12

Please sign in to comment.