Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(webex-core): fix memory leakage in tests #2996

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/@webex/http-core/src/request/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ function doRequest(options) {

const r = request(options, (error, response) => {
if (error) {
if (options.uri.includes('limited/catalog')) {
/* eslint no-console: ["error", { allow: ["trace"] }] */
console.trace('=============');
}
logger.warn(error);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ describe('webex-core', () => {
},
},
});
sinon.stub(webex.boundedStorage, 'put');

assert.equal(webex.config.credentials.authorizeUrl, authorizeUrl);
});
Expand All @@ -46,6 +47,7 @@ describe('webex-core', () => {
webex = new WebexCore({
credentials: user.token,
});
sinon.stub(webex.boundedStorage, 'put');

credentials = webex.credentials;
});
Expand All @@ -65,6 +67,7 @@ describe('webex-core', () => {
webex = new WebexCore({
credentials: user.token,
});
sinon.stub(webex.boundedStorage, 'put');

credentials = webex.credentials;
});
Expand All @@ -85,6 +88,7 @@ describe('webex-core', () => {
webex = new WebexCore({
credentials: user.token,
});
sinon.stub(webex.boundedStorage, 'put');

credentials = webex.credentials;
});
Expand All @@ -102,6 +106,7 @@ describe('webex-core', () => {
const webex = new WebexCore({
credentials: user.token,
});
sinon.stub(webex.boundedStorage, 'put');

return webex.credentials.refresh().then(() => {
assert.isDefined(user.token.access_token);
Expand All @@ -114,6 +119,7 @@ describe('webex-core', () => {
const webex = new WebexCore({
credentials: user.token,
});
sinon.stub(webex.boundedStorage, 'put');

return assert.isRejected(webex.credentials.refresh());
});
Expand All @@ -127,6 +133,7 @@ describe('webex-core', () => {
},
},
});
sinon.stub(webex.boundedStorage, 'put');

return webex.credentials.refresh().then(() => {
assert.isDefined(user.token.access_token);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describe('webex-core', () => {
describe('#downscope()', () => {
it('retrieves an access token with a subset of scopes', () => {
webex = new WebexCore({credentials: user.token});
sinon.stub(webex.boundedStorage, 'put');
const allScope = webex.credentials.config.scope;
const apiScope = filterScope('spark:kms', allScope);

Expand All @@ -46,6 +47,7 @@ describe('webex-core', () => {
describe('#refresh()', () => {
nodeOnly(it)('refreshes the token, returning a new Token instance', () => {
webex = new WebexCore({credentials: user.token});
sinon.stub(webex.boundedStorage, 'put');

return webex.credentials.supertoken.refresh().then((token2) => {
assert.notEqual(token2.access_token, webex.credentials.supertoken.access_token);
Expand All @@ -62,6 +64,7 @@ describe('webex-core', () => {
},
},
});
sinon.stub(webex.boundedStorage, 'put');

return webex.credentials.supertoken.refresh().then((token2) => {
assert.notEqual(token2.access_token, webex.credentials.supertoken.access_token);
Expand All @@ -73,6 +76,7 @@ describe('webex-core', () => {
describe('#validate()', () => {
it("shows the token's scopes", () => {
webex = new WebexCore({credentials: user.token});
sinon.stub(webex.boundedStorage, 'put');

return webex.credentials.supertoken.validate().then((details) => {
const detailScope = details.scope.sort();
Expand All @@ -89,6 +93,7 @@ describe('webex-core', () => {
describe('#revoke()', () => {
it('revokes the token', () => {
webex = new WebexCore({credentials: user.token});
sinon.stub(webex.boundedStorage, 'put');

return webex.credentials.supertoken.revoke().then(() => {
assert.isUndefined(webex.credentials.supertoken.access_token);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ describe('webex-core', () => {
setTimeout(() => {
webexUser = user;
webex = new WebexCore({credentials: user.token});
sinon.stub(webex.boundedStorage, 'put');
services = webex.internal.services;
catalog = services._getCatalog();
resolve();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ describe('webex-core', () => {
beforeEach('create webex instance', () => {
webex = new WebexCore({credentials: {supertoken: webexUser.token}});
webexEU = new WebexCore({credentials: {supertoken: webexUserEU.token}});
sinon.stub(webex.boundedStorage, 'put');
sinon.stub(webexEU.boundedStorage, 'put');
services = webex.internal.services;
servicesEU = webexEU.internal.services;
catalog = services._getCatalog();
Expand Down Expand Up @@ -397,6 +399,7 @@ describe('webex-core', () => {

it('should not attempt to collect catalogs without authorization', (done) => {
const otherWebex = new WebexCore();
sinon.stub(otherWebex.boundedStorage, 'put');
let {initServiceCatalogs} = otherWebex.internal.services;

initServiceCatalogs = sinon.stub();
Expand Down Expand Up @@ -802,6 +805,7 @@ describe('webex-core', () => {

describe('#validateUser()', () => {
const unauthWebex = new WebexCore();
sinon.stub(unauthWebex.boundedStorage, 'put');
const unauthServices = unauthWebex.internal.services;
let sandbox = null;

Expand Down Expand Up @@ -1104,6 +1108,7 @@ describe('webex-core', () => {

describe('#collectPreauthCatalog()', () => {
const unauthWebex = new WebexCore({config: {credentials: {federation: true}}});
sinon.stub(unauthWebex.boundedStorage, 'put');
const unauthServices = unauthWebex.internal.services;
const forceRefresh = true;

Expand Down Expand Up @@ -1158,6 +1163,7 @@ describe('webex-core', () => {

describe('#collectSigninCatalog()', () => {
const unauthWebex = new WebexCore({config: {credentials: {federation: true}}});
sinon.stub(unauthWebex.boundedStorage, 'put');
const unauthServices = unauthWebex.internal.services;

it('requires an email as the parameter', () =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ describe('webex-core', function () {

before(() => {
webex = new WebexCore();
sinon.stub(webex.boundedStorage, 'put');
});

it('adds a tracking id to each request', () =>
Expand Down Expand Up @@ -108,6 +109,7 @@ describe('webex-core', function () {

sinon.spy(webex.boundedStorage, 'clear');
sinon.spy(webex.unboundedStorage, 'clear');
sinon.stub(webex.boundedStorage, 'put');

return new Promise((resolve) => webex.once('ready', resolve)).then(() => {
const {supertoken} = webex.credentials;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import {assert} from '@webex/test-helper-chai';
import {capitalize} from 'lodash';
import WebexCore from '@webex/webex-core';
import sinon from 'sinon';

describe('webex-core', () => {
describe('Interceptors', () => {
Expand Down Expand Up @@ -113,6 +114,7 @@ describe('webex-core', () => {
},
},
});
sinon.stub(webex.boundedStorage, 'put');
});

describe('#transform()', () => {
Expand Down
8 changes: 8 additions & 0 deletions packages/@webex/webex-core/test/unit/spec/webex-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ describe('Webex', () => {

beforeEach(() => {
webex = new WebexCore();
sinon.stub(webex.boundedStorage, 'put');
});

describe('#logger', () => {
Expand Down Expand Up @@ -60,6 +61,7 @@ describe('Webex', () => {

assert.doesNotThrow(() => {
webex = new WebexCore();
sinon.stub(webex.boundedStorage, 'put');
});
assert.isFalse(webex.canAuthorize);
assert.property(webex, 'credentials');
Expand Down Expand Up @@ -107,6 +109,7 @@ describe('Webex', () => {
.forEach(({msg, data}) => {
it(msg, () => {
const webex = new WebexCore(data);
sinon.stub(webex.boundedStorage, 'put');

assert.isTrue(webex.credentials.canAuthorize);
assert.equal(webex.credentials.supertoken.access_token, 'ST');
Expand Down Expand Up @@ -146,6 +149,7 @@ describe('Webex', () => {
access_token: token,
},
});
sinon.stub(webex.boundedStorage, 'put');

assert.isTrue(webex.credentials.canAuthorize);
assert.equal(webex.credentials.supertoken.access_token, '1234');
Expand All @@ -160,6 +164,7 @@ describe('Webex', () => {
const config = {credentials: {prop: true}};

const webex = new WebexCore();
sinon.stub(webex.boundedStorage, 'put');

assert.isUndefined(webex.config.credentials.prop);

Expand Down Expand Up @@ -189,6 +194,7 @@ describe('Webex', () => {
},
},
});
sinon.stub(webex.boundedStorage, 'put');

assert.isFalse(webex.loaded);
assert.isFalse(webex.canAuthorize);
Expand All @@ -204,6 +210,7 @@ describe('Webex', () => {

it('emits the ready event when the storage layer has loaded and all plugins signal ready', () => {
const webex = new WebexCore();
sinon.stub(webex.boundedStorage, 'put');

assert.isFalse(webex.ready);

Expand All @@ -228,6 +235,7 @@ describe('Webex', () => {
);

const webex = new WebexCore();
sinon.stub(webex.boundedStorage, 'put');

const changeSpy = sinon.spy();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describe('Webex', () => {
},
},
});
sinon.stub(webex.boundedStorage, 'put');

assert.isTrue(webex.internal.test.config.reachable);
webex.config.test.reachable = false;
Expand Down Expand Up @@ -52,6 +53,7 @@ describe('Webex', () => {
},
},
});
sinon.stub(webex.boundedStorage, 'put');

webex.internal.on('all', (ev) =>
console.info(
Expand Down
1 change: 1 addition & 0 deletions packages/legacy/jest/static/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ module.exports = {
reporters: ['default'],
testMatch: ['<rootDir>/test/unit/**/!(lib|fixture)/*.[jt]s'],
testPathIgnorePatterns: ['/node_modules/', '/dist/'],
detectOpenHandles: true,
};
Loading