Skip to content

Commit

Permalink
wip: Device handshake blind spots
Browse files Browse the repository at this point in the history
  • Loading branch information
mroz22 committed Jan 16, 2025
1 parent b2a5073 commit 235d165
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
1 change: 1 addition & 0 deletions packages/connect/src/device/Device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ export class Device extends TypedEmitter<DeviceEvents> {
error.message === TRANSPORT_ERROR.HTTP_ERROR // bridge died during device initialization
) {
// disconnected, do nothing
this.emitLifecycle(DEVICE.DISCONNECT);
} else if (
// we don't know what really happened
error.message === TRANSPORT_ERROR.UNEXPECTED_ERROR ||
Expand Down
14 changes: 4 additions & 10 deletions packages/connect/src/device/__tests__/DeviceList.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,20 +141,14 @@ describe('DeviceList', () => {
list.init({ transports: [transport], pendingTransportEvent: true });
const transportFirstEvent = list.pendingConnection();

// NOTE: this behavior is wrong, if device creation fails DeviceList shouldn't wait 10 secs.
jest.useFakeTimers();
// move 9 sec forward
await jest.advanceTimersByTimeAsync(9 * 1000);
// no events yet
expect(eventsSpy).toHaveBeenCalledTimes(0);
// move 2 sec forward
await jest.advanceTimersByTimeAsync(2 * 1000);
// promise should be resolved by now
await transportFirstEvent;
jest.useRealTimers();
const events = eventsSpy.mock.calls.map(call => call[0]);
expect(events).toEqual(['device-disconnect', 'transport-start']);

expect(eventsSpy).toHaveBeenCalledTimes(1);
expect(eventsSpy.mock.calls[0][0]).toEqual('transport-start');
// todo: device should also disappear from DeviceList but it does not. this needs to get discussed
expect(list.getDeviceCount()).toEqual(0);
});

it('.init() with pendingTransportEvent (unreadable device)', async () => {
Expand Down

0 comments on commit 235d165

Please sign in to comment.