diff --git a/src/sagas/bootloader.test.ts b/src/sagas/bootloader.test.ts index b3210527..a0d775d1 100644 --- a/src/sagas/bootloader.test.ts +++ b/src/sagas/bootloader.test.ts @@ -20,6 +20,8 @@ import { BootloaderStateRequestAction, BootloaderStateResponseAction, didReceive, + didSend, + eraseRequest, } from '../actions/bootloader'; import { Command, HubType, ProtectionLevel, Result } from '../protocols/bootloader'; import bootloader from './bootloader'; @@ -145,6 +147,42 @@ describe('message encoder', () => { withResponse: false, }); }); + + test('requests are serialized', async () => { + const channel = stdChannel(); + const dispatched = new Array(); + const task = runSaga( + { + channel, + dispatch: (action: Action) => dispatched.push(action), + }, + bootloader, + ); + + // we send 4 requests + channel.put(eraseRequest()); + channel.put(eraseRequest()); + channel.put(eraseRequest()); + channel.put(eraseRequest()); + + // but only one didSend action meaning only the first one completed + channel.put(didSend()); + + task.cancel(); + await task.toPromise(); + + // so only 2 messages were actually sent and 2 are still waiting for + // the second one to complete + expect(dispatched.length).toEqual(2); + const message = new Uint8Array([Command.EraseFlash]); + for (const d of dispatched) { + expect(d).toEqual({ + type: BootloaderConnectionActionType.Send, + data: message, + withResponse: false, + }); + } + }); }); describe('message decoder', () => { diff --git a/src/sagas/bootloader.ts b/src/sagas/bootloader.ts index c9268eff..3d6f3c7c 100644 --- a/src/sagas/bootloader.ts +++ b/src/sagas/bootloader.ts @@ -114,9 +114,10 @@ function* encodeRequest(): Generator { case BootloaderRequestActionType.Disconnect: yield put(send(createDisconnectRequest())); break; + /* istanbul ignore next: should not be possible to reach */ default: console.error(`Unknown bootloader request action ${action}`); - break; + continue; } yield take(BootloaderConnectionActionType.DidSend);