mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-12 01:23:52 +00:00
add bootloader message serialization test
This commit is contained in:
committed by
David Lechner
parent
9b06bc7bd1
commit
0d57338d71
@@ -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', () => {
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user