diff options
author | Yusuke Sakurai <kerokerokerop@gmail.com> | 2020-03-21 22:53:47 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-21 09:53:47 -0400 |
commit | 60cee4f045778777a16b6fffd6d5b9a1400d7246 (patch) | |
tree | a477bd147fbd548d478a289af5bd0681b1a34c4e /cli/js/tests/test_util.ts | |
parent | 0adc86f105204b2475126c36dfc10e678f67df56 (diff) |
avoid using same port number for test (#4147)
Diffstat (limited to 'cli/js/tests/test_util.ts')
-rw-r--r-- | cli/js/tests/test_util.ts | 18 |
1 files changed, 18 insertions, 0 deletions
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<number> { + // 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; +} |