summaryrefslogtreecommitdiff
path: root/std/http/test_util.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/http/test_util.ts
parent0adc86f105204b2475126c36dfc10e678f67df56 (diff)
avoid using same port number for test (#4147)
Diffstat (limited to 'std/http/test_util.ts')
-rw-r--r--std/http/test_util.ts20
1 files changed, 20 insertions, 0 deletions
diff --git a/std/http/test_util.ts b/std/http/test_util.ts
new file mode 100644
index 000000000..c86a339a7
--- /dev/null
+++ b/std/http/test_util.ts
@@ -0,0 +1,20 @@
+import { assert } from "../testing/asserts.ts";
+
+function* portIterator(): IterableIterator<number> {
+ // use 55001 ~ 65535 (rest (49152~55000) are for cli/js)
+ let i = 55001;
+ while (true) {
+ yield i;
+ i++;
+ if (i > 65535) {
+ i = 55001;
+ }
+ }
+}
+const it = portIterator();
+/** Obtain (maybe) safe port number for net tests */
+export function randomPort(): number {
+ const { value } = it.next();
+ assert(value != null);
+ return value;
+}