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