From 48f07b4a4091cb10dc4d179118e155f3a118dca8 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 26 Apr 2019 08:50:52 +0200 Subject: All API tests in parallel --- shared/extra-utils/miscs/sql.ts | 35 ++++++++++++++-------------- shared/extra-utils/server/servers.ts | 2 +- shared/extra-utils/videos/video-playlists.ts | 4 ++-- shared/extra-utils/videos/videos.ts | 4 ++-- 4 files changed, 23 insertions(+), 22 deletions(-) (limited to 'shared') diff --git a/shared/extra-utils/miscs/sql.ts b/shared/extra-utils/miscs/sql.ts index 3cfae5c23..34477cb78 100644 --- a/shared/extra-utils/miscs/sql.ts +++ b/shared/extra-utils/miscs/sql.ts @@ -1,11 +1,12 @@ import { QueryTypes, Sequelize } from 'sequelize' +import { ServerInfo } from '../server/servers' let sequelizes: { [ id: number ]: Sequelize } = {} -function getSequelize (serverNumber: number) { - if (sequelizes[serverNumber]) return sequelizes[serverNumber] +function getSequelize (internalServerNumber: number) { + if (sequelizes[internalServerNumber]) return sequelizes[internalServerNumber] - const dbname = 'peertube_test' + serverNumber + const dbname = 'peertube_test' + internalServerNumber const username = 'peertube' const password = 'peertube' const host = 'localhost' @@ -18,37 +19,37 @@ function getSequelize (serverNumber: number) { logging: false }) - sequelizes[serverNumber] = seq + sequelizes[internalServerNumber] = seq return seq } -function setActorField (serverNumber: number, to: string, field: string, value: string) { - const seq = getSequelize(serverNumber) +function setActorField (internalServerNumber: number, to: string, field: string, value: string) { + const seq = getSequelize(internalServerNumber) const options = { type: QueryTypes.UPDATE } return seq.query(`UPDATE actor SET "${field}" = '${value}' WHERE url = '${to}'`, options) } -function setVideoField (serverNumber: number, uuid: string, field: string, value: string) { - const seq = getSequelize(serverNumber) +function setVideoField (internalServerNumber: number, uuid: string, field: string, value: string) { + const seq = getSequelize(internalServerNumber) const options = { type: QueryTypes.UPDATE } return seq.query(`UPDATE video SET "${field}" = '${value}' WHERE uuid = '${uuid}'`, options) } -function setPlaylistField (serverNumber: number, uuid: string, field: string, value: string) { - const seq = getSequelize(serverNumber) +function setPlaylistField (internalServerNumber: number, uuid: string, field: string, value: string) { + const seq = getSequelize(internalServerNumber) const options = { type: QueryTypes.UPDATE } return seq.query(`UPDATE "videoPlaylist" SET "${field}" = '${value}' WHERE uuid = '${uuid}'`, options) } -async function countVideoViewsOf (serverNumber: number, uuid: string) { - const seq = getSequelize(serverNumber) +async function countVideoViewsOf (internalServerNumber: number, uuid: string) { + const seq = getSequelize(internalServerNumber) // tslint:disable const query = `SELECT SUM("videoView"."views") AS "total" FROM "videoView" INNER JOIN "video" ON "video"."id" = "videoView"."videoId" WHERE "video"."uuid" = '${uuid}'` @@ -62,11 +63,11 @@ async function countVideoViewsOf (serverNumber: number, uuid: string) { return parseInt(total + '', 10) } -async function closeAllSequelize (servers: any[]) { - for (let i = 1; i <= servers.length; i++) { - if (sequelizes[ i ]) { - await sequelizes[ i ].close() - delete sequelizes[ i ] +async function closeAllSequelize (servers: ServerInfo[]) { + for (const server of servers) { + if (sequelizes[ server.internalServerNumber ]) { + await sequelizes[ server.internalServerNumber ].close() + delete sequelizes[ server.internalServerNumber ] } } } diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index 3992735e1..4c7d6862a 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts @@ -246,7 +246,7 @@ async function checkTmpIsEmpty (server: ServerInfo) { } async function checkDirectoryIsEmpty (server: ServerInfo, directory: string) { - const testDirectory = 'test' + server.serverNumber + const testDirectory = 'test' + server.internalServerNumber const directoryPath = join(root(), testDirectory, directory) diff --git a/shared/extra-utils/videos/video-playlists.ts b/shared/extra-utils/videos/video-playlists.ts index 4d110a131..fd62bef19 100644 --- a/shared/extra-utils/videos/video-playlists.ts +++ b/shared/extra-utils/videos/video-playlists.ts @@ -252,10 +252,10 @@ function reorderVideosPlaylist (options: { async function checkPlaylistFilesWereRemoved ( playlistUUID: string, - serverNumber: number, + internalServerNumber: number, directories = [ 'thumbnails' ] ) { - const testDirectory = 'test' + serverNumber + const testDirectory = 'test' + internalServerNumber for (const directory of directories) { const directoryPath = join(root(), testDirectory, directory) diff --git a/shared/extra-utils/videos/videos.ts b/shared/extra-utils/videos/videos.ts index b5a07b792..b64de2470 100644 --- a/shared/extra-utils/videos/videos.ts +++ b/shared/extra-utils/videos/videos.ts @@ -568,8 +568,8 @@ async function completeVideoCheck ( expect(file).not.to.be.undefined let extension = extname(attributes.fixture) - // Transcoding enabled on server 2, extension will always be .mp4 - if (attributes.account.host === 'localhost:9002') extension = '.mp4' + // Transcoding enabled: extension will always be .mp4 + if (attributes.files.length > 1) extension = '.mp4' const magnetUri = file.magnetUri expect(file.magnetUri).to.have.lengthOf.above(2) -- cgit v1.2.3