2021-07-16 09:47:51 +02:00
|
|
|
import { ensureDir } from 'fs-extra'
|
|
|
|
import { isGithubCI } from '../miscs'
|
|
|
|
import { PeerTubeServer, RunServerOptions } from './server'
|
2018-12-11 09:16:41 +01:00
|
|
|
|
2021-07-22 12:07:26 +02:00
|
|
|
async function createSingleServer (serverNumber: number, configOverride?: Object, options: RunServerOptions = {}) {
|
2021-07-16 09:47:51 +02:00
|
|
|
const server = new PeerTubeServer({ serverNumber })
|
2017-09-04 21:21:47 +02:00
|
|
|
|
2021-07-22 12:07:26 +02:00
|
|
|
await server.flushAndRun(configOverride, options)
|
2020-11-02 15:43:44 +01:00
|
|
|
|
2021-07-16 09:47:51 +02:00
|
|
|
return server
|
2019-04-24 14:00:30 +02:00
|
|
|
}
|
|
|
|
|
2021-08-17 08:26:20 +02:00
|
|
|
function createMultipleServers (totalServers: number, configOverride?: Object, options: RunServerOptions = {}) {
|
2021-07-16 09:47:51 +02:00
|
|
|
const serverPromises: Promise<PeerTubeServer>[] = []
|
2019-04-24 11:54:23 +02:00
|
|
|
|
2021-07-16 09:47:51 +02:00
|
|
|
for (let i = 1; i <= totalServers; i++) {
|
2021-08-17 08:26:20 +02:00
|
|
|
serverPromises.push(createSingleServer(i, configOverride, options))
|
2017-09-04 21:21:47 +02:00
|
|
|
}
|
|
|
|
|
2021-07-16 09:47:51 +02:00
|
|
|
return Promise.all(serverPromises)
|
2018-01-11 11:40:18 +01:00
|
|
|
}
|
|
|
|
|
2021-07-16 09:47:51 +02:00
|
|
|
async function killallServers (servers: PeerTubeServer[]) {
|
|
|
|
return Promise.all(servers.map(s => s.kill()))
|
2017-09-04 21:21:47 +02:00
|
|
|
}
|
|
|
|
|
2021-07-16 09:47:51 +02:00
|
|
|
async function cleanupTests (servers: PeerTubeServer[]) {
|
2021-07-09 15:37:43 +02:00
|
|
|
await killallServers(servers)
|
2019-04-24 11:54:23 +02:00
|
|
|
|
2020-12-10 11:24:17 +01:00
|
|
|
if (isGithubCI()) {
|
|
|
|
await ensureDir('artifacts')
|
|
|
|
}
|
|
|
|
|
2021-07-13 09:43:59 +02:00
|
|
|
let p: Promise<any>[] = []
|
2019-04-24 11:54:23 +02:00
|
|
|
for (const server of servers) {
|
2021-07-16 09:04:35 +02:00
|
|
|
p = p.concat(server.servers.cleanupTests())
|
2019-04-24 11:54:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return Promise.all(p)
|
|
|
|
}
|
|
|
|
|
2017-09-04 21:21:47 +02:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
2021-07-16 09:47:51 +02:00
|
|
|
createSingleServer,
|
|
|
|
createMultipleServers,
|
2019-04-24 11:54:23 +02:00
|
|
|
cleanupTests,
|
2021-07-16 09:47:51 +02:00
|
|
|
killallServers
|
2017-09-04 21:21:47 +02:00
|
|
|
}
|