1
0
Fork 0
peertube/shared/extra-utils/server/servers.ts
2021-07-20 15:27:18 +02:00

49 lines
1.2 KiB
TypeScript

import { ensureDir } from 'fs-extra'
import { isGithubCI } from '../miscs'
import { PeerTubeServer, RunServerOptions } from './server'
async function createSingleServer (serverNumber: number, configOverride?: Object, args = [], options: RunServerOptions = {}) {
const server = new PeerTubeServer({ serverNumber })
await server.flushAndRun(configOverride, args, options)
return server
}
function createMultipleServers (totalServers: number, configOverride?: Object) {
const serverPromises: Promise<PeerTubeServer>[] = []
for (let i = 1; i <= totalServers; i++) {
serverPromises.push(createSingleServer(i, configOverride))
}
return Promise.all(serverPromises)
}
async function killallServers (servers: PeerTubeServer[]) {
return Promise.all(servers.map(s => s.kill()))
}
async function cleanupTests (servers: PeerTubeServer[]) {
await killallServers(servers)
if (isGithubCI()) {
await ensureDir('artifacts')
}
let p: Promise<any>[] = []
for (const server of servers) {
p = p.concat(server.servers.cleanupTests())
}
return Promise.all(p)
}
// ---------------------------------------------------------------------------
export {
createSingleServer,
createMultipleServers,
cleanupTests,
killallServers
}