Skip to content

Commit e29269b

Browse files
authored
tests: fix test failure due to os.freemem() behaviour change in node v16.14.0 (#2570)
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
1 parent f346a75 commit e29269b

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

test/metrics/index.test.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,18 @@ test('reports expected metrics', function (t) {
7676
const free = os.freemem()
7777
if (os.type() === 'Linux' &&
7878
semver.lt(process.version, '18.0.0-nightly20220107') &&
79-
semver.lt(process.version, '17.4.0')) {
79+
semver.lt(process.version, '17.4.0') &&
80+
semver.lt(process.version, '16.14.0')) {
8081
// On Linux we use "MemAvailable" from /proc/meminfo as the value for
81-
// this metric. In versions of Node.js before v17.4.0 and v18.0.0,
82-
// `os.freemem()` reports "MemFree" from /proc/meminfo. (This changed
83-
// in v17.4.0 and v18.0.0-nightly20220107b6b6510187 when node upgraded
84-
// to libuv 1.43.0 to include https://github.com/libuv/libuv/pull/3351.)
82+
// this metric. In older versions of Node.js on Linus, `os.freemem()`
83+
// reports "MemFree" from /proc/meminfo. This changed when dev-lines
84+
// of node upgraded to libuv 1.43.0 to include
85+
// https://github.com/libuv/libuv/pull/3351.
8586
t.ok(value > free, `is larger than os.freemem() (value: ${value},
8687
free: ${free})`)
8788
} else {
89+
// `isRoughly` because we are comparing free memory queried at
90+
// near but separate times, so we expect some variance.
8891
t.ok(isRoughly(value, free, 0.1), `is close to current free memory (value: ${value}, free: ${free})`)
8992
}
9093
},

0 commit comments

Comments
 (0)