mirror of
https://github.com/denoland/deno.git
synced 2025-03-04 01:44:26 -05:00
tests: make worker test deterministic (#12361)
This commit is contained in:
parent
e8b3ffd155
commit
330aaae936
3 changed files with 9 additions and 16 deletions
|
@ -1,4 +1,4 @@
|
||||||
let messagesReceived = 0;
|
const messagesReceived = new Set();
|
||||||
|
|
||||||
for (let i = 0; i < 4; i++) {
|
for (let i = 0; i < 4; i++) {
|
||||||
const worker = new Worker(
|
const worker = new Worker(
|
||||||
|
@ -7,21 +7,20 @@ for (let i = 0; i < 4; i++) {
|
||||||
);
|
);
|
||||||
|
|
||||||
worker.addEventListener("message", () => {
|
worker.addEventListener("message", () => {
|
||||||
messagesReceived += 1;
|
messagesReceived.add(i);
|
||||||
|
if (messagesReceived.size == 4) {
|
||||||
if (messagesReceived == 4) {
|
|
||||||
console.log("received all 4 responses from the workers");
|
console.log("received all 4 responses from the workers");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
worker.postMessage(i);
|
worker.postMessage({});
|
||||||
}
|
}
|
||||||
|
|
||||||
globalThis.addEventListener("unload", () => {
|
globalThis.addEventListener("unload", () => {
|
||||||
if (messagesReceived !== 4) {
|
if (messagesReceived.size !== 4) {
|
||||||
console.log(
|
console.log(
|
||||||
"received only %d responses from the workers",
|
"received only %d responses from the workers",
|
||||||
messagesReceived,
|
messagesReceived.size,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,5 +1 @@
|
||||||
message received in worker 0
|
|
||||||
message received in worker 1
|
|
||||||
message received in worker 2
|
|
||||||
message received in worker 3
|
|
||||||
received all 4 responses from the workers
|
received all 4 responses from the workers
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
self.onmessage = (params) => {
|
onmessage = () => {
|
||||||
const workerId = params.data;
|
postMessage({});
|
||||||
console.log("message received in worker %d", workerId);
|
close();
|
||||||
self.postMessage(workerId);
|
|
||||||
self.close();
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue