[FIX] bus: fix non-deterministic bus tests

Since [1], some bus tests were failing in a non-deterministic
way. This PR fixes the issue.

[1]: https://github.com/odoo/odoo/pull/119525
Fixes runbot errors: 20755, 20756, 19933.

closes odoo/odoo#119807

X-original-commit: c52670c9e91c369410422afacfbd9080d432e8bd
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
Signed-off-by: Stockbauer Matthieu (tsm) <tsm@odoo.com>
This commit is contained in:
tsm-odoo
2023-04-26 15:06:48 +02:00
parent 15e2aebcf4
commit 2ba5818fac
+9 -3
View File
@@ -100,7 +100,7 @@ QUnit.module('Bus', {
const pyEnv = await startServer();
const env = await makeTestEnv({ activateMockServer: true });
env.services["bus_service"].start();
await env.services["bus_service"].start();
await nextTick();
env.services['bus_service'].addEventListener('notification', ({ detail: notifications }) => {
assert.step('notification - ' + notifications.map(notif => notif.payload).toString());
@@ -469,14 +469,20 @@ QUnit.module('Bus', {
QUnit.test("Disconnect on offline, re-connect on online", async function (assert) {
patchWebsocketWorkerWithCleanup();
let websocketConnectedDeferred = makeDeferred();
const env = await makeTestEnv();
env.services["bus_service"].addEventListener("connect", () => assert.step("connect"));
env.services["bus_service"].addEventListener("connect", () => {
assert.step("connect");
websocketConnectedDeferred.resolve();
websocketConnectedDeferred = makeDeferred();
});
env.services["bus_service"].addEventListener("disconnect", () => assert.step("disconnect"));
await env.services["bus_service"].start();
await websocketConnectedDeferred;
window.dispatchEvent(new Event("offline"));
await nextTick();
window.dispatchEvent(new Event("online"));
await nextTick();
await websocketConnectedDeferred;
assert.verifySteps(["connect", "disconnect", "connect"]);
});