import { ChildProcess, exec, fork } from 'child_process'
import { join } from 'path'
+import { root, wait } from '../miscs/miscs'
+import { readFile } from 'fs-extra'
interface ServerInfo {
app: ChildProcess,
id: number
uuid: string
name: string
- accountName: string
+ account: {
+ name: string
+ }
}
remoteVideo?: {
}
}
-function flushAndRunMultipleServers (totalServers) {
+function flushAndRunMultipleServers (totalServers: number, configOverride?: Object) {
let apps = []
let i = 0
flushTests()
.then(() => {
for (let j = 1; j <= totalServers; j++) {
- // For the virtual buffer
- setTimeout(() => {
- runServer(j).then(app => anotherServerDone(j, app))
- }, 1000 * (j - 1))
+ runServer(j, configOverride).then(app => anotherServerDone(j, app))
}
})
})
// These actions are async so we need to be sure that they have both been done
const serverRunString = {
- 'Server listening on port': false
+ 'Server listening': false
}
const key = 'Database peertube_test' + serverNumber + ' is ready'
serverRunString[key] = false
})
}
+async function reRunServer (server: ServerInfo, configOverride?: any) {
+ const newServer = await runServer(server.serverNumber, configOverride)
+ server.app = newServer.app
+
+ return server
+}
+
function killallServers (servers: ServerInfo[]) {
for (const server of servers) {
process.kill(-server.app.pid)
}
}
+async function waitUntilLog (server: ServerInfo, str: string, count = 1) {
+ const logfile = join(root(), 'test' + server.serverNumber, 'logs/peertube.log')
+
+ while (true) {
+ const buf = await readFile(logfile)
+
+ const matches = buf.toString().match(new RegExp(str, 'g'))
+ if (matches && matches.length === count) return
+
+ await wait(1000)
+ }
+}
+
// ---------------------------------------------------------------------------
export {
flushAndRunMultipleServers,
flushTests,
runServer,
- killallServers
+ killallServers,
+ reRunServer,
+ waitUntilLog
}