diff options
Diffstat (limited to 'cli/tests')
-rw-r--r-- | cli/tests/workers/shared_array_buffer.ts | 9 | ||||
-rw-r--r-- | cli/tests/workers/test.ts | 28 |
2 files changed, 37 insertions, 0 deletions
diff --git a/cli/tests/workers/shared_array_buffer.ts b/cli/tests/workers/shared_array_buffer.ts new file mode 100644 index 000000000..4af95863a --- /dev/null +++ b/cli/tests/workers/shared_array_buffer.ts @@ -0,0 +1,9 @@ +self.postMessage("ready"); + +globalThis.addEventListener("message", (e) => { + const bytes1 = new Uint8Array(e.data[0]); + const bytes2 = new Uint8Array(e.data[1]); + bytes1[0] = 1; + bytes2[0] = 2; + self.postMessage("done"); +}); diff --git a/cli/tests/workers/test.ts b/cli/tests/workers/test.ts index b37b7aeb1..d35dbec82 100644 --- a/cli/tests/workers/test.ts +++ b/cli/tests/workers/test.ts @@ -790,6 +790,34 @@ Deno.test({ }); Deno.test({ + name: "worker SharedArrayBuffer", + fn: async function (): Promise<void> { + const promise = deferred(); + const workerOptions: WorkerOptions = { type: "module" }; + const w = new Worker( + new URL("shared_array_buffer.ts", import.meta.url).href, + workerOptions, + ); + const sab1 = new SharedArrayBuffer(1); + const sab2 = new SharedArrayBuffer(1); + const bytes1 = new Uint8Array(sab1); + const bytes2 = new Uint8Array(sab2); + assertEquals(bytes1[0], 0); + assertEquals(bytes2[0], 0); + w.onmessage = (): void => { + w.postMessage([sab1, sab2]); + w.onmessage = (): void => { + assertEquals(bytes1[0], 1); + assertEquals(bytes2[0], 2); + promise.resolve(); + }; + }; + await promise; + w.terminate(); + }, +}); + +Deno.test({ name: "Send MessagePorts from / to workers", fn: async function (): Promise<void> { const result = deferred(); |