Fixed bug where message could get lost if plugin was selected

Summary:
If the analytics plugin was in the foreground, and messages arrived in quick succession, some messages would not be processed.

Although the code was tested, there were not enough assertions to make sure the loop was correct. coverage !== correctness {emoji:1f605}

This fixes T68101450

Changelog: Fixed regression where analytics messages where lost

Reviewed By: jknoxville

Differential Revision: D21929679

fbshipit-source-id: c9fe2b18a249e40085d99914a809abf14fa7cf8f
This commit is contained in:
Michel Weststrate
2020-06-08 11:54:43 -07:00
committed by Facebook GitHub Bot
parent 0007ef4b27
commit 2375dd02c3
2 changed files with 11 additions and 6 deletions

View File

@@ -88,13 +88,18 @@ function selectTestPlugin(store: Store, client: Client) {
test('queue - events are processed immediately if plugin is selected', async () => {
await createMockFlipperWithPlugin(
TestPlugin,
async ({store, sendMessage}) => {
async ({store, client, sendMessage}) => {
expect(store.getState().connections.selectedPlugin).toBe('TestPlugin');
sendMessage('noop', {});
sendMessage('noop', {});
sendMessage('inc', {});
sendMessage('inc', {delta: 4});
sendMessage('noop', {});
client.flushMessageBuffer();
expect(store.getState().pluginStates).toMatchInlineSnapshot(`
Object {
"TestApp#Android#MockAndroidDevice#serial#TestPlugin": Object {
"count": 1,
"count": 5,
},
}
`);

View File

@@ -172,10 +172,10 @@ export function processMessagesImmediately(
messages: Message[],
) {
const persistedState = getCurrentPluginState(store, plugin, pluginKey);
let newPluginState: any;
messages.forEach((message) => {
newPluginState = processMessage(persistedState, pluginKey, plugin, message);
});
const newPluginState = messages.reduce(
(state, message) => processMessage(state, pluginKey, plugin, message),
persistedState,
);
if (persistedState !== newPluginState) {
store.dispatch(
setPluginState({