Skip to content

Commit

Permalink
Disable the flakey out of memory test
Browse files Browse the repository at this point in the history
The memory consumption has probably gotten better in PR #21, and the
test was always super flakey anyway, and often passes even without
increasing the memory limit.

Just drop that "should error with out of memory" test altogether.
At least the test still has those initialMemoryPages options, so those
code paths get some coverage, even though there's no actual
counterexample to make sure they are improving things.
  • Loading branch information
noppa committed Apr 14, 2024
1 parent 745f180 commit af5b16b
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,32 +129,28 @@ async function testWithTwoFiles() {
}

async function testWithLargeFile() {
const nodeMajorVersion = Number(process.versions.node.split('.')[0]);
if(nodeMajorVersion < 14) {
console.log('Skipping large file test because Node version is < 14');
return;
}

// Takes the first item XML from the test file. I know I know, never parse
// XML with regex, but this is good enough for our test case.
const [partToRepliacate] = xmlValid.match(/<item\b(?:.|[\r\n])*<\/item>/) || [];
let [partToRepliacate] = xmlValid.match(/<item\b(?:.|[\r\n])*<\/item>/) || [];
if (!partToRepliacate) {
throw new Error('Could not find item in test file.');
}
// We are doing tests here that are sensitive to the exact amount of memory
// this test takes. Invoke the GC to try and make the test more predictable/stable.
if (typeof gc === 'function') {
/* globals gc */
gc();
}
// Make a large XML file by repeating the item 300 000 times.
// This will take about 300MB.
const xml = xmlValid.replace(partToRepliacate, partToRepliacate.repeat(300000));
partToRepliacate = '';
let error = 'No error. XML length: '
// Force V8 to eagerly evaluate length of the created string to fight
// any weird optimiziations that it migt be tempted to do.
+ xml.length;

// We are doing tests here that are sensitive to the exact amount of memory
// this test takes. Invoke the GC to try and make the test more predictable/stable.
if (typeof gc === 'function') {
/* globals gc */
gc();
}

try {
await xmllint.validateXML({
xml,
Expand All @@ -163,7 +159,15 @@ async function testWithLargeFile() {
} catch (err) {
error = String(err);
}
assert.match(error, /out of memory/);
if (error) {
console.info('Test without memory limit failed with error:', error);
} else {
console.info('Test passed even without memory limit.');
}

if (typeof gc === 'function') {
gc();
}

// Should pass if we increase the max heap size.
const result = await xmllint.validateXML({
Expand Down

0 comments on commit af5b16b

Please sign in to comment.