summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYoshiya Hinosawa <stibium121@gmail.com>2023-12-07 00:32:39 +0900
committerGitHub <noreply@github.com>2023-12-07 00:32:39 +0900
commitf75eb12801134dadb63327a18ea718af3f06b4eb (patch)
treed1f3af9189ba739a040c54281da2a51de5c1052f
parent1ac370632fdac5b7bbab3a24045692d6b74551dd (diff)
test(ext/node): compare free memory in log scale (#21475)
-rw-r--r--cli/tests/unit_node/os_test.ts13
1 files changed, 9 insertions, 4 deletions
diff --git a/cli/tests/unit_node/os_test.ts b/cli/tests/unit_node/os_test.ts
index 7ce29bea3..d687e9d0e 100644
--- a/cli/tests/unit_node/os_test.ts
+++ b/cli/tests/unit_node/os_test.ts
@@ -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);
},
});
@@ -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);
},
});