From fd129d31a4814c0628d9eed190ea12230f282a61 Mon Sep 17 00:00:00 2001 From: Trent Mick Date: Thu, 10 Feb 2022 10:26:36 -0800 Subject: [PATCH] tests: fix test failure due to os.freemem() behaviour change in node v16.14.0 The update to libuv 1.43.0 changed the behaviour of os.freemem() on Linux to report "MemAvailable" from /proc/meminfo rather than "MemFree". Refs: #2530, #2540 --- test/metrics/index.test.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/test/metrics/index.test.js b/test/metrics/index.test.js index 62cc795e49..c2560d40e2 100644 --- a/test/metrics/index.test.js +++ b/test/metrics/index.test.js @@ -76,15 +76,18 @@ test('reports expected metrics', function (t) { const free = os.freemem() if (os.type() === 'Linux' && semver.lt(process.version, '18.0.0-nightly20220107') && - semver.lt(process.version, '17.4.0')) { + semver.lt(process.version, '17.4.0') && + semver.lt(process.version, '16.14.0')) { // On Linux we use "MemAvailable" from /proc/meminfo as the value for - // this metric. In versions of Node.js before v17.4.0 and v18.0.0, - // `os.freemem()` reports "MemFree" from /proc/meminfo. (This changed - // in v17.4.0 and v18.0.0-nightly20220107b6b6510187 when node upgraded - // to libuv 1.43.0 to include https://github.com/libuv/libuv/pull/3351.) + // this metric. In older versions of Node.js on Linus, `os.freemem()` + // reports "MemFree" from /proc/meminfo. This changed when dev-lines + // of node upgraded to libuv 1.43.0 to include + // https://github.com/libuv/libuv/pull/3351. t.ok(value > free, `is larger than os.freemem() (value: ${value}, free: ${free})`) } else { + // `isRoughly` because we are comparing free memory queried at + // near but separate times, so we expect some variance. t.ok(isRoughly(value, free, 0.1), `is close to current free memory (value: ${value}, free: ${free})`) } },