Skip to content

Commit

Permalink
test(ReplaySubject): add memory leak test for ReplaySubject
Browse files Browse the repository at this point in the history
Add test for ReplaySubject that checks a memory leak should not happen when feeding in events to the
ReplaySubject synchronously, without any subscriber involved.

Related to issue ReactiveX#578.
  • Loading branch information
staltz committed Nov 17, 2015
1 parent 54a99a3 commit 0c3df26
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@
"build_closure": "java -jar ./node_modules/google-closure-compiler/compiler.jar ./dist/global/Rx.js --create_source_map ./dist/global/Rx.min.js.map --js_output_file ./dist/global/Rx.min.js",
"build_global": "rm -rf dist/global && mkdir \"dist/global\" && browserify src/Rx.global.js --outfile dist/global/Rx.js && npm run build_closure",
"build_perf": "npm run build_cjs && npm run build_global && webdriver-manager update && npm run perf",
"build_test": "rm -rf dist/ && npm run lint && npm run build_cjs && jasmine",
"build_test": "rm -rf dist/ && npm run lint && npm run build_cjs && npm run jasmine",
"build_cover": "rm -rf dist/ && npm run lint && npm run build_cjs && npm run cover",
"build_docs": "./docgen.sh",
"lint_perf": "eslint perf/ --fix",
"lint_spec": "eslint spec/**/*.js --fix",
"lint_src": "tslint -c .tslintrc src/*.ts src/**/*.ts src/**/**/*.ts",
"lint": "npm run lint_src && npm run lint_spec && npm run lint_perf",
"cover": "istanbul cover -x \"*-spec.js index.js *-helper.js spec/helpers/*\" ./node_modules/jasmine/bin/jasmine.js && npm run cover_remapping",
"cover": "istanbul cover -x \"*-spec.js index.js *-helper.js spec/helpers/*\" npm run jasmine && npm run cover_remapping",
"cover_remapping": "remap-istanbul -i coverage/coverage.json -o coverage/coverage-remapped.json && remap-istanbul -i coverage/coverage.json -o coverage/coverage-remapped.lcov -t lcovonly && remap-istanbul -i coverage/coverage.json -o coverage/coverage-remapped -t html",
"test": "jasmine && markdown-doctest",
"jasmine": "node --expose-gc ./node_modules/jasmine/bin/jasmine.js",
"test": "npm run jasmine && markdown-doctest",
"watch": "watch \"echo triggering build && npm run build_test && echo build completed\" src -d -u -w=15",
"perf": "protractor protractor.conf.js",
"perf_micro": "node ./perf/micro/index.js",
Expand Down
17 changes: 17 additions & 0 deletions spec/subjects/replay-subject-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,21 @@ describe('ReplaySubject', function () {
expectObservable(subscriber1).toBe(expected1);
});
});

it('should not leak memory if events are fed synchronously indefinitely', function () {
var replaySubject = new ReplaySubject(1);
var event = 'foobar'.repeat(10000).split(''); // memory-hungry object

replaySubject.next(event.slice());
global.gc();
var memoryBefore = process.memoryUsage().heapUsed;

for (var i = 0; i < 100; i++) {
replaySubject.next(event.slice());
}
global.gc();
var memoryAfter = process.memoryUsage().heapUsed;

expect(memoryAfter / memoryBefore).toBeLessThan(1.2);
});
});

0 comments on commit 0c3df26

Please sign in to comment.