add bootloader message serialization test

This commit is contained in:
David Lechner
2020-05-21 21:27:47 -05:00
committed by David Lechner
parent 9b06bc7bd1
commit 0d57338d71
2 changed files with 40 additions and 1 deletions
+38
View File
@@ -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<Action>();
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', () => {
+2 -1
View File
@@ -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);