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