diff options
author | Chocobozzz <me@florianbigard.com> | 2021-10-22 14:31:38 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-10-22 14:31:38 +0200 |
commit | d1bfbdeb203b0e4f37e9468861c690171156ee29 (patch) | |
tree | 2a6051ef212b964eb2ded1021a625acd0ba32053 /shared/extra-utils/mock-servers/mock-proxy.ts | |
parent | 5480933b7f088bf099b25fb467faace814f0da58 (diff) | |
download | PeerTube-d1bfbdeb203b0e4f37e9468861c690171156ee29.tar.gz PeerTube-d1bfbdeb203b0e4f37e9468861c690171156ee29.tar.zst PeerTube-d1bfbdeb203b0e4f37e9468861c690171156ee29.zip |
Random listen for mocked servers
Diffstat (limited to 'shared/extra-utils/mock-servers/mock-proxy.ts')
-rw-r--r-- | shared/extra-utils/mock-servers/mock-proxy.ts | 7 |
1 files changed, 2 insertions, 5 deletions
diff --git a/shared/extra-utils/mock-servers/mock-proxy.ts b/shared/extra-utils/mock-servers/mock-proxy.ts index 8583250f3..75ac79055 100644 --- a/shared/extra-utils/mock-servers/mock-proxy.ts +++ b/shared/extra-utils/mock-servers/mock-proxy.ts | |||
@@ -1,18 +1,15 @@ | |||
1 | 1 | ||
2 | import { createServer, Server } from 'http' | 2 | import { createServer, Server } from 'http' |
3 | import proxy from 'proxy' | 3 | import proxy from 'proxy' |
4 | import { randomInt } from '@shared/core-utils' | 4 | import { getPort, terminateServer } from './utils' |
5 | import { terminateServer } from './utils' | ||
6 | 5 | ||
7 | class MockProxy { | 6 | class MockProxy { |
8 | private server: Server | 7 | private server: Server |
9 | 8 | ||
10 | initialize () { | 9 | initialize () { |
11 | return new Promise<number>(res => { | 10 | return new Promise<number>(res => { |
12 | const port = 46000 + randomInt(1, 1000) | ||
13 | |||
14 | this.server = proxy(createServer()) | 11 | this.server = proxy(createServer()) |
15 | this.server.listen(port, () => res(port)) | 12 | this.server.listen(0, () => res(getPort(this.server))) |
16 | }) | 13 | }) |
17 | } | 14 | } |
18 | 15 | ||