Fix disabling a plugin nog clearing the message queue
Summary: While writing unit tests discovered a bug that disabling a plugin doesn't guarantee cleaning the messagequeues (both the buffer in client and the messagequeue reducer). Fixed that. That was thanks to @#%@#$@#%@ Redux a lot harder than it should be; as 'STAR_PLUGIN' reasons about a plugin + app name, while the message queue reducer would need to deduct the plugin keys from that, but it can't because that mapping is stored in the connections reducers. So I moved the `STAR_PLUGIN` action handling to the root reducer, sot that it can reason about the state of multiple reducers, which looked like the least of all evils. For more ranting about that and possible alternative solutions: https://twitter.com/mweststrate/status/1277556309706117122 Reviewed By: nikoant Differential Revision: D22284043 fbshipit-source-id: 35d0a8ba3a21a5959d2bb6ef17da3ff5077f48fd
This commit is contained in:
committed by
Facebook GitHub Bot
parent
bb0c8e0df0
commit
952e929699
@@ -197,9 +197,8 @@ test('queue - events are NOT processed immediately if plugin is NOT selected (bu
|
||||
selectDeviceLogs(store);
|
||||
sendMessage('inc', {delta: 4});
|
||||
client.flushMessageBuffer();
|
||||
expect(store.getState().pluginMessageQueue).toEqual({
|
||||
[pluginKey]: [],
|
||||
});
|
||||
expect(client.messageBuffer).toMatchInlineSnapshot(`Object {}`);
|
||||
expect(store.getState().pluginMessageQueue).toEqual({});
|
||||
|
||||
// star again, plugin still not selected, message is queued
|
||||
starTestPlugin(store, client);
|
||||
@@ -637,3 +636,61 @@ test('client - incoming messages are buffered and flushed together', async () =>
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
test('queue - messages that have not yet flushed be lost when disabling the plugin', async () => {
|
||||
const {
|
||||
client,
|
||||
store,
|
||||
sendMessage,
|
||||
pluginKey,
|
||||
} = await createMockFlipperWithPlugin(TestPlugin);
|
||||
selectDeviceLogs(store);
|
||||
|
||||
sendMessage('inc', {});
|
||||
sendMessage('inc', {delta: 2});
|
||||
|
||||
expect(client.messageBuffer).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"TestApp#Android#MockAndroidDevice#serial#TestPlugin": Object {
|
||||
"messages": Array [
|
||||
Object {
|
||||
"api": "TestPlugin",
|
||||
"method": "inc",
|
||||
"params": Object {
|
||||
"delta": 2,
|
||||
},
|
||||
},
|
||||
],
|
||||
"plugin": undefined,
|
||||
},
|
||||
}
|
||||
`);
|
||||
expect(store.getState().pluginMessageQueue).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"TestApp#Android#MockAndroidDevice#serial#TestPlugin": Array [
|
||||
Object {
|
||||
"api": "TestPlugin",
|
||||
"method": "inc",
|
||||
"params": Object {},
|
||||
},
|
||||
],
|
||||
}
|
||||
`);
|
||||
|
||||
// disable
|
||||
starTestPlugin(store, client);
|
||||
expect(client.messageBuffer).toMatchInlineSnapshot(`Object {}`);
|
||||
expect(store.getState().pluginMessageQueue).toMatchInlineSnapshot(
|
||||
`Object {}`,
|
||||
);
|
||||
|
||||
// re-enable, no messages arrive
|
||||
starTestPlugin(store, client);
|
||||
client.flushMessageBuffer();
|
||||
processMessageQueue(
|
||||
client.sandyPluginStates.get(TestPlugin.id)!,
|
||||
pluginKey,
|
||||
store,
|
||||
);
|
||||
expect(getTestPluginState(client)).toEqual({count: 0});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user