-
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stamp: add integration tests for idle timeout
- Loading branch information
1 parent
207df15
commit fd535ce
Showing
6 changed files
with
396 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
}); | ||
}); |
38 changes: 38 additions & 0 deletions
38
crates/base/test_cases/chunked-char-variable-delay-max-6000ms/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
19
crates/base/test_cases/websocket-upgrade-no-send-node/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); |
Oops, something went wrong.