Fix device cleanup
Summary: Fixes https://github.com/facebook/flipper/issues/1989 We had some self healing side effect that would destroy devices when registering a new device with the same serial, if they weren't yet. Redux isn't too happy about that, causing the attached crash. Instead introduced a utility to destroy devices, and log an error if the device life cycle isn't respected by the device implementations, rather than crashing we will now just waste some memory. Changelog: Fix a crash when disconnecting metro devices Reviewed By: passy Differential Revision: D26749214 fbshipit-source-id: 4c185ac521d44c1337fac8a9145440123b8b784c
This commit is contained in:
committed by
Facebook GitHub Bot
parent
4a71a5abd1
commit
224ec4d5d6
@@ -17,6 +17,7 @@ import {
|
||||
PluginClient,
|
||||
} from 'flipper-plugin';
|
||||
import {registerNewClient} from '../dispatcher/server';
|
||||
import {destroyDevice} from '../reducers/connections';
|
||||
|
||||
test('Devices can disconnect', async () => {
|
||||
const deviceplugin = new _SandyPluginDefinition(
|
||||
@@ -89,7 +90,9 @@ test('New device with same serial removes & cleans the old one', async () => {
|
||||
},
|
||||
},
|
||||
);
|
||||
const {device, store} = await createMockFlipperWithPlugin(deviceplugin);
|
||||
const {device, store, logger} = await createMockFlipperWithPlugin(
|
||||
deviceplugin,
|
||||
);
|
||||
|
||||
const instance = device.sandyPluginStates.get(deviceplugin.id)!;
|
||||
|
||||
@@ -98,6 +101,10 @@ test('New device with same serial removes & cleans the old one', async () => {
|
||||
expect(instance.instanceApi.destroy).toBeCalledTimes(0);
|
||||
expect(store.getState().connections.devices).toEqual([device]);
|
||||
|
||||
// calling destroy explicitly defeats the point of this test a bit,
|
||||
// but we now print an error rather than proactively destroying the device,
|
||||
// see https://github.com/facebook/flipper/issues/1989
|
||||
destroyDevice(store, logger, device.serial);
|
||||
// submit a new device with same serial
|
||||
const device2 = new BaseDevice(
|
||||
device.serial,
|
||||
|
||||
Reference in New Issue
Block a user