ladybird/Tests/LibWeb/Text/input/Worker/Worker-echo.html
sideshowbarker 2e86169246 Tests: Serialize Worker-echo messages to eliminate an ordering race
Problem: The Worker-echo.html test flakes under load in CI on the
Sanitizer runners, printing its messages out of order.

Cause: The test asserts a fixed order for messages arriving over two
separate ports: “loaded” over the Worker’s own port, and the channel
messages over the transferred MessagePort. Those two race, with no
cross-port ordering guarantee. So the printed order is nondeterministic.

Fix: Sequence each message explicitly with an awaited helper — the same
approach used for SharedWorker-reuse in #9669 — so the printed order is
deterministic. port2 is left unstarted until after “loaded”.
2026-06-22 14:46:00 +02:00

30 lines
1 KiB
HTML

<!DOCTYPE html>
<script src="../include.js"></script>
<script>
asyncTest(async (done) => {
const work = new Worker("worker.js");
const channel = new MessageChannel();
function nextMessage(target, label) {
return new Promise((resolve) => {
target.addEventListener("message", function handler(event) {
target.removeEventListener("message", handler);
println(label + ": " + JSON.stringify(event.data));
resolve(event.data);
});
});
}
work.postMessage({ port: channel.port1 }, { transfer: [channel.port1] });
await nextMessage(work, "Got message from worker");
channel.port2.start();
await nextMessage(channel.port2, "Got message from port");
channel.port2.postMessage("Hello from port2");
await nextMessage(channel.port2, "Got message from port");
println("DONE");
work.terminate();
done();
});
</script>