summaryrefslogtreecommitdiff
path: root/cli/tests/unit/serve_test.ts
diff options
context:
space:
mode:
authorMatt Mastracci <matthew@mastracci.com>2023-08-17 07:52:37 -0600
committerGitHub <noreply@github.com>2023-08-17 07:52:37 -0600
commit23ff0e722e3c4b0827940853c53c5ee2ede5ec9f (patch)
tree1521ffd2ac5e803224546cb349b3905925b9b5ff /cli/tests/unit/serve_test.ts
parent0960e895da1275792c1f38999f6a185c864edb3f (diff)
feat(ext/web): resourceForReadableStream (#20180)
Extracted from fast streams work. This is a resource wrapper for `ReadableStream`, allowing us to treat all `ReadableStream` instances as resources, and remove special paths in both `fetch` and `serve`. Performance with a ReadableStream response yields ~18% improvement: ``` return new Response(new ReadableStream({ start(controller) { controller.enqueue(new Uint8Array([104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100])); controller.close(); } }) ``` This patch: ``` 12:36 $ third_party/prebuilt/mac/wrk http://localhost:8080 Running 10s test @ http://localhost:8080 2 threads and 10 connections Thread Stats Avg Stdev Max +/- Stdev Latency 99.96us 100.03us 6.65ms 98.84% Req/Sec 47.73k 2.43k 51.02k 89.11% 959308 requests in 10.10s, 117.10MB read Requests/sec: 94978.71 Transfer/sec: 11.59MB ``` main: ``` Running 10s test @ http://localhost:8080 2 threads and 10 connections Thread Stats Avg Stdev Max +/- Stdev Latency 163.03us 685.51us 19.73ms 99.27% Req/Sec 39.50k 3.98k 66.11k 95.52% 789582 requests in 10.10s, 82.83MB read Requests/sec: 78182.65 Transfer/sec: 8.20MB ```
Diffstat (limited to 'cli/tests/unit/serve_test.ts')
-rw-r--r--cli/tests/unit/serve_test.ts36
1 files changed, 21 insertions, 15 deletions
diff --git a/cli/tests/unit/serve_test.ts b/cli/tests/unit/serve_test.ts
index 68d03e846..f0a5b430b 100644
--- a/cli/tests/unit/serve_test.ts
+++ b/cli/tests/unit/serve_test.ts
@@ -693,24 +693,30 @@ function createStreamTest(count: number, delay: number, action: string) {
onError: createOnErrorCb(ac),
});
- await listeningPromise;
- const resp = await fetch(`http://127.0.0.1:${servePort}/`);
- const text = await resp.text();
+ try {
+ await listeningPromise;
+ const resp = await fetch(`http://127.0.0.1:${servePort}/`);
+ if (action == "Throw") {
+ try {
+ await resp.text();
+ fail();
+ } catch (_) {
+ // expected
+ }
+ } else {
+ const text = await resp.text();
- ac.abort();
- await server.finished;
- let expected = "";
- if (action == "Throw" && count < 2 && delay < 1000) {
- // NOTE: This is specific to the current implementation. In some cases where a stream errors, we
- // don't send the first packet.
- expected = "";
- } else {
- for (let i = 0; i < count; i++) {
- expected += `a${i}`;
+ let expected = "";
+ for (let i = 0; i < count; i++) {
+ expected += `a${i}`;
+ }
+
+ assertEquals(text, expected);
}
+ } finally {
+ ac.abort();
+ await server.finished;
}
-
- assertEquals(text, expected);
});
}