From 60cee4f045778777a16b6fffd6d5b9a1400d7246 Mon Sep 17 00:00:00 2001 From: Yusuke Sakurai Date: Sat, 21 Mar 2020 22:53:47 +0900 Subject: avoid using same port number for test (#4147) --- cli/js/tests/test_util.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'cli/js/tests/test_util.ts') diff --git a/cli/js/tests/test_util.ts b/cli/js/tests/test_util.ts index 980d32bac..347a2204e 100644 --- a/cli/js/tests/test_util.ts +++ b/cli/js/tests/test_util.ts @@ -359,3 +359,21 @@ unitTest( }); } ); +function* portIterator(): IterableIterator { + // use 49152 ~ 55000 for js/cli (rest are for std) + let i = 49152; + while (true) { + yield i; + i++; + if (i > 55000) { + i = 55000; + } + } +} +const it = portIterator(); +/** Obtain (maybe) safe port number for net tests */ +export function randomPort(): number { + const { value } = it.next(); + assert(value != null); + return value; +} -- cgit v1.2.3