1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-07-16 00:14:34 +02:00

Mobile: Fix plugin API memory leak (#10115)

This commit is contained in:
Henry Heino
2024-03-14 11:42:13 -07:00
committed by GitHub
parent 6467bf0fc1
commit a53a8d67a1
5 changed files with 125 additions and 6 deletions

View File

@ -147,4 +147,34 @@ describe('RemoteMessenger', () => {
expect(await remoteApi.subObject.multiplyRounded(1.1, 2)).toBe(2);
expect(await remoteApi.subObject.multiplyRounded.call(remoteApi.subObject, 3.1, 4.2)).toBe(12);
});
it('should delete callbacks when dropped remotely', async () => {
const testApi = {
test: jest.fn(),
};
type ApiType = typeof testApi;
const messenger1 = new TestMessenger<ApiType, ApiType>('testid', testApi);
const messenger2 = new TestMessenger<ApiType, ApiType>('testid', testApi);
messenger1.connectTo(messenger2);
const callback = async () => {};
messenger1.remoteApi.test(callback);
// Callbacks should be stored with the source messenger
const callbackId = messenger1.getIdForCallback_(callback);
expect(callbackId).toBeTruthy();
expect(messenger2.getIdForCallback_(callback)).toBe(undefined);
// Dropping a callback at the remote messenger should clear the
// callback on the original messenger
messenger2.mockCallbackDropped(callbackId);
// To avoid random test failure, wait for a round-tip before checking
// whether the callback is still registered.
await messenger1.remoteApi.test(async ()=>{});
expect(messenger1.getIdForCallback_(callback)).toBe(undefined);
});
});