Skip to content

Instantly share code, notes, and snippets.

@FrankHassanabad
Created November 8, 2021 19:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FrankHassanabad/b04e4f957ddce430e517ad5ef16e9a5b to your computer and use it in GitHub Desktop.
Save FrankHassanabad/b04e4f957ddce430e517ad5ef16e9a5b to your computer and use it in GitHub Desktop.
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
// Put this file at "x-pack/plugins/alerting/server/" and then run it with the copy_tests.sh
// from here: https://gist.github.com/FrankHassanabad/ce8353ae0519cbb2cdf38a9e279da1c9
// so that you can see it leak memory very quickly.
// This does not leak memory. Uncomment this and use this instead of the one above.
// import { parseDuration } from '../common/parse_duration';
// This does leak memory
import { parseDuration } from '.';
describe('memory leak as soon as we pull in and use "parseDuration" from "alerting', () => {
beforeAll(() => {
jest.clearAllMocks();
jest.resetAllMocks();
jest.restoreAllMocks();
jest.resetModules();
});
beforeEach(() => {
jest.clearAllMocks();
jest.resetAllMocks();
jest.restoreAllMocks();
jest.resetModules();
jest.clearAllMocks();
});
afterEach(() => {
jest.clearAllMocks();
jest.resetAllMocks();
jest.restoreAllMocks();
jest.resetModules();
});
test('parseDuration', () => {
if (global.gc) {
// console.log('I am able to GC...');
global.gc();
} else {
// console.log('I cannot GC...');
}
parseDuration('5s');
expect(true).toEqual(true);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment