[FIX] bus: fix channels subscription ater disconnection test

Before this commit, the `channels subscription after disconnect` bus
test failed randomly. This occured when the websocket reconnection
happened before the first subscription. Indeed, the first subscription
is made only if the resulting channel list differs from the last one
we sent.

This commit fixes the issue by wating for the first subscription
before disconnecting the websocket.

closes odoo/odoo#100391

Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
This commit is contained in:
tsm-odoo
2022-09-17 00:51:49 +02:00
parent 1950e11167
commit b47a06c617
+5 -1
View File
@@ -287,16 +287,20 @@ QUnit.module('Bus', {
patchWithCleanup(window, {
setTimeout: fn => fn(),
});
const firstSubscribeDeferred = makeDeferred();
const worker = patchWebsocketWorkerWithCleanup({
_sendToServer({ event_name, data }) {
assert.step(`${event_name} - [${data.channels.toString()}]`);
if (event_name === 'subscribe') {
firstSubscribeDeferred.resolve();
}
},
});
await makeTestEnv();
// wait for the websocket to connect and the first subscription
// to occur.
await nextTick();
await firstSubscribeDeferred;
worker.websocket.close(WEBSOCKET_CLOSE_CODES.KEEP_ALIVE_TIMEOUT);
// wait for the websocket to re-connect.
await nextTick();