diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ba81e1a..4122280 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,7 +10,7 @@ jobs: contents: read steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: denoland/setup-deno@v1 with: deno-version: v1.x diff --git a/utils/fetchCached.test.ts b/utils/fetchCached.test.ts index e90cc70..b2d2076 100644 --- a/utils/fetchCached.test.ts +++ b/utils/fetchCached.test.ts @@ -9,7 +9,7 @@ Deno.test("should error when going above 10mb", async (t) => { }, }; const { fetchCached } = createFetchCacher(clock); - await using _server = Deno.serve({ port: 8040 }, (request) => { + await using server = Deno.serve((request) => { if (request.url.endsWith("large")) { return new Response(new Uint8Array(11 * 1024 * 1024).buffer, { status: 200, @@ -25,11 +25,14 @@ Deno.test("should error when going above 10mb", async (t) => { } }); + const addr = server.addr.hostname + ":" + server.addr.port; + console.log("Listening at ", addr); + // large await t.step("should error going above 10mb", async () => { const response = await fetchCached({ - url: `http://localhost:8040/large`, - hostname: "127.0.0.1", + url: `http://${addr}/large`, + hostname: server.addr.hostname, }); if (response.kind !== "error") { throw new Error("Expected error."); @@ -40,8 +43,8 @@ Deno.test("should error when going above 10mb", async (t) => { // small await t.step("should not error below 10mb", async () => { const response = await fetchCached({ - url: `http://localhost:8040/small`, - hostname: "127.0.0.1", + url: `http://${addr}/small`, + hostname: server.addr.hostname, }); if (response.kind !== "success") { throw new Error("Expected error."); @@ -49,8 +52,8 @@ Deno.test("should error when going above 10mb", async (t) => { assertEquals(response.body.byteLength, 9 * 1024 * 1024); const response2 = await fetchCached({ - url: `http://localhost:8040/small`, - hostname: "127.0.0.1", + url: `http://${addr}/small`, + hostname: server.addr.hostname, }); if (response.body !== response2.body) { throw new Error("Should have been the same objects."); @@ -60,15 +63,15 @@ Deno.test("should error when going above 10mb", async (t) => { await t.step("should error after 20 downloads because of rate limiting", async () => { for (let i = 0; i < 19; i++) { const response = await fetchCached({ - url: `http://localhost:8040/small`, - hostname: "127.0.0.1", + url: `http://${addr}/small`, + hostname: server.addr.hostname, }); assertEquals(response.kind, "success"); } let response = await fetchCached({ - url: `http://localhost:8040/small`, - hostname: "127.0.0.1", + url: `http://${addr}/small`, + hostname: server.addr.hostname, }); if (response.kind !== "error") { throw new Error("Was not error."); @@ -77,8 +80,8 @@ Deno.test("should error when going above 10mb", async (t) => { // advance time and it should work again time += 61 * 1000; response = await fetchCached({ - url: `http://localhost:8040/small`, - hostname: "127.0.0.1", + url: `http://${addr}/small`, + hostname: server.addr.hostname, }); assertEquals(response.kind, "success"); });