summaryrefslogtreecommitdiff
path: root/std/examples/chat/server_test.ts
diff options
context:
space:
mode:
authorYusuke Sakurai <kerokerokerop@gmail.com>2020-03-21 22:53:47 +0900
committerGitHub <noreply@github.com>2020-03-21 09:53:47 -0400
commit60cee4f045778777a16b6fffd6d5b9a1400d7246 (patch)
treea477bd147fbd548d478a289af5bd0681b1a34c4e /std/examples/chat/server_test.ts
parent0adc86f105204b2475126c36dfc10e678f67df56 (diff)
avoid using same port number for test (#4147)
Diffstat (limited to 'std/examples/chat/server_test.ts')
-rw-r--r--std/examples/chat/server_test.ts15
1 files changed, 12 insertions, 3 deletions
diff --git a/std/examples/chat/server_test.ts b/std/examples/chat/server_test.ts
index 0d21b3787..65e0b5958 100644
--- a/std/examples/chat/server_test.ts
+++ b/std/examples/chat/server_test.ts
@@ -3,13 +3,22 @@ import { assert, assertEquals } from "../../testing/asserts.ts";
import { TextProtoReader } from "../../textproto/mod.ts";
import { BufReader } from "../../io/bufio.ts";
import { connectWebSocket, WebSocket } from "../../ws/mod.ts";
+import { randomPort } from "../../http/test_util.ts";
import { delay } from "../../util/async.ts";
+const port = randomPort();
+
const { test, build } = Deno;
async function startServer(): Promise<Deno.Process> {
const server = Deno.run({
- args: [Deno.execPath(), "--allow-net", "--allow-read", "server.ts"],
+ args: [
+ Deno.execPath(),
+ "--allow-net",
+ "--allow-read",
+ "server.ts",
+ `127.0.0.1:${port}`
+ ],
cwd: "examples/chat",
stdout: "piped"
});
@@ -35,7 +44,7 @@ test({
async fn() {
const server = await startServer();
try {
- const resp = await fetch("http://127.0.0.1:8080/");
+ const resp = await fetch(`http://127.0.0.1:${port}/`);
assertEquals(resp.status, 200);
assertEquals(resp.headers.get("content-type"), "text/html");
const html = await resp.body.text();
@@ -55,7 +64,7 @@ test({
const server = await startServer();
let ws: WebSocket | undefined;
try {
- ws = await connectWebSocket("http://127.0.0.1:8080/ws");
+ ws = await connectWebSocket(`http://127.0.0.1:${port}/ws`);
const it = ws.receive();
assertEquals((await it.next()).value, "Connected: [1]");
ws.send("Hello");