diff options
Diffstat (limited to 'std/examples/tests')
-rw-r--r-- | std/examples/tests/curl_test.ts | 6 | ||||
-rw-r--r-- | std/examples/tests/echo_server_test.ts | 8 |
2 files changed, 9 insertions, 5 deletions
diff --git a/std/examples/tests/curl_test.ts b/std/examples/tests/curl_test.ts index bc413b23f..b23e73210 100644 --- a/std/examples/tests/curl_test.ts +++ b/std/examples/tests/curl_test.ts @@ -1,14 +1,16 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. import { serve } from "../../http/server.ts"; import { assertStrictEq } from "../../testing/asserts.ts"; +import { randomPort } from "../../http/test_util.ts"; +const port = randomPort(); Deno.test({ name: "[examples/curl] send a request to a specified url", // FIXME(bartlomieju): this test is leaking both resources and ops, // and causes interference with other tests ignore: true, fn: async () => { - const server = serve({ port: 8081 }); + const server = serve({ port }); (async (): Promise<void> => { for await (const req of server) { req.respond({ body: "Hello world" }); @@ -21,7 +23,7 @@ Deno.test({ Deno.execPath(), "--allow-net", "curl.ts", - "http://localhost:8081" + "http://localhost:" + port ], cwd: "examples", stdout: "piped" diff --git a/std/examples/tests/echo_server_test.ts b/std/examples/tests/echo_server_test.ts index 20fd7479c..3c1893342 100644 --- a/std/examples/tests/echo_server_test.ts +++ b/std/examples/tests/echo_server_test.ts @@ -1,12 +1,14 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. import { assertStrictEq, assertNotEquals } from "../../testing/asserts.ts"; import { BufReader, ReadLineResult } from "../../io/bufio.ts"; +import { randomPort } from "../../http/test_util.ts"; +const port = randomPort(); Deno.test("[examples/echo_server]", async () => { const encoder = new TextEncoder(); const decoder = new TextDecoder(); const process = Deno.run({ - args: [Deno.execPath(), "--allow-net", "echo_server.ts"], + args: [Deno.execPath(), "--allow-net", "echo_server.ts", `${port}`], cwd: "examples", stdout: "piped" }); @@ -19,10 +21,10 @@ Deno.test("[examples/echo_server]", async () => { assertNotEquals(message, Deno.EOF); assertStrictEq( decoder.decode((message as ReadLineResult).line).trim(), - "Listening on 0.0.0.0:8080" + "Listening on 0.0.0.0:" + port ); - conn = await Deno.connect({ hostname: "127.0.0.1", port: 8080 }); + conn = await Deno.connect({ hostname: "127.0.0.1", port }); const connReader = new BufReader(conn); await conn.write(encoder.encode("Hello echo_server\n")); |