Remove event_queue GK

Summary: Did run for 2 months stable now, time to remove some dead code.

Reviewed By: passy

Differential Revision: D20556785

fbshipit-source-id: 514673995212d62d21744f304286caa6e91007fb
This commit is contained in:
Michel Weststrate
2020-03-23 06:42:08 -07:00
committed by Facebook GitHub Bot
parent 06cd90562d
commit d103692883
2 changed files with 188 additions and 240 deletions

View File

@@ -25,11 +25,7 @@ import {EventEmitter} from 'events';
import invariant from 'invariant'; import invariant from 'invariant';
import {flipperRecorderAddEvent} from './utils/pluginStateRecorder'; import {flipperRecorderAddEvent} from './utils/pluginStateRecorder';
import {getPluginKey} from './utils/pluginUtils'; import {getPluginKey} from './utils/pluginUtils';
import { import {processMessageLater} from './utils/messageQueue';
processMessageImmediately,
processMessageLater,
} from './utils/messageQueue';
import GK from './fb-stubs/GK';
type Plugins = Array<string>; type Plugins = Array<string>;
@@ -350,21 +346,12 @@ export default class Client extends EventEmitter {
if (persistingPlugin && persistingPlugin.persistedStateReducer) { if (persistingPlugin && persistingPlugin.persistedStateReducer) {
const pluginKey = getPluginKey(this.id, device, params.api); const pluginKey = getPluginKey(this.id, device, params.api);
flipperRecorderAddEvent(pluginKey, params.method, params.params); flipperRecorderAddEvent(pluginKey, params.method, params.params);
if (GK.get('flipper_event_queue')) { processMessageLater(
processMessageLater( this.store,
this.store, pluginKey,
pluginKey, persistingPlugin,
persistingPlugin, params,
params, );
);
} else {
processMessageImmediately(
this.store,
pluginKey,
persistingPlugin,
params,
);
}
} }
} else { } else {
console.warn( console.warn(

View File

@@ -9,7 +9,7 @@
import {FlipperPlugin} from '../../plugin'; import {FlipperPlugin} from '../../plugin';
import {createMockFlipperWithPlugin} from '../../test-utils/createMockFlipperWithPlugin'; import {createMockFlipperWithPlugin} from '../../test-utils/createMockFlipperWithPlugin';
import {GK, Store, Client} from '../../'; import {Store, Client} from '../../';
import { import {
selectPlugin, selectPlugin,
starPlugin, starPlugin,
@@ -84,41 +84,22 @@ function selectTestPlugin(store: Store, client: Client) {
); );
} }
test('will process event with GK disabled', async () => { test('queue - events are processed immediately if plugin is selected', async () => {
await createMockFlipperWithPlugin( await createMockFlipperWithPlugin(
TestPlugin, TestPlugin,
async ({store, sendMessage}) => { async ({store, sendMessage}) => {
expect(store.getState().connections.selectedPlugin).toBe('TestPlugin'); expect(store.getState().connections.selectedPlugin).toBe('TestPlugin');
sendMessage('inc', {}); sendMessage('inc', {});
expect(store.getState().pluginStates).toMatchInlineSnapshot(` expect(store.getState().pluginStates).toMatchInlineSnapshot(`
Object {
"TestApp#Android#MockAndroidDevice#serial#TestPlugin": Object {
"count": 1,
},
}
`);
},
);
});
test('queue - events are processed immediately if plugin is selected', async () => {
await createMockFlipperWithPlugin(
TestPlugin,
async ({store, sendMessage}) => {
await GK.withWhitelistedGK('flipper_event_queue', () => {
expect(store.getState().connections.selectedPlugin).toBe('TestPlugin');
sendMessage('inc', {});
expect(store.getState().pluginStates).toMatchInlineSnapshot(`
Object { Object {
"TestApp#Android#MockAndroidDevice#serial#TestPlugin": Object { "TestApp#Android#MockAndroidDevice#serial#TestPlugin": Object {
"count": 1, "count": 1,
}, },
} }
`); `);
expect(store.getState().pluginMessageQueue).toMatchInlineSnapshot( expect(store.getState().pluginMessageQueue).toMatchInlineSnapshot(
`Object {}`, `Object {}`,
); );
});
}, },
); );
}); });
@@ -127,18 +108,15 @@ test('queue - events are NOT processed immediately if plugin is NOT selected (bu
await createMockFlipperWithPlugin( await createMockFlipperWithPlugin(
TestPlugin, TestPlugin,
async ({client, device, store, sendMessage}) => { async ({client, device, store, sendMessage}) => {
await GK.withWhitelistedGK('flipper_event_queue', async () => { selectDeviceLogs(store);
selectDeviceLogs(store); expect(store.getState().connections.selectedPlugin).not.toBe(
expect(store.getState().connections.selectedPlugin).not.toBe( 'TestPlugin',
'TestPlugin', );
);
sendMessage('inc', {}); sendMessage('inc', {});
sendMessage('inc', {delta: 2}); sendMessage('inc', {delta: 2});
expect(store.getState().pluginStates).toMatchInlineSnapshot( expect(store.getState().pluginStates).toMatchInlineSnapshot(`Object {}`);
`Object {}`, expect(store.getState().pluginMessageQueue).toMatchInlineSnapshot(`
);
expect(store.getState().pluginMessageQueue).toMatchInlineSnapshot(`
Object { Object {
"TestApp#Android#MockAndroidDevice#serial#TestPlugin": Array [ "TestApp#Android#MockAndroidDevice#serial#TestPlugin": Array [
Object { Object {
@@ -155,44 +133,43 @@ test('queue - events are NOT processed immediately if plugin is NOT selected (bu
} }
`); `);
// process the message // process the message
const pluginKey = getPluginKey(client.id, device, TestPlugin.id); const pluginKey = getPluginKey(client.id, device, TestPlugin.id);
await processMessageQueue(TestPlugin, pluginKey, store); await processMessageQueue(TestPlugin, pluginKey, store);
expect(store.getState().pluginStates).toEqual({ expect(store.getState().pluginStates).toEqual({
[pluginKey]: { [pluginKey]: {
count: 3, count: 3,
}, },
}); });
expect(store.getState().pluginMessageQueue).toEqual({ expect(store.getState().pluginMessageQueue).toEqual({
[pluginKey]: [], [pluginKey]: [],
}); });
// unstar, but, messages still arrives because selected // unstar, but, messages still arrives because selected
starTestPlugin(store, client); starTestPlugin(store, client);
selectTestPlugin(store, client); selectTestPlugin(store, client);
sendMessage('inc', {delta: 3}); sendMessage('inc', {delta: 3});
// active, immediately processed // active, immediately processed
expect(store.getState().pluginStates).toEqual({ expect(store.getState().pluginStates).toEqual({
[pluginKey]: { [pluginKey]: {
count: 6, count: 6,
}, },
}); });
// different plugin, and not starred, message will never arrive // different plugin, and not starred, message will never arrive
selectDeviceLogs(store); selectDeviceLogs(store);
sendMessage('inc', {delta: 4}); sendMessage('inc', {delta: 4});
expect(store.getState().pluginMessageQueue).toEqual({ expect(store.getState().pluginMessageQueue).toEqual({
[pluginKey]: [], [pluginKey]: [],
}); });
// star again, plugin still not selected, message is queued // star again, plugin still not selected, message is queued
starTestPlugin(store, client); starTestPlugin(store, client);
sendMessage('inc', {delta: 5}); sendMessage('inc', {delta: 5});
expect(store.getState().pluginMessageQueue).toEqual({ expect(store.getState().pluginMessageQueue).toEqual({
[pluginKey]: [{method: 'inc', params: {delta: 5}}], [pluginKey]: [{method: 'inc', params: {delta: 5}}],
});
}); });
}, },
); );
@@ -202,23 +179,20 @@ test('queue - events are queued for plugins that are favorite when app is not se
await createMockFlipperWithPlugin( await createMockFlipperWithPlugin(
TestPlugin, TestPlugin,
async ({device, store, sendMessage, createClient}) => { async ({device, store, sendMessage, createClient}) => {
await GK.withWhitelistedGK('flipper_event_queue', async () => { selectDeviceLogs(store);
selectDeviceLogs(store); expect(store.getState().connections.selectedPlugin).not.toBe(
expect(store.getState().connections.selectedPlugin).not.toBe( 'TestPlugin',
'TestPlugin', );
);
const client2 = createClient(device, 'TestApp2'); const client2 = createClient(device, 'TestApp2');
store.dispatch(selectClient(client2.id)); store.dispatch(selectClient(client2.id));
// Now we send a message to the second client, it should arrive, // Now we send a message to the second client, it should arrive,
// as the plugin was enabled already on the first client as well // as the plugin was enabled already on the first client as well
sendMessage('inc', {delta: 2}); sendMessage('inc', {delta: 2});
expect(store.getState().pluginStates).toMatchInlineSnapshot( expect(store.getState().pluginStates).toMatchInlineSnapshot(`Object {}`);
`Object {}`, expect(store.getState().pluginMessageQueue).toMatchInlineSnapshot(
); `
expect(store.getState().pluginMessageQueue).toMatchInlineSnapshot(
`
Object { Object {
"TestApp#Android#MockAndroidDevice#serial#TestPlugin": Array [ "TestApp#Android#MockAndroidDevice#serial#TestPlugin": Array [
Object { Object {
@@ -230,8 +204,7 @@ test('queue - events are queued for plugins that are favorite when app is not se
], ],
} }
`, `,
); );
});
}, },
); );
}); });
@@ -240,25 +213,22 @@ test('queue - events are queued for plugins that are favorite when app is select
await createMockFlipperWithPlugin( await createMockFlipperWithPlugin(
TestPlugin, TestPlugin,
async ({client, store, sendMessage, createDevice, createClient}) => { async ({client, store, sendMessage, createDevice, createClient}) => {
await GK.withWhitelistedGK('flipper_event_queue', async () => { selectDeviceLogs(store);
selectDeviceLogs(store); expect(store.getState().connections.selectedPlugin).not.toBe(
expect(store.getState().connections.selectedPlugin).not.toBe( 'TestPlugin',
'TestPlugin', );
);
const device2 = createDevice('serial2'); const device2 = createDevice('serial2');
const client2 = createClient(device2, client.query.app); // same app id const client2 = createClient(device2, client.query.app); // same app id
store.dispatch(selectDevice(device2)); store.dispatch(selectDevice(device2));
store.dispatch(selectClient(client2.id)); store.dispatch(selectClient(client2.id));
// Now we send a message to the second client, it should arrive, // Now we send a message to the second client, it should arrive,
// as the plugin was enabled already on the first client as well // as the plugin was enabled already on the first client as well
sendMessage('inc', {delta: 2}); sendMessage('inc', {delta: 2});
expect(store.getState().pluginStates).toMatchInlineSnapshot( expect(store.getState().pluginStates).toMatchInlineSnapshot(`Object {}`);
`Object {}`, expect(store.getState().pluginMessageQueue).toMatchInlineSnapshot(
); `
expect(store.getState().pluginMessageQueue).toMatchInlineSnapshot(
`
Object { Object {
"TestApp#Android#MockAndroidDevice#serial#TestPlugin": Array [ "TestApp#Android#MockAndroidDevice#serial#TestPlugin": Array [
Object { Object {
@@ -270,8 +240,7 @@ test('queue - events are queued for plugins that are favorite when app is select
], ],
} }
`, `,
); );
});
}, },
); );
}); });
@@ -280,52 +249,50 @@ test('queue - events processing will be paused', async () => {
await createMockFlipperWithPlugin( await createMockFlipperWithPlugin(
TestPlugin, TestPlugin,
async ({client, device, store, sendMessage}) => { async ({client, device, store, sendMessage}) => {
await GK.withWhitelistedGK('flipper_event_queue', async () => { selectDeviceLogs(store);
selectDeviceLogs(store);
sendMessage('inc', {}); sendMessage('inc', {});
sendMessage('inc', {delta: 3}); sendMessage('inc', {delta: 3});
sendMessage('inc', {delta: 5}); sendMessage('inc', {delta: 5});
// process the message // process the message
const pluginKey = getPluginKey(client.id, device, TestPlugin.id); const pluginKey = getPluginKey(client.id, device, TestPlugin.id);
// controlled idler will signal and and off that idling is needed // controlled idler will signal and and off that idling is needed
const idler = new TestIdler(); const idler = new TestIdler();
const p = processMessageQueue( const p = processMessageQueue(
TestPlugin, TestPlugin,
pluginKey, pluginKey,
store, store,
undefined, undefined,
idler, idler,
); );
expect(store.getState().pluginStates).toEqual({ expect(store.getState().pluginStates).toEqual({
[pluginKey]: { [pluginKey]: {
count: 4, count: 4,
}, },
});
expect(store.getState().pluginMessageQueue).toEqual({
[pluginKey]: [{method: 'inc', params: {delta: 5}}],
});
await idler.next();
expect(store.getState().pluginStates).toEqual({
[pluginKey]: {
count: 9,
},
});
expect(store.getState().pluginMessageQueue).toEqual({
[pluginKey]: [],
});
// don't idle anymore
idler.run();
await p;
}); });
expect(store.getState().pluginMessageQueue).toEqual({
[pluginKey]: [{method: 'inc', params: {delta: 5}}],
});
await idler.next();
expect(store.getState().pluginStates).toEqual({
[pluginKey]: {
count: 9,
},
});
expect(store.getState().pluginMessageQueue).toEqual({
[pluginKey]: [],
});
// don't idle anymore
idler.run();
await p;
}, },
); );
}); });
@@ -334,53 +301,51 @@ test('queue - messages that arrive during processing will be queued', async () =
await createMockFlipperWithPlugin( await createMockFlipperWithPlugin(
TestPlugin, TestPlugin,
async ({client, device, store, sendMessage}) => { async ({client, device, store, sendMessage}) => {
await GK.withWhitelistedGK('flipper_event_queue', async () => { selectDeviceLogs(store);
selectDeviceLogs(store);
sendMessage('inc', {}); sendMessage('inc', {});
sendMessage('inc', {delta: 2}); sendMessage('inc', {delta: 2});
sendMessage('inc', {delta: 3}); sendMessage('inc', {delta: 3});
// process the message // process the message
const pluginKey = getPluginKey(client.id, device, TestPlugin.id); const pluginKey = getPluginKey(client.id, device, TestPlugin.id);
const idler = new TestIdler(); const idler = new TestIdler();
const p = processMessageQueue( const p = processMessageQueue(
TestPlugin, TestPlugin,
pluginKey, pluginKey,
store, store,
undefined, undefined,
idler, idler,
); );
// first message is consumed // first message is consumed
expect(store.getState().pluginMessageQueue[pluginKey].length).toBe(1); expect(store.getState().pluginMessageQueue[pluginKey].length).toBe(1);
expect(store.getState().pluginStates[pluginKey].count).toBe(3); expect(store.getState().pluginStates[pluginKey].count).toBe(3);
// Select the current plugin as active, still, messages should end up in the queue // Select the current plugin as active, still, messages should end up in the queue
store.dispatch( store.dispatch(
selectPlugin({ selectPlugin({
selectedPlugin: TestPlugin.id, selectedPlugin: TestPlugin.id,
selectedApp: client.id, selectedApp: client.id,
deepLinkPayload: null, deepLinkPayload: null,
selectedDevice: device, selectedDevice: device,
}), }),
); );
expect(store.getState().connections.selectedPlugin).toBe('TestPlugin'); expect(store.getState().connections.selectedPlugin).toBe('TestPlugin');
sendMessage('inc', {delta: 4}); sendMessage('inc', {delta: 4});
// should not be processed yet // should not be processed yet
expect(store.getState().pluginMessageQueue[pluginKey].length).toBe(2); expect(store.getState().pluginMessageQueue[pluginKey].length).toBe(2);
expect(store.getState().pluginStates[pluginKey].count).toBe(3); expect(store.getState().pluginStates[pluginKey].count).toBe(3);
await idler.next(); await idler.next();
expect(store.getState().pluginMessageQueue[pluginKey].length).toBe(0); expect(store.getState().pluginMessageQueue[pluginKey].length).toBe(0);
expect(store.getState().pluginStates[pluginKey].count).toBe(10); expect(store.getState().pluginStates[pluginKey].count).toBe(10);
idler.run(); idler.run();
await p; await p;
});
}, },
); );
}); });
@@ -389,39 +354,37 @@ test('queue - processing can be cancelled', async () => {
await createMockFlipperWithPlugin( await createMockFlipperWithPlugin(
TestPlugin, TestPlugin,
async ({client, device, store, sendMessage}) => { async ({client, device, store, sendMessage}) => {
await GK.withWhitelistedGK('flipper_event_queue', async () => { selectDeviceLogs(store);
selectDeviceLogs(store);
sendMessage('inc', {}); sendMessage('inc', {});
sendMessage('inc', {delta: 2}); sendMessage('inc', {delta: 2});
sendMessage('inc', {delta: 3}); sendMessage('inc', {delta: 3});
sendMessage('inc', {delta: 4}); sendMessage('inc', {delta: 4});
sendMessage('inc', {delta: 5}); sendMessage('inc', {delta: 5});
// process the message // process the message
const pluginKey = getPluginKey(client.id, device, TestPlugin.id); const pluginKey = getPluginKey(client.id, device, TestPlugin.id);
const idler = new TestIdler(); const idler = new TestIdler();
const p = processMessageQueue( const p = processMessageQueue(
TestPlugin, TestPlugin,
pluginKey, pluginKey,
store, store,
undefined, undefined,
idler, idler,
); );
// first message is consumed // first message is consumed
await idler.next(); await idler.next();
expect(store.getState().pluginMessageQueue[pluginKey].length).toBe(1); expect(store.getState().pluginMessageQueue[pluginKey].length).toBe(1);
expect(store.getState().pluginStates[pluginKey].count).toBe(10); expect(store.getState().pluginStates[pluginKey].count).toBe(10);
idler.cancel(); idler.cancel();
expect(store.getState().pluginMessageQueue[pluginKey].length).toBe(1); expect(store.getState().pluginMessageQueue[pluginKey].length).toBe(1);
expect(store.getState().pluginStates[pluginKey].count).toBe(10); expect(store.getState().pluginStates[pluginKey].count).toBe(10);
await p; await p;
});
}, },
); );
}); });
@@ -430,23 +393,21 @@ test('queue - make sure resetting plugin state clears the message queue', async
await createMockFlipperWithPlugin( await createMockFlipperWithPlugin(
TestPlugin, TestPlugin,
async ({client, device, store, sendMessage}) => { async ({client, device, store, sendMessage}) => {
await GK.withWhitelistedGK('flipper_event_queue', async () => { selectDeviceLogs(store);
selectDeviceLogs(store);
sendMessage('inc', {}); sendMessage('inc', {});
sendMessage('inc', {delta: 2}); sendMessage('inc', {delta: 2});
const pluginKey = getPluginKey(client.id, device, TestPlugin.id); const pluginKey = getPluginKey(client.id, device, TestPlugin.id);
expect(store.getState().pluginMessageQueue[pluginKey].length).toBe(2); expect(store.getState().pluginMessageQueue[pluginKey].length).toBe(2);
store.dispatch({ store.dispatch({
type: 'CLEAR_PLUGIN_STATE', type: 'CLEAR_PLUGIN_STATE',
payload: {clientId: client.id, devicePlugins: new Set()}, payload: {clientId: client.id, devicePlugins: new Set()},
});
expect(store.getState().pluginMessageQueue[pluginKey]).toBe(undefined);
}); });
expect(store.getState().pluginMessageQueue[pluginKey]).toBe(undefined);
}, },
); );
}); });