Skip to content

Commit ed100a3

Browse files
trentmAlan Storm
authored andcommitted
tests: fix test failure due to os.freemem() behaviour change in node v18 (#2530)
Recent node v18 nightly builds changed the behaviour of os.freemem() on Linux to report "MemAvailable" from /proc/meminfo rather than "MemFree". This broke our tests.
1 parent 244177c commit ed100a3

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

test/metrics/index.test.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const os = require('os')
44

5+
const semver = require('semver')
56
const test = require('tape')
67

78
const Metrics = require('../../lib/metrics')
@@ -73,10 +74,14 @@ test('reports expected metrics', function (t) {
7374
},
7475
'system.memory.actual.free': (value) => {
7576
const free = os.freemem()
76-
if (os.type() === 'Linux') {
77-
// On Linux we use MemAvailable from /proc/meminfo as the value for this metric
78-
// The Node.js API os.freemem() is reporting MemFree from the same file
79-
t.ok(value > free, `is larger than os.freemem() (value: ${value}, free: ${free})`)
77+
if (os.type() === 'Linux' && semver.lt(process.version, '18.0.0-nightly20220107')) {
78+
// On Linux we use "MemAvailable" from /proc/meminfo as the value for
79+
// this metric. In versions of Node.js before v18.0.0, `os.freemem()`
80+
// reports "MemFree" from /proc/meminfo. (This changed in
81+
// v18.0.0-nightly20220107b6b6510187 when node upgraded to libuv
82+
// 1.43.0 to include https://github.com/libuv/libuv/pull/3351.)
83+
t.ok(value > free, `is larger than os.freemem() (value: ${value},
84+
free: ${free})`)
8085
} else {
8186
t.ok(isRoughly(value, free, 0.1), `is close to current free memory (value: ${value}, free: ${free})`)
8287
}

0 commit comments

Comments
 (0)