Skip to content

Commit

Permalink
Fix: memory leak in test? automatically unsubscribe from all subscribe (
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheeguerin authored Feb 21, 2018
1 parent 60f0df6 commit f966e93
Show file tree
Hide file tree
Showing 5 changed files with 176 additions and 139 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ addons:
apt:
packages:
- libgnome-keyring-dev
- icnsutils
# - openjpeg-tools # or libopenjp2-tools
- graphicsmagick
- libreadline6
- xz-utils
Expand Down
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"css-loader": "~0.28.9",
"devtron": "^1.4.0",
"electron": "~1.8.2",
"electron-builder": "~19.56.0",
"electron-builder": "~20.0.7",
"extract-text-webpack-plugin": "~3.0.2",
"file-loader": "~1.1.5",
"html-webpack-plugin": "^2.28.0",
Expand Down Expand Up @@ -117,18 +117,18 @@
"yesno": "~0.0.1"
},
"dependencies": {
"@angular/animations": "5.2.1",
"@angular/animations": "5.2.5",
"@angular/cdk": "5.1.0",
"@angular/common": "5.2.1",
"@angular/compiler": "5.2.1",
"@angular/compiler-cli": "5.2.1",
"@angular/core": "5.2.1",
"@angular/forms": "5.2.1",
"@angular/http": "5.2.1",
"@angular/common": "5.2.5",
"@angular/compiler": "5.2.5",
"@angular/compiler-cli": "5.2.5",
"@angular/core": "5.2.5",
"@angular/forms": "5.2.5",
"@angular/http": "5.2.5",
"@angular/material": "5.1.0",
"@angular/platform-browser": "5.2.1",
"@angular/platform-browser-dynamic": "5.2.1",
"@angular/router": "5.2.1",
"@angular/platform-browser": "5.2.5",
"@angular/platform-browser-dynamic": "5.2.5",
"@angular/router": "5.2.5",
"@tweenjs/tween.js": "~17.1.1",
"azure-batch": "git://github.com/amarzavery/azure-batch-ts#fae8b77267b013711be52c1ff5efba7c5eefa092",
"azure-batch-js": "git://github.com/amarzavery/azure-batch-ts#fae8b77267b013711be52c1ff5efba7c5eefa092",
Expand Down
2 changes: 1 addition & 1 deletion scripts/travis/build-and-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ if [ "${TRAVIS_PULL_REQUEST}" = "false" ] || [ "${TRAVIS_BRANCH}" = "stable" ];
if [ "${TRAVIS_PULL_REQUEST}" = "false" ] && [ "${TRAVIS_BRANCH}" = "stable" ]; then
npm run package -- --publish always --draft
else
npm run package -- --publish never # TODO replace with this
npm run package -- --publish never
fi
ls release
else
Expand Down
38 changes: 37 additions & 1 deletion test/app/spec-controls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// tslint:disable:no-console
import { DataCacheTracker } from "app/services/core";
import { GenericView } from "app/services/core/data/generic-view";
import { Observable, Subscription } from "rxjs";
import { MockEntityView, MockListView } from "test/utils/mocks";

/**
Expand All @@ -13,9 +14,14 @@ afterEach(() => {
DataCacheTracker.disposeAll();
});

const viewCreated = {};
// Generic view
let viewCreated = {};
let lastInit;
let lastDispose;

// Observable
let subscriptionCreated = {};
let lastSubscribe;
let counter = 0;

jasmine.getEnv().addReporter({
Expand All @@ -35,11 +41,13 @@ jasmine.getEnv().addReporter({
dispose.bind(this)();
}
};

},
specDone: (result) => {
GenericView.prototype.init = lastInit;
GenericView.prototype.dispose = lastDispose;
if (result.status === "disabled") { return; }

},

jasmineDone: () => {
Expand All @@ -55,5 +63,33 @@ jasmine.getEnv().addReporter({
}
console.warn("=".repeat(100));
}

viewCreated = {};
},
});

beforeEach(() => {
const subscribe = Observable.prototype.subscribe;
lastSubscribe = subscribe;

Observable.prototype.subscribe = function (this: any, ...args) {
const sub = subscribe.bind(this)(...args);
sub.id = counter++;
subscriptionCreated[sub.id] = {
sub: sub,
};
return sub;
};
});

afterEach(() => {
Observable.prototype.subscribe = lastSubscribe;
const subIds = Object.keys(subscriptionCreated);
if (subIds.length > 0) {
for (const value of Object.values(subscriptionCreated) as any) {
value.sub.unsubscribe();
}
}

subscriptionCreated = {};
});
Loading

0 comments on commit f966e93

Please sign in to comment.