Last active
November 9, 2021 00:20
-
-
Save FrankHassanabad/68cef0d806f8cd9b2af50fa815af92c1 to your computer and use it in GitHub Desktop.
actionsClientMock leaking memory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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. | |
*/ | |
// Importing like this won't leak memory | |
// import { actionsClientMock } from './actions_client.mock'; | |
// Importing like this will leak memory as it's a more broad import/export with an issue somewhere | |
import { actionsClientMock } from './mocks'; | |
describe('test', () => { | |
afterEach(() => { | |
jest.clearAllMocks(); | |
jest.resetAllMocks(); | |
jest.restoreAllMocks(); | |
jest.resetModules(); | |
}); | |
test('test', () => { | |
// If you expose the garbage collector, run it before all the tests | |
if (global.gc) { | |
global.gc(); | |
} | |
// We need to just do _something_ with the object in order to leak memory. We don't | |
// need to call actionsClientMock.create(); as that's not where the memory leak is. It's within the | |
// import/export somewhere. | |
Object.keys(actionsClientMock); | |
// You actually don't have to call into this below. You just have to touch the object or use the object for the memory leak to happen | |
// const actionsClient = actionsClientMock.create(); | |
expect(true).toEqual(true); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run the
copy_tests.sh
from: https://gist.github.com/FrankHassanabad/ce8353ae0519cbb2cdf38a9e279da1c9 to see it leakingE.x.:
./copy_tests.sh ~/projects/kibana/x-pack/plugins/actions/server/sample.test.ts