Skip to content

Commit

Permalink
chore: maybe fix ci
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret committed Jul 11, 2024
1 parent c9f3d72 commit f0d5c27
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 16 additions & 13 deletions utils/fetchCached.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.");
Expand All @@ -40,17 +43,17 @@ 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.");
}
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.");
Expand All @@ -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.");
Expand All @@ -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");
});
Expand Down

0 comments on commit f0d5c27

Please sign in to comment.