Skip to content

Commit

Permalink
tests: fix test failure due to os.freemem() behaviour change in node …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
trentm committed Feb 10, 2022
1 parent f346a75 commit fd129d3
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions test/metrics/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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})`)
}
},
Expand Down

0 comments on commit fd129d3

Please sign in to comment.