diff options
Diffstat (limited to 'shared/server-commands/server/servers.ts')
-rw-r--r-- | shared/server-commands/server/servers.ts | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/shared/server-commands/server/servers.ts b/shared/server-commands/server/servers.ts new file mode 100644 index 000000000..21ab9405b --- /dev/null +++ b/shared/server-commands/server/servers.ts | |||
@@ -0,0 +1,49 @@ | |||
1 | import { ensureDir } from 'fs-extra' | ||
2 | import { isGithubCI } from '../miscs' | ||
3 | import { PeerTubeServer, RunServerOptions } from './server' | ||
4 | |||
5 | async function createSingleServer (serverNumber: number, configOverride?: Object, options: RunServerOptions = {}) { | ||
6 | const server = new PeerTubeServer({ serverNumber }) | ||
7 | |||
8 | await server.flushAndRun(configOverride, options) | ||
9 | |||
10 | return server | ||
11 | } | ||
12 | |||
13 | function createMultipleServers (totalServers: number, configOverride?: Object, options: RunServerOptions = {}) { | ||
14 | const serverPromises: Promise<PeerTubeServer>[] = [] | ||
15 | |||
16 | for (let i = 1; i <= totalServers; i++) { | ||
17 | serverPromises.push(createSingleServer(i, configOverride, options)) | ||
18 | } | ||
19 | |||
20 | return Promise.all(serverPromises) | ||
21 | } | ||
22 | |||
23 | async function killallServers (servers: PeerTubeServer[]) { | ||
24 | return Promise.all(servers.map(s => s.kill())) | ||
25 | } | ||
26 | |||
27 | async function cleanupTests (servers: PeerTubeServer[]) { | ||
28 | await killallServers(servers) | ||
29 | |||
30 | if (isGithubCI()) { | ||
31 | await ensureDir('artifacts') | ||
32 | } | ||
33 | |||
34 | let p: Promise<any>[] = [] | ||
35 | for (const server of servers) { | ||
36 | p = p.concat(server.servers.cleanupTests()) | ||
37 | } | ||
38 | |||
39 | return Promise.all(p) | ||
40 | } | ||
41 | |||
42 | // --------------------------------------------------------------------------- | ||
43 | |||
44 | export { | ||
45 | createSingleServer, | ||
46 | createMultipleServers, | ||
47 | cleanupTests, | ||
48 | killallServers | ||
49 | } | ||