Use parallel tests
This commit is contained in:
parent
5fb6996b81
commit
86ebdf8c46
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
import 'mocha'
|
import 'mocha'
|
||||||
|
|
||||||
import { flushTests, killallServers, flushAndRunServer, ServerInfo } from '../../../../shared/extra-utils'
|
import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../../shared/extra-utils'
|
||||||
import {
|
import {
|
||||||
checkBadCountPagination,
|
checkBadCountPagination,
|
||||||
checkBadSortPagination,
|
checkBadSortPagination,
|
||||||
|
@ -42,7 +42,7 @@ describe('Test accounts API validators', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
after(function () {
|
after(async function () {
|
||||||
killallServers([ server ])
|
await cleanupTests([ server ])
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -3,16 +3,16 @@
|
||||||
import 'mocha'
|
import 'mocha'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
cleanupTests,
|
||||||
createUser,
|
createUser,
|
||||||
doubleFollow,
|
doubleFollow,
|
||||||
flushAndRunMultipleServers,
|
flushAndRunMultipleServers,
|
||||||
flushTests,
|
|
||||||
killallServers,
|
|
||||||
makeDeleteRequest,
|
makeDeleteRequest,
|
||||||
makeGetRequest,
|
makeGetRequest,
|
||||||
makePostBodyRequest,
|
makePostBodyRequest,
|
||||||
ServerInfo,
|
ServerInfo,
|
||||||
setAccessTokensToServers, userLogin
|
setAccessTokensToServers,
|
||||||
|
userLogin
|
||||||
} from '../../../../shared/extra-utils'
|
} from '../../../../shared/extra-utils'
|
||||||
import {
|
import {
|
||||||
checkBadCountPagination,
|
checkBadCountPagination,
|
||||||
|
@ -190,7 +190,7 @@ describe('Test blocklist API validators', function () {
|
||||||
url: server.url,
|
url: server.url,
|
||||||
token: server.accessToken,
|
token: server.accessToken,
|
||||||
path,
|
path,
|
||||||
fields: { host: 'localhost:9001' },
|
fields: { host: 'localhost:' + server.port },
|
||||||
statusCodeExpected: 409
|
statusCodeExpected: 409
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -200,7 +200,7 @@ describe('Test blocklist API validators', function () {
|
||||||
url: server.url,
|
url: server.url,
|
||||||
token: server.accessToken,
|
token: server.accessToken,
|
||||||
path,
|
path,
|
||||||
fields: { host: 'localhost:9002' },
|
fields: { host: 'localhost:' + servers[1].port },
|
||||||
statusCodeExpected: 204
|
statusCodeExpected: 204
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -210,7 +210,7 @@ describe('Test blocklist API validators', function () {
|
||||||
it('Should fail with an unauthenticated user', async function () {
|
it('Should fail with an unauthenticated user', async function () {
|
||||||
await makeDeleteRequest({
|
await makeDeleteRequest({
|
||||||
url: server.url,
|
url: server.url,
|
||||||
path: path + '/localhost:9002',
|
path: path + '/localhost:' + servers[1].port,
|
||||||
statusCodeExpected: 401
|
statusCodeExpected: 401
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -227,7 +227,7 @@ describe('Test blocklist API validators', function () {
|
||||||
it('Should succeed with the correct params', async function () {
|
it('Should succeed with the correct params', async function () {
|
||||||
await makeDeleteRequest({
|
await makeDeleteRequest({
|
||||||
url: server.url,
|
url: server.url,
|
||||||
path: path + '/localhost:9002',
|
path: path + '/localhost:' + servers[1].port,
|
||||||
token: server.accessToken,
|
token: server.accessToken,
|
||||||
statusCodeExpected: 204
|
statusCodeExpected: 204
|
||||||
})
|
})
|
||||||
|
@ -400,7 +400,7 @@ describe('Test blocklist API validators', function () {
|
||||||
await makePostBodyRequest({
|
await makePostBodyRequest({
|
||||||
url: server.url,
|
url: server.url,
|
||||||
path,
|
path,
|
||||||
fields: { host: 'localhost:9002' },
|
fields: { host: 'localhost:' + servers[1].port },
|
||||||
statusCodeExpected: 401
|
statusCodeExpected: 401
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -410,7 +410,7 @@ describe('Test blocklist API validators', function () {
|
||||||
url: server.url,
|
url: server.url,
|
||||||
token: userAccessToken,
|
token: userAccessToken,
|
||||||
path,
|
path,
|
||||||
fields: { host: 'localhost:9002' },
|
fields: { host: 'localhost:' + servers[1].port },
|
||||||
statusCodeExpected: 403
|
statusCodeExpected: 403
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -430,7 +430,7 @@ describe('Test blocklist API validators', function () {
|
||||||
url: server.url,
|
url: server.url,
|
||||||
token: server.accessToken,
|
token: server.accessToken,
|
||||||
path,
|
path,
|
||||||
fields: { host: 'localhost:9001' },
|
fields: { host: 'localhost:' + server.port },
|
||||||
statusCodeExpected: 409
|
statusCodeExpected: 409
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -440,7 +440,7 @@ describe('Test blocklist API validators', function () {
|
||||||
url: server.url,
|
url: server.url,
|
||||||
token: server.accessToken,
|
token: server.accessToken,
|
||||||
path,
|
path,
|
||||||
fields: { host: 'localhost:9002' },
|
fields: { host: 'localhost:' + servers[1].port },
|
||||||
statusCodeExpected: 204
|
statusCodeExpected: 204
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -450,7 +450,7 @@ describe('Test blocklist API validators', function () {
|
||||||
it('Should fail with an unauthenticated user', async function () {
|
it('Should fail with an unauthenticated user', async function () {
|
||||||
await makeDeleteRequest({
|
await makeDeleteRequest({
|
||||||
url: server.url,
|
url: server.url,
|
||||||
path: path + '/localhost:9002',
|
path: path + '/localhost:' + servers[1].port,
|
||||||
statusCodeExpected: 401
|
statusCodeExpected: 401
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -458,7 +458,7 @@ describe('Test blocklist API validators', function () {
|
||||||
it('Should fail with a user without the appropriate rights', async function () {
|
it('Should fail with a user without the appropriate rights', async function () {
|
||||||
await makeDeleteRequest({
|
await makeDeleteRequest({
|
||||||
url: server.url,
|
url: server.url,
|
||||||
path: path + '/localhost:9002',
|
path: path + '/localhost:' + servers[1].port,
|
||||||
token: userAccessToken,
|
token: userAccessToken,
|
||||||
statusCodeExpected: 403
|
statusCodeExpected: 403
|
||||||
})
|
})
|
||||||
|
@ -476,7 +476,7 @@ describe('Test blocklist API validators', function () {
|
||||||
it('Should succeed with the correct params', async function () {
|
it('Should succeed with the correct params', async function () {
|
||||||
await makeDeleteRequest({
|
await makeDeleteRequest({
|
||||||
url: server.url,
|
url: server.url,
|
||||||
path: path + '/localhost:9002',
|
path: path + '/localhost:' + servers[1].port,
|
||||||
token: server.accessToken,
|
token: server.accessToken,
|
||||||
statusCodeExpected: 204
|
statusCodeExpected: 204
|
||||||
})
|
})
|
||||||
|
@ -485,7 +485,7 @@ describe('Test blocklist API validators', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
after(function () {
|
after(async function () {
|
||||||
killallServers(servers)
|
await cleanupTests(servers)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -12,6 +12,10 @@ interface ServerInfo {
|
||||||
app: ChildProcess,
|
app: ChildProcess,
|
||||||
url: string
|
url: string
|
||||||
host: string
|
host: string
|
||||||
|
|
||||||
|
port: number
|
||||||
|
parallel: boolean
|
||||||
|
internalServerNumber: number
|
||||||
serverNumber: number
|
serverNumber: number
|
||||||
|
|
||||||
client: {
|
client: {
|
||||||
|
@ -76,12 +80,27 @@ function flushTests (serverNumber?: number) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function flushAndRunServer (serverNumber: number, configOverride?: Object, args = []) {
|
function randomServer () {
|
||||||
|
const low = 10
|
||||||
|
const high = 10000
|
||||||
|
|
||||||
|
return Math.floor(Math.random() * (high - low) + low)
|
||||||
|
}
|
||||||
|
|
||||||
|
function flushAndRunServer (serverNumber: number, configOverrideArg?: Object, args = []) {
|
||||||
|
const parallel = process.env.MOCHA_PARALLEL === 'true'
|
||||||
|
|
||||||
|
const internalServerNumber = parallel ? randomServer() : serverNumber
|
||||||
|
const port = 9000 + internalServerNumber
|
||||||
|
|
||||||
const server: ServerInfo = {
|
const server: ServerInfo = {
|
||||||
app: null,
|
app: null,
|
||||||
serverNumber: serverNumber,
|
port,
|
||||||
url: `http://localhost:${9000 + serverNumber}`,
|
internalServerNumber,
|
||||||
host: `localhost:${9000 + serverNumber}`,
|
parallel,
|
||||||
|
serverNumber: internalServerNumber,
|
||||||
|
url: `http://localhost:${port}`,
|
||||||
|
host: `localhost:${port}`,
|
||||||
client: {
|
client: {
|
||||||
id: null,
|
id: null,
|
||||||
secret: null
|
secret: null
|
||||||
|
@ -96,7 +115,7 @@ function flushAndRunServer (serverNumber: number, configOverride?: Object, args
|
||||||
const serverRunString = {
|
const serverRunString = {
|
||||||
'Server listening': false
|
'Server listening': false
|
||||||
}
|
}
|
||||||
const key = 'Database peertube_test' + serverNumber + ' is ready'
|
const key = 'Database peertube_test' + internalServerNumber + ' is ready'
|
||||||
serverRunString[key] = false
|
serverRunString[key] = false
|
||||||
|
|
||||||
const regexps = {
|
const regexps = {
|
||||||
|
@ -111,10 +130,44 @@ function flushAndRunServer (serverNumber: number, configOverride?: Object, args
|
||||||
env['NODE_ENV'] = 'test'
|
env['NODE_ENV'] = 'test'
|
||||||
env['NODE_APP_INSTANCE'] = serverNumber.toString()
|
env['NODE_APP_INSTANCE'] = serverNumber.toString()
|
||||||
|
|
||||||
if (configOverride !== undefined) {
|
let configOverride: any = {}
|
||||||
env['NODE_CONFIG'] = JSON.stringify(configOverride)
|
|
||||||
|
if (parallel) {
|
||||||
|
configOverride = {
|
||||||
|
listen: {
|
||||||
|
port: port
|
||||||
|
},
|
||||||
|
webserver: {
|
||||||
|
port: port
|
||||||
|
},
|
||||||
|
database: {
|
||||||
|
suffix: '_test' + internalServerNumber
|
||||||
|
},
|
||||||
|
storage: {
|
||||||
|
tmp: `test${internalServerNumber}/tmp/`,
|
||||||
|
avatars: `test${internalServerNumber}/avatars/`,
|
||||||
|
videos: `test${internalServerNumber}/videos/`,
|
||||||
|
streaming_playlists: `test${internalServerNumber}/streaming-playlists/`,
|
||||||
|
redundancy: `test${internalServerNumber}/redundancy/`,
|
||||||
|
logs: `test${internalServerNumber}/logs/`,
|
||||||
|
previews: `test${internalServerNumber}/previews/`,
|
||||||
|
thumbnails: `test${internalServerNumber}/thumbnails/`,
|
||||||
|
torrents: `test${internalServerNumber}/torrents/`,
|
||||||
|
captions: `test${internalServerNumber}/captions/`,
|
||||||
|
cache: `test${internalServerNumber}/cache/`
|
||||||
|
},
|
||||||
|
admin: {
|
||||||
|
email: `admin${internalServerNumber}@example.com`
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (configOverrideArg !== undefined) {
|
||||||
|
Object.assign(configOverride, configOverrideArg)
|
||||||
|
}
|
||||||
|
|
||||||
|
env['NODE_CONFIG'] = JSON.stringify(configOverride)
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
silent: true,
|
silent: true,
|
||||||
env: env,
|
env: env,
|
||||||
|
@ -122,7 +175,7 @@ function flushAndRunServer (serverNumber: number, configOverride?: Object, args
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Promise<ServerInfo>(res => {
|
return new Promise<ServerInfo>(res => {
|
||||||
flushTests(serverNumber)
|
flushTests(internalServerNumber)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
|
||||||
server.app = fork(join(root(), 'dist', 'server.js'), args, options)
|
server.app = fork(join(root(), 'dist', 'server.js'), args, options)
|
||||||
|
@ -155,8 +208,7 @@ function flushAndRunServer (serverNumber: number, configOverride?: Object, args
|
||||||
process.on('exit', () => {
|
process.on('exit', () => {
|
||||||
try {
|
try {
|
||||||
process.kill(server.app.pid)
|
process.kill(server.app.pid)
|
||||||
} catch { /* empty */
|
} catch { /* empty */ }
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
res(server)
|
res(server)
|
||||||
|
@ -194,6 +246,19 @@ function killallServers (servers: ServerInfo[]) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function cleanupTests (servers: ServerInfo[]) {
|
||||||
|
killallServers(servers)
|
||||||
|
|
||||||
|
const p: Promise<any>[] = []
|
||||||
|
for (const server of servers) {
|
||||||
|
if (server.parallel) {
|
||||||
|
p.push(flushTests(server.internalServerNumber))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Promise.all(p)
|
||||||
|
}
|
||||||
|
|
||||||
async function waitUntilLog (server: ServerInfo, str: string, count = 1) {
|
async function waitUntilLog (server: ServerInfo, str: string, count = 1) {
|
||||||
const logfile = join(root(), 'test' + server.serverNumber, 'logs/peertube.log')
|
const logfile = join(root(), 'test' + server.serverNumber, 'logs/peertube.log')
|
||||||
|
|
||||||
|
@ -213,6 +278,7 @@ export {
|
||||||
checkDirectoryIsEmpty,
|
checkDirectoryIsEmpty,
|
||||||
checkTmpIsEmpty,
|
checkTmpIsEmpty,
|
||||||
ServerInfo,
|
ServerInfo,
|
||||||
|
cleanupTests,
|
||||||
flushAndRunMultipleServers,
|
flushAndRunMultipleServers,
|
||||||
flushTests,
|
flushTests,
|
||||||
flushAndRunServer,
|
flushAndRunServer,
|
||||||
|
|
Loading…
Reference in New Issue