diff options
author | Jimmy Wärting <jimmy@warting.se> | 2021-07-05 15:34:37 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-05 15:34:37 +0200 |
commit | 2c0b0e45b72ef1b5d7fa95e1e110d07ddbc720f7 (patch) | |
tree | 3b54a6f1f156f8d105cf41ac290035c8b5f8f1c9 /cli/tests | |
parent | ea87d860beda7cd40eb6857199a00e5ba8700fd2 (diff) |
refactor: asynchronous blob backing store (#10969)
Co-authored-by: Luca Casonato <hello@lcas.dev>
Diffstat (limited to 'cli/tests')
-rw-r--r-- | cli/tests/blob_gc_finalization.js | 11 | ||||
-rw-r--r-- | cli/tests/blob_gc_finalization.js.out | 1 | ||||
-rw-r--r-- | cli/tests/integration/run_tests.rs | 6 | ||||
-rw-r--r-- | cli/tests/unit/fetch_test.ts | 4 | ||||
-rw-r--r-- | cli/tests/unit/response_test.ts | 3 |
5 files changed, 23 insertions, 2 deletions
diff --git a/cli/tests/blob_gc_finalization.js b/cli/tests/blob_gc_finalization.js new file mode 100644 index 000000000..34c878513 --- /dev/null +++ b/cli/tests/blob_gc_finalization.js @@ -0,0 +1,11 @@ +// This test creates 1024 blobs of 128 MB each. This will only work if the blobs +// and their backing data is GCed as expected. +for (let i = 0; i < 1024; i++) { + // Create a 128MB byte array, and then a blob from it. + const buf = new Uint8Array(128 * 1024 * 1024); + new Blob([buf]); + // It is very important that there is a yield here, otherwise the finalizer + // for the blob is not called and the memory is not freed. + await new Promise((resolve) => setTimeout(resolve, 0)); +} +console.log("GCed all blobs"); diff --git a/cli/tests/blob_gc_finalization.js.out b/cli/tests/blob_gc_finalization.js.out new file mode 100644 index 000000000..dcc4500f8 --- /dev/null +++ b/cli/tests/blob_gc_finalization.js.out @@ -0,0 +1 @@ +GCed all blobs diff --git a/cli/tests/integration/run_tests.rs b/cli/tests/integration/run_tests.rs index 025ee07e1..374cd473b 100644 --- a/cli/tests/integration/run_tests.rs +++ b/cli/tests/integration/run_tests.rs @@ -366,6 +366,12 @@ itest!(js_import_detect { exit_code: 0, }); +itest!(blob_gc_finalization { + args: "run blob_gc_finalization.js", + output: "blob_gc_finalization.js.out", + exit_code: 0, +}); + itest!(lock_write_requires_lock { args: "run --lock-write some_file.ts", output: "lock_write_requires_lock.out", diff --git a/cli/tests/unit/fetch_test.ts b/cli/tests/unit/fetch_test.ts index a84e18367..24a820dba 100644 --- a/cli/tests/unit/fetch_test.ts +++ b/cli/tests/unit/fetch_test.ts @@ -821,7 +821,9 @@ unitTest(function responseRedirect(): void { unitTest(async function responseWithoutBody(): Promise<void> { const response = new Response(); assertEquals(await response.arrayBuffer(), new ArrayBuffer(0)); - assertEquals(await response.blob(), new Blob([])); + const blob = await response.blob(); + assertEquals(blob.size, 0); + assertEquals(await blob.arrayBuffer(), new ArrayBuffer(0)); assertEquals(await response.text(), ""); await assertThrowsAsync(async () => { await response.json(); diff --git a/cli/tests/unit/response_test.ts b/cli/tests/unit/response_test.ts index 9993eb925..7e444fd83 100644 --- a/cli/tests/unit/response_test.ts +++ b/cli/tests/unit/response_test.ts @@ -34,7 +34,8 @@ unitTest(async function responseBlob() { assert(blobPromise instanceof Promise); const blob = await blobPromise; assert(blob instanceof Blob); - assertEquals(blob, new Blob([new Uint8Array([1, 2, 3])])); + assertEquals(blob.size, 3); + assertEquals(await blob.arrayBuffer(), new Uint8Array([1, 2, 3]).buffer); }); // TODO(lucacasonato): re-enable test once #10002 is fixed. |