Skip to content

Commit

Permalink
stamp: add integration tests for idle timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
nyannyacha committed May 13, 2024
1 parent 2bc5567 commit e45865a
Show file tree
Hide file tree
Showing 6 changed files with 396 additions and 1 deletion.
32 changes: 32 additions & 0 deletions crates/base/test_cases/chunked-char-first-6000ms/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
async function sleep(ms: number) {
return new Promise(res => {
setTimeout(() => {
res(void 0);
}, ms)
});
}

Deno.serve(() => {
const encoder = new TextEncoder();
const stream = new ReadableStream({
async start(controller) {
const input: [string, number][] = [
["m", 6000],
["e", 100],
];

for (const [char, wait] of input) {
await sleep(wait);
controller.enqueue(encoder.encode(char));
}

controller.close();
},
});

return new Response(stream, {
headers: {
"Content-Type": "text/plain"
}
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
async function sleep(ms: number) {
return new Promise(res => {
setTimeout(() => {
res(void 0);
}, ms)
});
}

Deno.serve(() => {
const encoder = new TextEncoder();
const stream = new ReadableStream({
async start(controller) {
const input: [string, number][] = [
["m", 500],
["e", 1000],
["o", 1000],
["w", 6000],
["m", 100],
["e", 100],
["o", 100],
["w", 600],
];

for (const [char, wait] of input) {
await sleep(wait);
controller.enqueue(encoder.encode(char));
}

controller.close();
},
});

return new Response(stream, {
headers: {
"Content-Type": "text/plain"
}
});
});
12 changes: 12 additions & 0 deletions crates/base/test_cases/sleep-5000ms/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
async function sleep(ms: number) {
return new Promise(res => {
setTimeout(() => {
res(void 0);
}, ms)
});
}

Deno.serve(async () => {
await sleep(5000);
return new Response("meow");
});
19 changes: 19 additions & 0 deletions crates/base/test_cases/websocket-upgrade-no-send-node/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { createServer } from "node:http";
import { WebSocketServer } from "npm:ws";

const server = createServer();
const wss = new WebSocketServer({ noServer: true });

wss.on("connection", ws => {
ws.on("message", data => {
ws.send(data.toString());
});
});

server.on("upgrade", (req, socket, head) => {
wss.handleUpgrade(req, socket, head, ws => {
wss.emit("connection", ws, req);
});
});

server.listen(8080);
9 changes: 9 additions & 0 deletions crates/base/test_cases/websocket-upgrade-no-send/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Deno.serve(async (req: Request) => {
const { socket, response } = Deno.upgradeWebSocket(req);

socket.onmessage = ev => {
socket.send(ev.data);
};

return response;
});
Loading

0 comments on commit e45865a

Please sign in to comment.