Skip to content

Commit

Permalink
test: Added test checking for memory leaks.
Browse files Browse the repository at this point in the history
Check for memory leaks on the C++ side by measuring memoryUsage().external, difference is measured
within reason.
  • Loading branch information
voodooattack committed Nov 24, 2018
1 parent 8b788f1 commit 8a2f460
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"typedoc": "typedoc --out docs --target es6 --theme minimal --mode file src",
"lint": "tslint -c tslint.json --project .",
"pretest": "npm run clean && npm run lint && npm run debug-build",
"test": "nyc mocha --ui mocha-typescript test/test_**.ts",
"test": "nyc mocha --expose-gc --ui mocha-typescript test/test_**.ts",
"coverage": "nyc report --reporter=text-lcov | coveralls",
"watch": "mocha-typescript-watch",
"prepare": "npm run lint && tsc",
Expand Down
13 changes: 13 additions & 0 deletions test/test_native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,17 @@ export class TestNative {
assert.isNotEmpty(result);
assert.deepStrictEqual(target, result);
}

@test
'memory leaks'() {
gc();
const memBefore = process.memoryUsage();
for (let i = 0; i < 1024; i++) {
const buffer = serializeNative(new ArrayBuffer(1024));
assert.isAbove(buffer.byteLength, 1024);
}
gc();
const memAfter = process.memoryUsage();
assert.isAtMost(memAfter.external - memBefore.external, 1024);
}
}

0 comments on commit 8a2f460

Please sign in to comment.