From 9c8aa11deaee710b1e139842d136763b36c637ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Tue, 22 Jun 2021 18:39:44 +0200 Subject: [PATCH] Choose test server port in a range To fix random test failures --- config/run.flags | 1 + config/test.flags | 1 + run | 19 +++++++++++++++++++ server.ts | 6 +++--- testing.ts | 8 ++++---- 5 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 config/run.flags create mode 100644 config/test.flags create mode 100755 run diff --git a/config/run.flags b/config/run.flags new file mode 100644 index 0000000..e64d5d1 --- /dev/null +++ b/config/run.flags @@ -0,0 +1 @@ +--allow-read --allow-net --location https://rs.thunderk.net/ \ No newline at end of file diff --git a/config/test.flags b/config/test.flags new file mode 100644 index 0000000..cf1bd0d --- /dev/null +++ b/config/test.flags @@ -0,0 +1 @@ +--allow-read --allow-net --location https://test.rs.thunderk.net/ \ No newline at end of file diff --git a/run b/run new file mode 100755 index 0000000..74d1c6d --- /dev/null +++ b/run @@ -0,0 +1,19 @@ +#!/bin/sh +# Simplified run tool for deno commands + +if test $# -eq 0 +then + echo "Usage: $0 [file or command]" + exit 1 +elif echo $1 | grep -q '.*.ts' +then + denocmd=run + denoargs=$1 + shift +else + denocmd=$1 + shift +fi + +denoargs="$(cat config/$denocmd.flags 2> /dev/null) $denoargs $@" +exec deno $denocmd $denoargs diff --git a/server.ts b/server.ts index 6fadaa6..fef7381 100755 --- a/server.ts +++ b/server.ts @@ -1,8 +1,8 @@ -#!/usr/bin/env -S deno run --allow-read --allow-net -import { getLocalStorage } from "./mod.ts"; +#!./run import { KeyValueStorage } from "./basic.ts"; -import { HEADER_REPLYIER, HEADER_REQUESTER } from "./remote.ts"; import { json, opine, opineCors, readAll } from "./deps.ts"; +import { getLocalStorage } from "./mod.ts"; +import { HEADER_REPLYIER, HEADER_REQUESTER } from "./remote.ts"; const PORT = 5001; diff --git a/testing.ts b/testing.ts index 82066e7..4b6de5e 100644 --- a/testing.ts +++ b/testing.ts @@ -1,12 +1,12 @@ -import { KeyValueStorage, MemoryStorage } from "./basic.ts"; import { expect } from "https://code.thunderk.net/typescript/devtools/raw/1.2.2/testing.ts"; +import { getAvailablePort } from "https://deno.land/x/port@1.0.0/mod.ts"; +import { KeyValueStorage, MemoryStorage } from "./basic.ts"; +import { startRestServer } from "./server.ts"; export { describe, expect, it, } from "https://code.thunderk.net/typescript/devtools/raw/1.2.2/testing.ts"; -import { getAvailablePort } from "https://deno.land/x/port@1.0.0/mod.ts"; -import { startRestServer } from "./server.ts"; /** * Basic high-level test suite for any kind storage @@ -43,7 +43,7 @@ export async function disableLocalStorage( export async function runTestServer( body: (url: string) => Promise, ): Promise { - const port = await getAvailablePort(); + const port = await getAvailablePort({ port: { start: 3000, end: 30000 } }); if (!port) { throw new Error("No port available for test server"); }