Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(ext/web): use a non-resource stream for textDecoderStreamCleansUpOnCancel #21181

Merged
merged 4 commits into from
Nov 13, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use a ReadableStream rather than a resource for this test
  • Loading branch information
mmastrac committed Nov 13, 2023
commit 06470bced3f9762a7915065bc085d1fc5fcec1e6
26 changes: 19 additions & 7 deletions cli/tests/unit/text_encoding_test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
import { assert, assertEquals, assertThrows } from "./test_util.ts";
import {
assert,
assertEquals,
assertStrictEquals,
assertThrows,
} from "./test_util.ts";

Deno.test(function btoaSuccess() {
const text = "hello world";
Expand Down Expand Up @@ -323,14 +328,20 @@ Deno.test(function binaryEncode() {
Deno.test(
{
permissions: { read: true },
// TODO(mmastrac): readableStreamForRid doesn't guarantee cancellation of ops, so we may be left with a
// dangling read op that triggers the sanitizer.
sanitizeOps: false,
},
async function textDecoderStreamCleansUpOnCancel() {
const filename = "cli/tests/testdata/assets/hello.txt";
const file = await Deno.open(filename);
const readable = file.readable.pipeThrough(new TextDecoderStream());
let timeout: number | undefined = undefined;
const readable = new ReadableStream({
start: (controller) => {
controller.enqueue(new Uint8Array(12));
// This will never be called
timeout = setTimeout(() => controller.close());
},
cancel: () => {
clearTimeout(timeout);
timeout = undefined;
},
}).pipeThrough(new TextDecoderStream());
const chunks = [];
for await (const chunk of readable) {
chunks.push(chunk);
Expand All @@ -339,5 +350,6 @@ Deno.test(
}
assertEquals(chunks.length, 1);
assertEquals(chunks[0].length, 12);
assertStrictEquals(timeout, undefined);
},
);