From da3a3ab6829107b3ed7f18dda42648dfde41871d Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 25 Apr 2019 09:46:02 +0200 Subject: [PATCH 1/5] Try parallel check params tests --- package.json | 1 + scripts/travis.sh | 2 +- server/tests/api/index-1.ts | 3 - server/tests/api/notifications/index.ts | 2 +- .../search-activitypub-video-channels.ts | 2 +- .../api/search/search-activitypub-videos.ts | 2 +- server/tests/api/search/search-videos.ts | 2 +- server/tests/api/travis-1.sh | 10 +++ yarn.lock | 77 ++++++++++++++++++- 9 files changed, 92 insertions(+), 9 deletions(-) delete mode 100644 server/tests/api/index-1.ts create mode 100644 server/tests/api/travis-1.sh diff --git a/package.json b/package.json index 1dbf33a0a..6f789c5bf 100644 --- a/package.json +++ b/package.json @@ -205,6 +205,7 @@ "maildev": "^1.0.0-rc3", "marked-man": "^0.4.2", "mocha": "^6.0.0", + "mocha-parallel-tests": "^2.1.0", "nodemon": "^1.18.6", "sass-lint": "^1.12.1", "source-map-support": "^0.5.0", diff --git a/scripts/travis.sh b/scripts/travis.sh index 3557816c8..67d8b5d7e 100755 --- a/scripts/travis.sh +++ b/scripts/travis.sh @@ -20,7 +20,7 @@ elif [ "$1" = "cli" ]; then mocha --timeout 5000 --exit --require ts-node/register --bail server/tests/cli/index.ts elif [ "$1" = "api-1" ]; then npm run build:server - mocha --timeout 5000 --exit --require ts-node/register --bail server/tests/api/index-1.ts + sh ./server/tests/api/travis-1.sh elif [ "$1" = "api-2" ]; then npm run build:server mocha --timeout 5000 --exit --require ts-node/register --bail server/tests/api/index-2.ts diff --git a/server/tests/api/index-1.ts b/server/tests/api/index-1.ts deleted file mode 100644 index 75cdd9025..000000000 --- a/server/tests/api/index-1.ts +++ /dev/null @@ -1,3 +0,0 @@ -import './check-params' -import './notifications' -import './search' diff --git a/server/tests/api/notifications/index.ts b/server/tests/api/notifications/index.ts index 95ac8fc51..b573f850e 100644 --- a/server/tests/api/notifications/index.ts +++ b/server/tests/api/notifications/index.ts @@ -1 +1 @@ -export * from './user-notifications' +import './user-notifications' diff --git a/server/tests/api/search/search-activitypub-video-channels.ts b/server/tests/api/search/search-activitypub-video-channels.ts index 4d1ceb767..70a077ffc 100644 --- a/server/tests/api/search/search-activitypub-video-channels.ts +++ b/server/tests/api/search/search-activitypub-video-channels.ts @@ -24,7 +24,7 @@ import { searchVideoChannel } from '../../../../shared/extra-utils/search/video- const expect = chai.expect -describe('Test a ActivityPub video channels search', function () { +describe('Test ActivityPub video channels search', function () { let servers: ServerInfo[] let userServer2Token: string let videoServer2UUID: string diff --git a/server/tests/api/search/search-activitypub-videos.ts b/server/tests/api/search/search-activitypub-videos.ts index e039961cb..e8e2b5a64 100644 --- a/server/tests/api/search/search-activitypub-videos.ts +++ b/server/tests/api/search/search-activitypub-videos.ts @@ -22,7 +22,7 @@ import { Video, VideoPrivacy } from '../../../../shared/models/videos' const expect = chai.expect -describe('Test a ActivityPub videos search', function () { +describe('Test ActivityPub videos search', function () { let servers: ServerInfo[] let videoServer1UUID: string let videoServer2UUID: string diff --git a/server/tests/api/search/search-videos.ts b/server/tests/api/search/search-videos.ts index 1a086b33a..22d3a5951 100644 --- a/server/tests/api/search/search-videos.ts +++ b/server/tests/api/search/search-videos.ts @@ -18,7 +18,7 @@ import { const expect = chai.expect -describe('Test a videos search', function () { +describe('Test videos search', function () { let server: ServerInfo = null let startDate: string diff --git a/server/tests/api/travis-1.sh b/server/tests/api/travis-1.sh new file mode 100644 index 000000000..e4761d2f9 --- /dev/null +++ b/server/tests/api/travis-1.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env sh + +set -eu + +files=$(find server/tests/api/check-params -type f | grep -v index.ts | xargs echo) + +MOCHA_PARALLEL=true mocha-parallel-tests --max-parallel 4 --timeout 5000 --exit --require ts-node/register --bail $files + +mocha --timeout 5000 --exit --require ts-node/register --bail server/tests/api/notifications/index.ts +mocha --timeout 5000 --exit --require ts-node/register --bail server/tests/api/search/index.ts diff --git a/yarn.lock b/yarn.lock index f2cc0ee05..f2dc8a9ec24 100644 --- a/yarn.lock +++ b/yarn.lock @@ -515,6 +515,11 @@ ansi-regex@^3.0.0: resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-3.0.0.tgz#ed0317c322064f79466c02966bddb605ab37d998" integrity sha1-7QMXwyIGT3lGbAKWa922Bas32Zg= +ansi-regex@^4.1.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-4.1.0.tgz#8b9f8f08cf1acb843756a839ca8c7e3168c51997" + integrity sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg== + ansi-styles@^2.2.1: version "2.2.1" resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-2.2.1.tgz#b432dd3358b634cf75e1e4664368240533c1ddbe" @@ -1446,6 +1451,11 @@ circular-json@^0.3.1: resolved "https://registry.yarnpkg.com/circular-json/-/circular-json-0.3.3.tgz#815c99ea84f6809529d2f45791bdf82711352d66" integrity sha512-UZK3NBx2Mca+b5LsG7bY183pHWt5Y1xts4P3Pz7ENTwGVnJOUWbRb3ocjvX7hx9tq/yTAdclXm9sZ38gNuem4A== +circular-json@^0.5.9: + version "0.5.9" + resolved "https://registry.yarnpkg.com/circular-json/-/circular-json-0.5.9.tgz#932763ae88f4f7dead7a0d09c8a51a4743a53b1d" + integrity sha512-4ivwqHpIFJZBuhN3g/pEcdbnGUywkBblloGbkglyloVjjR3uT6tieI89MVOfbP2tHX5sgb01FuLgAOzebNlJNQ== + class-utils@^0.3.5: version "0.3.6" resolved "https://registry.yarnpkg.com/class-utils/-/class-utils-0.3.6.tgz#f93369ae8b9a7ce02fd41faad0ca83033190c463" @@ -2322,6 +2332,11 @@ elliptic@=3.0.3: hash.js "^1.0.0" inherits "^2.0.1" +emoji-regex@^7.0.1: + version "7.0.3" + resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-7.0.3.tgz#933a04052860c85e83c122479c4748a8e4c72156" + integrity sha512-CwBLREIQ7LvYFB0WyRvwhq5N5qPhc6PMjD6bYggFlI5YyDgl+0vxq5VHbMOFqLg7hfWzmu8T5Z1QofhmTIhItA== + enabled@1.0.x: version "1.0.2" resolved "https://registry.yarnpkg.com/enabled/-/enabled-1.0.2.tgz#965f6513d2c2d1c5f4652b64a2e3396467fc2f93" @@ -3304,6 +3319,11 @@ get-caller-file@^1.0.1: resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-1.0.3.tgz#f978fa4c90d1dfe7ff2d6beda2a515e713bdcf4a" integrity sha512-3t6rVToeoZfYSGd8YoLFR2DJkiQrIiUrGcjvFX2mDw3bn6k2OtwHN0TNCLbBO+w8qTvimhDkv+LSscbJY1vE6w== +get-caller-file@^2.0.1: + version "2.0.5" + resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-2.0.5.tgz#4f94412a82db32f36e3b0b9741f8a97feb031f7e" + integrity sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg== + get-func-name@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/get-func-name/-/get-func-name-2.0.0.tgz#ead774abee72e20409433a066366023dd6887a41" @@ -5322,6 +5342,15 @@ mkdirp@0.5.1, mkdirp@0.x.x, "mkdirp@>=0.5 0", mkdirp@^0.5.0, mkdirp@^0.5.1, mkdi dependencies: minimist "0.0.8" +mocha-parallel-tests@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/mocha-parallel-tests/-/mocha-parallel-tests-2.1.0.tgz#94ab823b619b129fc347472f97c18595f0870c0e" + integrity sha512-NElZRp6T7kpis0mSkviPTwgIU13kkvazmmPPFLl/UqBeJoEjMj9tKz47qMV9kB0txURLoA1Rd/yDYqG1hlsKoA== + dependencies: + circular-json "^0.5.9" + debug "^4.1.1" + yargs "^13.2.2" + mocha@^6.0.0: version "6.0.2" resolved "https://registry.yarnpkg.com/mocha/-/mocha-6.0.2.tgz#cdc1a6fdf66472c079b5605bac59d29807702d2c" @@ -6170,7 +6199,7 @@ os-locale@^2.0.0: lcid "^1.0.0" mem "^1.1.0" -os-locale@^3.0.0: +os-locale@^3.0.0, os-locale@^3.1.0: version "3.1.0" resolved "https://registry.yarnpkg.com/os-locale/-/os-locale-3.1.0.tgz#a802a6ee17f24c10483ab9935719cef4ed16bf1a" integrity sha512-Z8l3R4wYWM40/52Z+S265okfFj8Kt2cC2MKY+xNi3kFs+XGI7WXu/I309QQQYbRW4ijiZ+yxs9pqEhJh0DqW3Q== @@ -7171,6 +7200,11 @@ require-main-filename@^1.0.1: resolved "https://registry.yarnpkg.com/require-main-filename/-/require-main-filename-1.0.1.tgz#97f717b69d48784f5f526a6c5aa8ffdda055a4d1" integrity sha1-l/cXtp1IeE9fUmpsWqj/3aBVpNE= +require-main-filename@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/require-main-filename/-/require-main-filename-2.0.0.tgz#d0b329ecc7cc0f61649f62215be69af54aa8989b" + integrity sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg== + require-uncached@^1.0.2: version "1.0.3" resolved "https://registry.yarnpkg.com/require-uncached/-/require-uncached-1.0.3.tgz#4e0d56d6c9662fd31e43011c4b95aa49955421d3" @@ -8136,6 +8170,15 @@ string-width@^1.0.1: is-fullwidth-code-point "^2.0.0" strip-ansi "^4.0.0" +string-width@^3.0.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/string-width/-/string-width-3.1.0.tgz#22767be21b62af1081574306f69ac51b62203961" + integrity sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w== + dependencies: + emoji-regex "^7.0.1" + is-fullwidth-code-point "^2.0.0" + strip-ansi "^5.1.0" + string2compact@^1.1.1, string2compact@^1.2.5: version "1.3.0" resolved "https://registry.yarnpkg.com/string2compact/-/string2compact-1.3.0.tgz#22d946127b082d1203c51316af60117a337423c3" @@ -8191,6 +8234,13 @@ strip-ansi@^4.0.0: dependencies: ansi-regex "^3.0.0" +strip-ansi@^5.1.0: + version "5.2.0" + resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-5.2.0.tgz#8c9a536feb6afc962bdfa5b104a5091c1ad9c0ae" + integrity sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA== + dependencies: + ansi-regex "^4.1.0" + strip-eof@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/strip-eof/-/strip-eof-1.0.0.tgz#bb43ff5598a6eb05d89b59fcd129c983313606bf" @@ -9315,6 +9365,14 @@ yargs-parser@11.1.1, yargs-parser@^11.1.1: camelcase "^5.0.0" decamelize "^1.2.0" +yargs-parser@^13.0.0: + version "13.0.0" + resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-13.0.0.tgz#3fc44f3e76a8bdb1cc3602e860108602e5ccde8b" + integrity sha512-w2LXjoL8oRdRQN+hOyppuXs+V/fVAYtpcrRxZuF7Kt/Oc+Jr2uAcVntaUTNT6w5ihoWfFDpNY8CPx1QskxZ/pw== + dependencies: + camelcase "^5.0.0" + decamelize "^1.2.0" + yargs-parser@^8.0.0: version "8.1.0" resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-8.1.0.tgz#f1376a33b6629a5d063782944da732631e966950" @@ -9374,6 +9432,23 @@ yargs@^11.0.0: y18n "^3.2.1" yargs-parser "^9.0.2" +yargs@^13.2.2: + version "13.2.2" + resolved "https://registry.yarnpkg.com/yargs/-/yargs-13.2.2.tgz#0c101f580ae95cea7f39d927e7770e3fdc97f993" + integrity sha512-WyEoxgyTD3w5XRpAQNYUB9ycVH/PQrToaTXdYXRdOXvEy1l19br+VJsc0vcO8PTGg5ro/l/GY7F/JMEBmI0BxA== + dependencies: + cliui "^4.0.0" + find-up "^3.0.0" + get-caller-file "^2.0.1" + os-locale "^3.1.0" + require-directory "^2.1.1" + require-main-filename "^2.0.0" + set-blocking "^2.0.0" + string-width "^3.0.0" + which-module "^2.0.0" + y18n "^4.0.0" + yargs-parser "^13.0.0" + yeast@0.1.2: version "0.1.2" resolved "https://registry.yarnpkg.com/yeast/-/yeast-0.1.2.tgz#008e06d8094320c372dbc2f8ed76a0ca6c8ac419" From 7243f84db0f34c6d5610a54603b0cce7c284a7b3 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 25 Apr 2019 17:14:49 +0200 Subject: [PATCH 2/5] Redundancy and search tests in parallel too --- .../api/notifications/user-notifications.ts | 41 +++++++------ server/tests/api/redundancy/redundancy.ts | 34 +++++++---- .../search-activitypub-video-channels.ts | 37 ++++++------ .../api/search/search-activitypub-videos.ts | 29 +++++---- server/tests/api/search/search-videos.ts | 8 +-- server/tests/api/server/contact-form.ts | 5 +- server/tests/api/server/email.ts | 28 ++++----- server/tests/api/server/follow-constraints.ts | 46 +++++++++------ server/tests/api/server/follows-moderation.ts | 20 +++---- server/tests/api/server/follows.ts | 59 +++++++++---------- server/tests/api/server/handle-down.ts | 4 +- server/tests/api/travis-1.sh | 10 ++-- server/tests/api/users/blocklist.ts | 28 ++++----- server/tests/api/users/users-verification.ts | 5 +- server/tests/api/videos/multiple-servers.ts | 41 +++++++------ server/tests/api/videos/services.ts | 10 ++-- server/tests/api/videos/single-server.ts | 4 +- server/tests/api/videos/video-abuse.ts | 9 ++- server/tests/api/videos/video-channels.ts | 6 +- server/tests/api/videos/video-comments.ts | 6 +- server/tests/api/videos/video-hls.ts | 9 ++- server/tests/api/videos/video-transcoder.ts | 18 +++--- server/tests/cli/optimize-old-videos.ts | 10 ++-- shared/extra-utils/server/servers.ts | 2 +- .../extra-utils/users/user-notifications.ts | 2 +- 25 files changed, 249 insertions(+), 222 deletions(-) diff --git a/server/tests/api/notifications/user-notifications.ts b/server/tests/api/notifications/user-notifications.ts index f479e1785..662b64e05 100644 --- a/server/tests/api/notifications/user-notifications.ts +++ b/server/tests/api/notifications/user-notifications.ts @@ -114,11 +114,12 @@ describe('Test users notifications', function () { before(async function () { this.timeout(120000) - await MockSmtpServer.Instance.collectEmails(emails) + const port = await MockSmtpServer.Instance.collectEmails(emails) const overrideConfig = { smtp: { - hostname: 'localhost' + hostname: 'localhost', + port } } servers = await flushAndRunMultipleServers(3, overrideConfig) @@ -194,7 +195,7 @@ describe('Test users notifications', function () { it('Should send a new video notification if the user follows the local video publisher', async function () { this.timeout(15000) - await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:9001') + await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:' + servers[0].port) await waitJobs(servers) const { name, uuid } = await uploadVideoByLocalAccount(servers) @@ -204,7 +205,7 @@ describe('Test users notifications', function () { it('Should send a new video notification from a remote account', async function () { this.timeout(50000) // Server 2 has transcoding enabled - await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:9002') + await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:' + servers[1].port) await waitJobs(servers) const { name, uuid } = await uploadVideoByRemoteAccount(servers) @@ -578,7 +579,9 @@ describe('Test users notifications', function () { const uuid = resVideo.body.video.uuid await waitJobs(servers) - const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'hello @user_1@localhost:9001 1') + + const text1 = `hello @user_1@localhost:${servers[ 0 ].port} 1` + const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, text1) const server2ThreadId = resThread.body.comment.id await waitJobs(servers) @@ -588,8 +591,8 @@ describe('Test users notifications', function () { const server1ThreadId = resThread2.body.data[0].id await checkCommentMention(baseParams, uuid, server1ThreadId, server1ThreadId, 'super root 2 name', 'presence') - const text = '@user_1@localhost:9001 hello 2 @root@localhost:9001' - await addVideoCommentReply(servers[1].url, servers[1].accessToken, uuid, server2ThreadId, text) + const text2 = `@user_1@localhost:${servers[ 0 ].port} hello 2 @root@localhost:${servers[ 0 ].port}` + await addVideoCommentReply(servers[1].url, servers[1].accessToken, uuid, server2ThreadId, text2) await waitJobs(servers) @@ -889,10 +892,10 @@ describe('Test users notifications', function () { await waitJobs(servers) - await checkNewInstanceFollower(baseParams, 'localhost:9003', 'presence') + await checkNewInstanceFollower(baseParams, 'localhost:' + servers[2].port, 'presence') const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } } - await checkNewInstanceFollower(immutableAssign(baseParams, userOverride), 'localhost:9003', 'absence') + await checkNewInstanceFollower(immutableAssign(baseParams, userOverride), 'localhost:' + servers[2].port, 'absence') }) }) @@ -933,29 +936,29 @@ describe('Test users notifications', function () { it('Should notify when a local channel is following one of our channel', async function () { this.timeout(10000) - await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001') + await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:' + servers[0].port) await waitJobs(servers) await checkNewActorFollow(baseParams, 'channel', 'root', 'super root name', myChannelName, 'presence') - await removeUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001') + await removeUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:' + servers[0].port) }) it('Should notify when a remote channel is following one of our channel', async function () { this.timeout(10000) - await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001') + await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port) await waitJobs(servers) await checkNewActorFollow(baseParams, 'channel', 'root', 'super root 2 name', myChannelName, 'presence') - await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001') + await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port) }) it('Should notify when a local account is following one of our channel', async function () { this.timeout(10000) - await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1@localhost:9001') + await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1@localhost:' + servers[0].port) await waitJobs(servers) @@ -965,7 +968,7 @@ describe('Test users notifications', function () { it('Should notify when a remote account is following one of our channel', async function () { this.timeout(10000) - await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1@localhost:9001') + await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1@localhost:' + servers[0].port) await waitJobs(servers) @@ -1019,8 +1022,8 @@ describe('Test users notifications', function () { autoBlacklistTestsCustomConfig.transcoding.enabled = true await updateCustomConfig(servers[0].url, servers[0].accessToken, autoBlacklistTestsCustomConfig) - await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001') - await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001') + await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:' + servers[0].port) + await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port) }) @@ -1142,8 +1145,8 @@ describe('Test users notifications', function () { after(async () => { await updateCustomConfig(servers[0].url, servers[0].accessToken, currentCustomConfig) - await removeUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001') - await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001') + await removeUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:' + servers[0].port) + await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port) }) }) diff --git a/server/tests/api/redundancy/redundancy.ts b/server/tests/api/redundancy/redundancy.ts index e31329c25..6f2c59076 100644 --- a/server/tests/api/redundancy/redundancy.ts +++ b/server/tests/api/redundancy/redundancy.ts @@ -100,7 +100,7 @@ async function check1WebSeed (videoUUID?: string) { if (!videoUUID) videoUUID = video1Server2UUID const webseeds = [ - 'http://localhost:9002/static/webseed/' + videoUUID + `http://localhost:${servers[ 1 ].port}/static/webseed/${videoUUID}` ] for (const server of servers) { @@ -118,8 +118,8 @@ async function check2Webseeds (videoUUID?: string) { if (!videoUUID) videoUUID = video1Server2UUID const webseeds = [ - 'http://localhost:9001/static/redundancy/' + videoUUID, - 'http://localhost:9002/static/webseed/' + videoUUID + `http://localhost:${servers[ 0 ].port}/static/redundancy/${videoUUID}`, + `http://localhost:${servers[ 1 ].port}/static/webseed/${videoUUID}` ] for (const server of servers) { @@ -145,7 +145,12 @@ async function check2Webseeds (videoUUID?: string) { } } - for (const directory of [ 'test1/redundancy', 'test2/videos' ]) { + const directories = [ + 'test' + servers[0].internalServerNumber + '/redundancy', + 'test' + servers[1].internalServerNumber + '/videos' + ] + + for (const directory of directories) { const files = await readdir(join(root(), directory)) expect(files).to.have.length.at.least(4) @@ -194,7 +199,12 @@ async function check1PlaylistRedundancies (videoUUID?: string) { await checkSegmentHash(baseUrlPlaylist, baseUrlSegment, videoUUID, resolution, hlsPlaylist) } - for (const directory of [ 'test1/redundancy/hls', 'test2/streaming-playlists/hls' ]) { + const directories = [ + 'test' + servers[0].internalServerNumber + '/redundancy/hls', + 'test' + servers[1].internalServerNumber + '/streaming-playlists/hls' + ] + + for (const directory of directories) { const files = await readdir(join(root(), directory, videoUUID)) expect(files).to.have.length.at.least(4) @@ -239,8 +249,8 @@ async function enableRedundancyOnServer1 () { const res = await getFollowingListPaginationAndSort(servers[ 0 ].url, 0, 5, '-createdAt') const follows: ActorFollow[] = res.body.data - const server2 = follows.find(f => f.following.host === 'localhost:9002') - const server3 = follows.find(f => f.following.host === 'localhost:9003') + const server2 = follows.find(f => f.following.host === `localhost:${servers[ 1 ].port}`) + const server3 = follows.find(f => f.following.host === `localhost:${servers[ 2 ].port}`) expect(server3).to.not.be.undefined expect(server3.following.hostRedundancyAllowed).to.be.false @@ -254,8 +264,8 @@ async function disableRedundancyOnServer1 () { const res = await getFollowingListPaginationAndSort(servers[ 0 ].url, 0, 5, '-createdAt') const follows: ActorFollow[] = res.body.data - const server2 = follows.find(f => f.following.host === 'localhost:9002') - const server3 = follows.find(f => f.following.host === 'localhost:9003') + const server2 = follows.find(f => f.following.host === `localhost:${servers[ 1 ].port}`) + const server3 = follows.find(f => f.following.host === `localhost:${servers[ 2 ].port}`) expect(server3).to.not.be.undefined expect(server3.following.hostRedundancyAllowed).to.be.false @@ -475,12 +485,12 @@ describe('Test videos redundancy', function () { await wait(10000) try { - await checkContains(servers, 'http%3A%2F%2Flocalhost%3A9001') + await checkContains(servers, 'http%3A%2F%2Flocalhost%3A' + servers[0].port) } catch { // Maybe a server deleted a redundancy in the scheduler await wait(2000) - await checkContains(servers, 'http%3A%2F%2Flocalhost%3A9001') + await checkContains(servers, 'http%3A%2F%2Flocalhost%3A' + servers[0].port) } }) @@ -491,7 +501,7 @@ describe('Test videos redundancy', function () { await wait(15000) - await checkNotContains([ servers[1], servers[2] ], 'http%3A%2F%2Flocalhost%3A9001') + await checkNotContains([ servers[1], servers[2] ], 'http%3A%2F%2Flocalhost%3A' + servers[0].port) }) after(async function () { diff --git a/server/tests/api/search/search-activitypub-video-channels.ts b/server/tests/api/search/search-activitypub-video-channels.ts index 70a077ffc..8a008b8c6 100644 --- a/server/tests/api/search/search-activitypub-video-channels.ts +++ b/server/tests/api/search/search-activitypub-video-channels.ts @@ -3,16 +3,17 @@ import * as chai from 'chai' import 'mocha' import { - addVideoChannel, cleanupTests, + addVideoChannel, + cleanupTests, createUser, deleteVideoChannel, flushAndRunMultipleServers, - flushTests, - getVideoChannelsList, getVideoChannelVideos, - killallServers, + getVideoChannelsList, + getVideoChannelVideos, ServerInfo, setAccessTokensToServers, - updateMyUser, updateVideo, + updateMyUser, + updateVideo, updateVideoChannel, uploadVideo, userLogin, @@ -67,7 +68,7 @@ describe('Test ActivityPub video channels search', function () { it('Should not find a remote video channel', async function () { { - const search = 'http://localhost:9002/video-channels/channel1_server3' + const search = 'http://localhost:' + servers[ 1 ].port + '/video-channels/channel1_server3' const res = await searchVideoChannel(servers[ 0 ].url, search, servers[ 0 ].accessToken) expect(res.body.total).to.equal(0) @@ -77,7 +78,7 @@ describe('Test ActivityPub video channels search', function () { { // Without token - const search = 'http://localhost:9002/video-channels/channel1_server2' + const search = 'http://localhost:' + servers[ 1 ].port + '/video-channels/channel1_server2' const res = await searchVideoChannel(servers[0].url, search) expect(res.body.total).to.equal(0) @@ -88,8 +89,8 @@ describe('Test ActivityPub video channels search', function () { it('Should search a local video channel', async function () { const searches = [ - 'http://localhost:9001/video-channels/channel1_server1', - 'channel1_server1@localhost:9001' + 'http://localhost:' + servers[ 0 ].port + '/video-channels/channel1_server1', + 'channel1_server1@localhost:' + servers[ 0 ].port ] for (const search of searches) { @@ -105,8 +106,8 @@ describe('Test ActivityPub video channels search', function () { it('Should search a remote video channel with URL or handle', async function () { const searches = [ - 'http://localhost:9002/video-channels/channel1_server2', - 'channel1_server2@localhost:9002' + 'http://localhost:' + servers[ 1 ].port + '/video-channels/channel1_server2', + 'channel1_server2@localhost:' + servers[ 1 ].port ] for (const search of searches) { @@ -134,13 +135,13 @@ describe('Test ActivityPub video channels search', function () { await waitJobs(servers) - const res = await getVideoChannelVideos(servers[0].url, null, 'channel1_server2@localhost:9002', 0, 5) + const res = await getVideoChannelVideos(servers[0].url, null, 'channel1_server2@localhost:' + servers[ 1 ].port, 0, 5) expect(res.body.total).to.equal(0) expect(res.body.data).to.have.lengthOf(0) }) it('Should list video channel videos of server 2 with token', async function () { - const res = await getVideoChannelVideos(servers[0].url, servers[0].accessToken, 'channel1_server2@localhost:9002', 0, 5) + const res = await getVideoChannelVideos(servers[0].url, servers[0].accessToken, 'channel1_server2@localhost:' + servers[ 1 ].port, 0, 5) expect(res.body.total).to.equal(1) expect(res.body.data[0].name).to.equal('video 1 server 2') @@ -156,7 +157,7 @@ describe('Test ActivityPub video channels search', function () { // Expire video channel await wait(10000) - const search = 'http://localhost:9002/video-channels/channel1_server2' + const search = 'http://localhost:' + servers[ 1 ].port + '/video-channels/channel1_server2' const res = await searchVideoChannel(servers[0].url, search, servers[0].accessToken) expect(res.body.total).to.equal(1) expect(res.body.data).to.have.lengthOf(1) @@ -179,12 +180,13 @@ describe('Test ActivityPub video channels search', function () { // Expire video channel await wait(10000) - const search = 'http://localhost:9002/video-channels/channel1_server2' + const search = 'http://localhost:' + servers[ 1 ].port + '/video-channels/channel1_server2' await searchVideoChannel(servers[0].url, search, servers[0].accessToken) await waitJobs(servers) - const res = await getVideoChannelVideos(servers[0].url, servers[0].accessToken, 'channel1_server2@localhost:9002', 0, 5, '-createdAt') + const videoChannelName = 'channel1_server2@localhost:' + servers[ 1 ].port + const res = await getVideoChannelVideos(servers[0].url, servers[0].accessToken, videoChannelName, 0, 5, '-createdAt') expect(res.body.total).to.equal(2) expect(res.body.data[0].name).to.equal('video 2 server 2') @@ -200,7 +202,8 @@ describe('Test ActivityPub video channels search', function () { // Expire video await wait(10000) - const res = await searchVideoChannel(servers[0].url, 'http://localhost:9002/video-channels/channel1_server2', servers[0].accessToken) + const search = 'http://localhost:' + servers[ 1 ].port + '/video-channels/channel1_server2' + const res = await searchVideoChannel(servers[0].url, search, servers[0].accessToken) expect(res.body.total).to.equal(0) expect(res.body.data).to.have.lengthOf(0) }) diff --git a/server/tests/api/search/search-activitypub-videos.ts b/server/tests/api/search/search-activitypub-videos.ts index e8e2b5a64..dbfefadda 100644 --- a/server/tests/api/search/search-activitypub-videos.ts +++ b/server/tests/api/search/search-activitypub-videos.ts @@ -4,18 +4,17 @@ import * as chai from 'chai' import 'mocha' import { addVideoChannel, + cleanupTests, flushAndRunMultipleServers, - flushTests, getVideosList, - killallServers, removeVideo, + searchVideo, searchVideoWithToken, ServerInfo, setAccessTokensToServers, updateVideo, uploadVideo, - wait, - searchVideo, cleanupTests + wait } from '../../../../shared/extra-utils' import { waitJobs } from '../../../../shared/extra-utils/server/jobs' import { Video, VideoPrivacy } from '../../../../shared/models/videos' @@ -49,7 +48,8 @@ describe('Test ActivityPub videos search', function () { it('Should not find a remote video', async function () { { - const res = await searchVideoWithToken(servers[ 0 ].url, 'http://localhost:9002/videos/watch/43', servers[ 0 ].accessToken) + const search = 'http://localhost:' + servers[1].port + '/videos/watch/43' + const res = await searchVideoWithToken(servers[ 0 ].url, search, servers[ 0 ].accessToken) expect(res.body.total).to.equal(0) expect(res.body.data).to.be.an('array') @@ -58,7 +58,8 @@ describe('Test ActivityPub videos search', function () { { // Without token - const res = await searchVideo(servers[0].url, 'http://localhost:9002/videos/watch/' + videoServer2UUID) + const search = 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID + const res = await searchVideo(servers[0].url, search) expect(res.body.total).to.equal(0) expect(res.body.data).to.be.an('array') @@ -67,7 +68,8 @@ describe('Test ActivityPub videos search', function () { }) it('Should search a local video', async function () { - const res = await searchVideo(servers[0].url, 'http://localhost:9001/videos/watch/' + videoServer1UUID) + const search = 'http://localhost:' + servers[0].port + '/videos/watch/' + videoServer1UUID + const res = await searchVideo(servers[0].url, search) expect(res.body.total).to.equal(1) expect(res.body.data).to.be.an('array') @@ -76,7 +78,8 @@ describe('Test ActivityPub videos search', function () { }) it('Should search a remote video', async function () { - const res = await searchVideoWithToken(servers[0].url, 'http://localhost:9002/videos/watch/' + videoServer2UUID, servers[0].accessToken) + const search = 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID + const res = await searchVideoWithToken(servers[0].url, search, servers[0].accessToken) expect(res.body.total).to.equal(1) expect(res.body.data).to.be.an('array') @@ -114,12 +117,13 @@ describe('Test ActivityPub videos search', function () { await wait(10000) // Will run refresh async - await searchVideoWithToken(servers[0].url, 'http://localhost:9002/videos/watch/' + videoServer2UUID, servers[0].accessToken) + const search = 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID + await searchVideoWithToken(servers[0].url, search, servers[0].accessToken) // Wait refresh await wait(5000) - const res = await searchVideoWithToken(servers[0].url, 'http://localhost:9002/videos/watch/' + videoServer2UUID, servers[0].accessToken) + const res = await searchVideoWithToken(servers[0].url, search, servers[0].accessToken) expect(res.body.total).to.equal(1) expect(res.body.data).to.have.lengthOf(1) @@ -139,12 +143,13 @@ describe('Test ActivityPub videos search', function () { await wait(10000) // Will run refresh async - await searchVideoWithToken(servers[0].url, 'http://localhost:9002/videos/watch/' + videoServer2UUID, servers[0].accessToken) + const search = 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID + await searchVideoWithToken(servers[0].url, search, servers[0].accessToken) // Wait refresh await wait(5000) - const res = await searchVideoWithToken(servers[0].url, 'http://localhost:9002/videos/watch/' + videoServer2UUID, servers[0].accessToken) + const res = await searchVideoWithToken(servers[0].url, search, servers[0].accessToken) expect(res.body.total).to.equal(0) expect(res.body.data).to.have.lengthOf(0) }) diff --git a/server/tests/api/search/search-videos.ts b/server/tests/api/search/search-videos.ts index 22d3a5951..92cc0dc71 100644 --- a/server/tests/api/search/search-videos.ts +++ b/server/tests/api/search/search-videos.ts @@ -4,16 +4,14 @@ import * as chai from 'chai' import 'mocha' import { advancedVideosSearch, - flushTests, - killallServers, + cleanupTests, flushAndRunServer, + immutableAssign, searchVideo, ServerInfo, setAccessTokensToServers, uploadVideo, - wait, - immutableAssign, - cleanupTests + wait } from '../../../../shared/extra-utils' const expect = chai.expect diff --git a/server/tests/api/server/contact-form.ts b/server/tests/api/server/contact-form.ts index ba51198b3..0a1c49ef5 100644 --- a/server/tests/api/server/contact-form.ts +++ b/server/tests/api/server/contact-form.ts @@ -24,11 +24,12 @@ describe('Test contact form', function () { before(async function () { this.timeout(30000) - await MockSmtpServer.Instance.collectEmails(emails) + const port = await MockSmtpServer.Instance.collectEmails(emails) const overrideConfig = { smtp: { - hostname: 'localhost' + hostname: 'localhost', + port } } server = await flushAndRunServer(1, overrideConfig) diff --git a/server/tests/api/server/email.ts b/server/tests/api/server/email.ts index bacdf1b1b..9ccb1c36f 100644 --- a/server/tests/api/server/email.ts +++ b/server/tests/api/server/email.ts @@ -7,18 +7,18 @@ import { askResetPassword, askSendVerifyEmail, blockUser, - createUser, removeVideoFromBlacklist, + cleanupTests, + createUser, + flushAndRunServer, + removeVideoFromBlacklist, reportVideoAbuse, resetPassword, - flushAndRunServer, + ServerInfo, + setAccessTokensToServers, unblockUser, uploadVideo, userLogin, - verifyEmail, - flushTests, - killallServers, - ServerInfo, - setAccessTokensToServers, cleanupTests + verifyEmail } from '../../../../shared/extra-utils' import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email' import { waitJobs } from '../../../../shared/extra-utils/server/jobs' @@ -87,7 +87,7 @@ describe('Test emails', function () { const email = emails[0] - expect(email['from'][0]['name']).equal('localhost:9001') + expect(email['from'][0]['name']).equal('localhost:' + server.port) expect(email['from'][0]['address']).equal('test-admin@localhost') expect(email['to'][0]['address']).equal('user_1@example.com') expect(email['subject']).contains('password') @@ -132,7 +132,7 @@ describe('Test emails', function () { const email = emails[1] - expect(email['from'][0]['name']).equal('localhost:9001') + expect(email['from'][0]['name']).equal('localhost:' + server.port) expect(email['from'][0]['address']).equal('test-admin@localhost') expect(email['to'][0]['address']).equal('admin1@example.com') expect(email['subject']).contains('abuse') @@ -153,7 +153,7 @@ describe('Test emails', function () { const email = emails[2] - expect(email['from'][0]['name']).equal('localhost:9001') + expect(email['from'][0]['name']).equal('localhost:' + server.port) expect(email['from'][0]['address']).equal('test-admin@localhost') expect(email['to'][0]['address']).equal('user_1@example.com') expect(email['subject']).contains(' blocked') @@ -171,7 +171,7 @@ describe('Test emails', function () { const email = emails[3] - expect(email['from'][0]['name']).equal('localhost:9001') + expect(email['from'][0]['name']).equal('localhost:' + server.port) expect(email['from'][0]['address']).equal('test-admin@localhost') expect(email['to'][0]['address']).equal('user_1@example.com') expect(email['subject']).contains(' unblocked') @@ -191,7 +191,7 @@ describe('Test emails', function () { const email = emails[4] - expect(email['from'][0]['name']).equal('localhost:9001') + expect(email['from'][0]['name']).equal('localhost:' + server.port) expect(email['from'][0]['address']).equal('test-admin@localhost') expect(email['to'][0]['address']).equal('user_1@example.com') expect(email['subject']).contains(' blacklisted') @@ -209,7 +209,7 @@ describe('Test emails', function () { const email = emails[5] - expect(email['from'][0]['name']).equal('localhost:9001') + expect(email['from'][0]['name']).equal('localhost:' + server.port) expect(email['from'][0]['address']).equal('test-admin@localhost') expect(email['to'][0]['address']).equal('user_1@example.com') expect(email['subject']).contains(' unblacklisted') @@ -229,7 +229,7 @@ describe('Test emails', function () { const email = emails[6] - expect(email['from'][0]['name']).equal('localhost:9001') + expect(email['from'][0]['name']).equal('localhost:' + server.port) expect(email['from'][0]['address']).equal('test-admin@localhost') expect(email['to'][0]['address']).equal('user_1@example.com') expect(email['subject']).contains('Verify') diff --git a/server/tests/api/server/follow-constraints.ts b/server/tests/api/server/follow-constraints.ts index 4285a9e7a..ac3ff37f0 100644 --- a/server/tests/api/server/follow-constraints.ts +++ b/server/tests/api/server/follow-constraints.ts @@ -3,16 +3,16 @@ import * as chai from 'chai' import 'mocha' import { + cleanupTests, doubleFollow, + flushAndRunMultipleServers, getAccountVideos, getVideo, getVideoChannelVideos, getVideoWithToken, - flushAndRunMultipleServers, - killallServers, ServerInfo, setAccessTokensToServers, - uploadVideo, cleanupTests + uploadVideo } from '../../../../shared/extra-utils' import { unfollow } from '../../../../shared/extra-utils/server/follows' import { userLogin } from '../../../../shared/extra-utils/users/login' @@ -66,28 +66,30 @@ describe('Test follow constraints', function () { }) it('Should list local account videos', async function () { - const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:9001', 0, 5) + const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:' + servers[0].port, 0, 5) expect(res.body.total).to.equal(1) expect(res.body.data).to.have.lengthOf(1) }) it('Should list remote account videos', async function () { - const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:9002', 0, 5) + const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:' + servers[1].port, 0, 5) expect(res.body.total).to.equal(1) expect(res.body.data).to.have.lengthOf(1) }) it('Should list local channel videos', async function () { - const res = await getVideoChannelVideos(servers[0].url, undefined, 'root_channel@localhost:9001', 0, 5) + const videoChannelName = 'root_channel@localhost:' + servers[0].port + const res = await getVideoChannelVideos(servers[0].url, undefined, videoChannelName, 0, 5) expect(res.body.total).to.equal(1) expect(res.body.data).to.have.lengthOf(1) }) it('Should list remote channel videos', async function () { - const res = await getVideoChannelVideos(servers[0].url, undefined, 'root_channel@localhost:9002', 0, 5) + const videoChannelName = 'root_channel@localhost:' + servers[1].port + const res = await getVideoChannelVideos(servers[0].url, undefined, videoChannelName, 0, 5) expect(res.body.total).to.equal(1) expect(res.body.data).to.have.lengthOf(1) @@ -104,28 +106,30 @@ describe('Test follow constraints', function () { }) it('Should list local account videos', async function () { - const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:9001', 0, 5) + const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:' + servers[0].port, 0, 5) expect(res.body.total).to.equal(1) expect(res.body.data).to.have.lengthOf(1) }) it('Should list remote account videos', async function () { - const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:9002', 0, 5) + const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:' + servers[1].port, 0, 5) expect(res.body.total).to.equal(1) expect(res.body.data).to.have.lengthOf(1) }) it('Should list local channel videos', async function () { - const res = await getVideoChannelVideos(servers[0].url, userAccessToken, 'root_channel@localhost:9001', 0, 5) + const videoChannelName = 'root_channel@localhost:' + servers[0].port + const res = await getVideoChannelVideos(servers[0].url, userAccessToken, videoChannelName, 0, 5) expect(res.body.total).to.equal(1) expect(res.body.data).to.have.lengthOf(1) }) it('Should list remote channel videos', async function () { - const res = await getVideoChannelVideos(servers[0].url, userAccessToken, 'root_channel@localhost:9002', 0, 5) + const videoChannelName = 'root_channel@localhost:' + servers[1].port + const res = await getVideoChannelVideos(servers[0].url, userAccessToken, videoChannelName, 0, 5) expect(res.body.total).to.equal(1) expect(res.body.data).to.have.lengthOf(1) @@ -152,28 +156,30 @@ describe('Test follow constraints', function () { }) it('Should list local account videos', async function () { - const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:9001', 0, 5) + const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:' + servers[0].port, 0, 5) expect(res.body.total).to.equal(1) expect(res.body.data).to.have.lengthOf(1) }) it('Should not list remote account videos', async function () { - const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:9002', 0, 5) + const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:' + servers[1].port, 0, 5) expect(res.body.total).to.equal(0) expect(res.body.data).to.have.lengthOf(0) }) it('Should list local channel videos', async function () { - const res = await getVideoChannelVideos(servers[0].url, undefined, 'root_channel@localhost:9001', 0, 5) + const videoChannelName = 'root_channel@localhost:' + servers[0].port + const res = await getVideoChannelVideos(servers[0].url, undefined, videoChannelName, 0, 5) expect(res.body.total).to.equal(1) expect(res.body.data).to.have.lengthOf(1) }) it('Should not list remote channel videos', async function () { - const res = await getVideoChannelVideos(servers[0].url, undefined, 'root_channel@localhost:9002', 0, 5) + const videoChannelName = 'root_channel@localhost:' + servers[1].port + const res = await getVideoChannelVideos(servers[0].url, undefined, videoChannelName, 0, 5) expect(res.body.total).to.equal(0) expect(res.body.data).to.have.lengthOf(0) @@ -190,28 +196,30 @@ describe('Test follow constraints', function () { }) it('Should list local account videos', async function () { - const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:9001', 0, 5) + const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:' + servers[0].port, 0, 5) expect(res.body.total).to.equal(1) expect(res.body.data).to.have.lengthOf(1) }) it('Should list remote account videos', async function () { - const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:9002', 0, 5) + const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:' + servers[1].port, 0, 5) expect(res.body.total).to.equal(1) expect(res.body.data).to.have.lengthOf(1) }) it('Should list local channel videos', async function () { - const res = await getVideoChannelVideos(servers[0].url, userAccessToken, 'root_channel@localhost:9001', 0, 5) + const videoChannelName = 'root_channel@localhost:' + servers[0].port + const res = await getVideoChannelVideos(servers[0].url, userAccessToken, videoChannelName, 0, 5) expect(res.body.total).to.equal(1) expect(res.body.data).to.have.lengthOf(1) }) it('Should list remote channel videos', async function () { - const res = await getVideoChannelVideos(servers[0].url, userAccessToken, 'root_channel@localhost:9002', 0, 5) + const videoChannelName = 'root_channel@localhost:' + servers[1].port + const res = await getVideoChannelVideos(servers[0].url, userAccessToken, videoChannelName, 0, 5) expect(res.body.total).to.equal(1) expect(res.body.data).to.have.lengthOf(1) diff --git a/server/tests/api/server/follows-moderation.ts b/server/tests/api/server/follows-moderation.ts index 2a3a4d5c8..fc20f8961 100644 --- a/server/tests/api/server/follows-moderation.ts +++ b/server/tests/api/server/follows-moderation.ts @@ -3,9 +3,9 @@ import * as chai from 'chai' import 'mocha' import { - acceptFollower, cleanupTests, + acceptFollower, + cleanupTests, flushAndRunMultipleServers, - killallServers, ServerInfo, setAccessTokensToServers, updateCustomSubConfig @@ -14,8 +14,8 @@ import { follow, getFollowersListPaginationAndSort, getFollowingListPaginationAndSort, - removeFollower, - rejectFollower + rejectFollower, + removeFollower } from '../../../../shared/extra-utils/server/follows' import { waitJobs } from '../../../../shared/extra-utils/server/jobs' import { ActorFollow } from '../../../../shared/models/actors' @@ -29,8 +29,8 @@ async function checkServer1And2HasFollowers (servers: ServerInfo[], state = 'acc const follow = res.body.data[0] as ActorFollow expect(follow.state).to.equal(state) - expect(follow.follower.url).to.equal('http://localhost:9001/accounts/peertube') - expect(follow.following.url).to.equal('http://localhost:9002/accounts/peertube') + expect(follow.follower.url).to.equal('http://localhost:' + servers[0].port + 'accounts/peertube') + expect(follow.following.url).to.equal('http://localhost:' + servers[1].port + '/accounts/peertube') } { @@ -39,8 +39,8 @@ async function checkServer1And2HasFollowers (servers: ServerInfo[], state = 'acc const follow = res.body.data[0] as ActorFollow expect(follow.state).to.equal(state) - expect(follow.follower.url).to.equal('http://localhost:9001/accounts/peertube') - expect(follow.following.url).to.equal('http://localhost:9002/accounts/peertube') + expect(follow.follower.url).to.equal('http://localhost:' + servers[0].port + 'accounts/peertube') + expect(follow.following.url).to.equal('http://localhost:' + servers[1].port + '/accounts/peertube') } } @@ -151,7 +151,7 @@ describe('Test follows moderation', function () { }) it('Should accept a follower', async function () { - await acceptFollower(servers[1].url, servers[1].accessToken, 'peertube@localhost:9001') + await acceptFollower(servers[1].url, servers[1].accessToken, 'peertube@localhost:' + servers[0].port) await waitJobs(servers) await checkServer1And2HasFollowers(servers) @@ -178,7 +178,7 @@ describe('Test follows moderation', function () { expect(res.body.total).to.equal(1) } - await rejectFollower(servers[2].url, servers[2].accessToken, 'peertube@localhost:9001') + await rejectFollower(servers[2].url, servers[2].accessToken, 'peertube@localhost:' + servers[0].port) await waitJobs(servers) await checkServer1And2HasFollowers(servers) diff --git a/server/tests/api/server/follows.ts b/server/tests/api/server/follows.ts index 397093cdb..d4155667f 100644 --- a/server/tests/api/server/follows.ts +++ b/server/tests/api/server/follows.ts @@ -8,7 +8,6 @@ import { cleanupTests, completeVideoCheck } from '../../../../shared/extra-utils import { flushAndRunMultipleServers, getVideosList, - killallServers, ServerInfo, setAccessTokensToServers, uploadVideo @@ -89,8 +88,8 @@ describe('Test follows', function () { res = await getFollowingListPaginationAndSort(servers[0].url, 1, 1, 'createdAt') follows = follows.concat(res.body.data) - const server2Follow = follows.find(f => f.following.host === 'localhost:9002') - const server3Follow = follows.find(f => f.following.host === 'localhost:9003') + const server2Follow = follows.find(f => f.following.host === 'localhost:' + servers[1].port) + const server3Follow = follows.find(f => f.following.host === 'localhost:' + servers[2].port) expect(server2Follow).to.not.be.undefined expect(server3Follow).to.not.be.undefined @@ -100,12 +99,12 @@ describe('Test follows', function () { it('Should search followings on server 1', async function () { { - const res = await getFollowingListPaginationAndSort(servers[ 0 ].url, 0, 1, 'createdAt', ':9002') + const res = await getFollowingListPaginationAndSort(servers[ 0 ].url, 0, 1, 'createdAt', ':' + servers[1].port) const follows = res.body.data expect(res.body.total).to.equal(1) expect(follows.length).to.equal(1) - expect(follows[ 0 ].following.host).to.equal('localhost:9002') + expect(follows[ 0 ].following.host).to.equal('localhost:' + servers[1].port) } { @@ -136,7 +135,7 @@ describe('Test follows', function () { expect(res.body.total).to.equal(1) expect(follows).to.be.an('array') expect(follows.length).to.equal(1) - expect(follows[0].follower.host).to.equal('localhost:9001') + expect(follows[0].follower.host).to.equal('localhost:' + servers[0].port) } }) @@ -147,7 +146,7 @@ describe('Test follows', function () { expect(res.body.total).to.equal(1) expect(follows.length).to.equal(1) - expect(follows[ 0 ].following.host).to.equal('localhost:9003') + expect(follows[ 0 ].following.host).to.equal('localhost:' + servers[2].port) } { @@ -169,16 +168,16 @@ describe('Test follows', function () { }) it('Should have the correct follows counts', async function () { - await expectAccountFollows(servers[0].url, 'peertube@localhost:9001', 0, 2) - await expectAccountFollows(servers[0].url, 'peertube@localhost:9002', 1, 0) - await expectAccountFollows(servers[0].url, 'peertube@localhost:9003', 1, 0) + await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[0].port, 0, 2) + await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[1].port, 1, 0) + await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[2].port, 1, 0) // Server 2 and 3 does not know server 1 follow another server (there was not a refresh) - await expectAccountFollows(servers[1].url, 'peertube@localhost:9001', 0, 1) - await expectAccountFollows(servers[1].url, 'peertube@localhost:9002', 1, 0) + await expectAccountFollows(servers[1].url, 'peertube@localhost:' + servers[0].port, 0, 1) + await expectAccountFollows(servers[1].url, 'peertube@localhost:' + servers[1].port, 1, 0) - await expectAccountFollows(servers[2].url, 'peertube@localhost:9001', 0, 1) - await expectAccountFollows(servers[2].url, 'peertube@localhost:9003', 1, 0) + await expectAccountFollows(servers[2].url, 'peertube@localhost:' + servers[0].port, 0, 1) + await expectAccountFollows(servers[2].url, 'peertube@localhost:' + servers[2].port, 1, 0) }) it('Should unfollow server 3 on server 1', async function () { @@ -197,7 +196,7 @@ describe('Test follows', function () { expect(follows).to.be.an('array') expect(follows.length).to.equal(1) - expect(follows[0].following.host).to.equal('localhost:9002') + expect(follows[0].following.host).to.equal('localhost:' + servers[1].port) }) it('Should not have server 1 as follower on server 3 anymore', async function () { @@ -210,14 +209,14 @@ describe('Test follows', function () { }) it('Should have the correct follows counts 2', async function () { - await expectAccountFollows(servers[0].url, 'peertube@localhost:9001', 0, 1) - await expectAccountFollows(servers[0].url, 'peertube@localhost:9002', 1, 0) + await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[0].port, 0, 1) + await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[1].port, 1, 0) - await expectAccountFollows(servers[1].url, 'peertube@localhost:9001', 0, 1) - await expectAccountFollows(servers[1].url, 'peertube@localhost:9002', 1, 0) + await expectAccountFollows(servers[1].url, 'peertube@localhost:' + servers[0].port, 0, 1) + await expectAccountFollows(servers[1].url, 'peertube@localhost:' + servers[1].port, 1, 0) - await expectAccountFollows(servers[2].url, 'peertube@localhost:9001', 0, 0) - await expectAccountFollows(servers[2].url, 'peertube@localhost:9003', 0, 0) + await expectAccountFollows(servers[2].url, 'peertube@localhost:' + servers[0].port, 0, 0) + await expectAccountFollows(servers[2].url, 'peertube@localhost:' + servers[2].port, 0, 0) }) it('Should upload a video on server 2 and 3 and propagate only the video of server 2', async function () { @@ -310,15 +309,15 @@ describe('Test follows', function () { }) it('Should have the correct follows counts 3', async function () { - await expectAccountFollows(servers[0].url, 'peertube@localhost:9001', 0, 2) - await expectAccountFollows(servers[0].url, 'peertube@localhost:9002', 1, 0) - await expectAccountFollows(servers[0].url, 'peertube@localhost:9003', 1, 0) + await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[0].port, 0, 2) + await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[1].port, 1, 0) + await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[2].port, 1, 0) - await expectAccountFollows(servers[1].url, 'peertube@localhost:9001', 0, 1) - await expectAccountFollows(servers[1].url, 'peertube@localhost:9002', 1, 0) + await expectAccountFollows(servers[1].url, 'peertube@localhost:' + servers[0].port, 0, 1) + await expectAccountFollows(servers[1].url, 'peertube@localhost:' + servers[1].port, 1, 0) - await expectAccountFollows(servers[2].url, 'peertube@localhost:9001', 0, 2) - await expectAccountFollows(servers[2].url, 'peertube@localhost:9003', 1, 0) + await expectAccountFollows(servers[2].url, 'peertube@localhost:' + servers[0].port, 0, 2) + await expectAccountFollows(servers[2].url, 'peertube@localhost:' + servers[2].port, 1, 0) }) it('Should have propagated videos', async function () { @@ -344,7 +343,7 @@ describe('Test follows', function () { support: 'my super support text', account: { name: 'root', - host: 'localhost:9003' + host: 'localhost:' + servers[2].port }, isLocal, commentsEnabled: true, @@ -384,7 +383,7 @@ describe('Test follows', function () { expect(comment.videoId).to.equal(video4.id) expect(comment.id).to.equal(comment.threadId) expect(comment.account.name).to.equal('root') - expect(comment.account.host).to.equal('localhost:9003') + expect(comment.account.host).to.equal('localhost:' + servers[2].port) expect(comment.totalReplies).to.equal(3) expect(dateIsValid(comment.createdAt as string)).to.be.true expect(dateIsValid(comment.updatedAt as string)).to.be.true diff --git a/server/tests/api/server/handle-down.ts b/server/tests/api/server/handle-down.ts index 19010dbc1..9a8bc08f9 100644 --- a/server/tests/api/server/handle-down.ts +++ b/server/tests/api/server/handle-down.ts @@ -70,7 +70,7 @@ describe('Test handle downs', function () { support: 'my super support text for server 1', account: { name: 'root', - host: 'localhost:9001' + host: 'localhost:' + servers[0].port }, isLocal: false, duration: 10, @@ -172,7 +172,7 @@ describe('Test handle downs', function () { const res = await getFollowersListPaginationAndSort(servers[0].url, 0, 2, 'createdAt') expect(res.body.data).to.be.an('array') expect(res.body.data).to.have.lengthOf(1) - expect(res.body.data[0].follower.host).to.equal('localhost:9003') + expect(res.body.data[0].follower.host).to.equal('localhost:' + servers[2].port) }) it('Should not have pending/processing jobs anymore', async function () { diff --git a/server/tests/api/travis-1.sh b/server/tests/api/travis-1.sh index e4761d2f9..0673bb2bf 100644 --- a/server/tests/api/travis-1.sh +++ b/server/tests/api/travis-1.sh @@ -2,9 +2,9 @@ set -eu -files=$(find server/tests/api/check-params -type f | grep -v index.ts | xargs echo) +notificationsFiles=$(find server/tests/api/notifications -type f | grep -v index.ts | xargs echo) +searchFiles=$(find server/tests/api/search -type f | grep -v index.ts | xargs echo) +checkParamFiles=$(find server/tests/api/check-params -type f | grep -v index.ts | xargs echo) -MOCHA_PARALLEL=true mocha-parallel-tests --max-parallel 4 --timeout 5000 --exit --require ts-node/register --bail $files - -mocha --timeout 5000 --exit --require ts-node/register --bail server/tests/api/notifications/index.ts -mocha --timeout 5000 --exit --require ts-node/register --bail server/tests/api/search/index.ts +MOCHA_PARALLEL=true mocha-parallel-tests --max-parallel 4 --timeout 5000 --exit --require ts-node/register --bail \ + $notificationsFiles $searchFiles $checkParamFiles diff --git a/server/tests/api/users/blocklist.ts b/server/tests/api/users/blocklist.ts index fbc57e0ef..c25e85ada 100644 --- a/server/tests/api/users/blocklist.ts +++ b/server/tests/api/users/blocklist.ts @@ -144,7 +144,7 @@ describe('Test blocklist', function () { }) it('Should block a remote account', async function () { - await addAccountToAccountBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'user2@localhost:9002') + await addAccountToAccountBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'user2@localhost:' + servers[1].port) }) it('Should hide its videos', async function () { @@ -209,7 +209,7 @@ describe('Test blocklist', function () { expect(block.byAccount.name).to.equal('root') expect(block.blockedAccount.displayName).to.equal('user2') expect(block.blockedAccount.name).to.equal('user2') - expect(block.blockedAccount.host).to.equal('localhost:9002') + expect(block.blockedAccount.host).to.equal('localhost:' + servers[1].port) } { @@ -223,12 +223,12 @@ describe('Test blocklist', function () { expect(block.byAccount.name).to.equal('root') expect(block.blockedAccount.displayName).to.equal('user1') expect(block.blockedAccount.name).to.equal('user1') - expect(block.blockedAccount.host).to.equal('localhost:9001') + expect(block.blockedAccount.host).to.equal('localhost:' + servers[0].port) } }) it('Should unblock the remote account', async function () { - await removeAccountFromAccountBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'user2@localhost:9002') + await removeAccountFromAccountBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'user2@localhost:' + servers[1].port) }) it('Should display its videos', async function () { @@ -260,7 +260,7 @@ describe('Test blocklist', function () { }) it('Should block a remote server', async function () { - await addServerToAccountBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'localhost:9002') + await addServerToAccountBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'localhost:' + servers[1].port) }) it('Should hide its videos', async function () { @@ -291,11 +291,11 @@ describe('Test blocklist', function () { const block = blocks[ 0 ] expect(block.byAccount.displayName).to.equal('root') expect(block.byAccount.name).to.equal('root') - expect(block.blockedServer.host).to.equal('localhost:9002') + expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port) }) it('Should unblock the remote server', async function () { - await removeServerFromAccountBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'localhost:9002') + await removeServerFromAccountBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'localhost:' + servers[1].port) }) it('Should display its videos', function () { @@ -324,7 +324,7 @@ describe('Test blocklist', function () { }) it('Should block a remote account', async function () { - await addAccountToServerBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'user2@localhost:9002') + await addAccountToServerBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'user2@localhost:' + servers[1].port) }) it('Should hide its videos', async function () { @@ -387,7 +387,7 @@ describe('Test blocklist', function () { expect(block.byAccount.name).to.equal('peertube') expect(block.blockedAccount.displayName).to.equal('user2') expect(block.blockedAccount.name).to.equal('user2') - expect(block.blockedAccount.host).to.equal('localhost:9002') + expect(block.blockedAccount.host).to.equal('localhost:' + servers[1].port) } { @@ -401,12 +401,12 @@ describe('Test blocklist', function () { expect(block.byAccount.name).to.equal('peertube') expect(block.blockedAccount.displayName).to.equal('user1') expect(block.blockedAccount.name).to.equal('user1') - expect(block.blockedAccount.host).to.equal('localhost:9001') + expect(block.blockedAccount.host).to.equal('localhost:' + servers[0].port) } }) it('Should unblock the remote account', async function () { - await removeAccountFromServerBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'user2@localhost:9002') + await removeAccountFromServerBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'user2@localhost:' + servers[1].port) }) it('Should display its videos', async function () { @@ -446,7 +446,7 @@ describe('Test blocklist', function () { }) it('Should block a remote server', async function () { - await addServerToServerBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'localhost:9002') + await addServerToServerBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'localhost:' + servers[1].port) }) it('Should hide its videos', async function () { @@ -478,11 +478,11 @@ describe('Test blocklist', function () { const block = blocks[ 0 ] expect(block.byAccount.displayName).to.equal('peertube') expect(block.byAccount.name).to.equal('peertube') - expect(block.blockedServer.host).to.equal('localhost:9002') + expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port) }) it('Should unblock the remote server', async function () { - await removeServerFromServerBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'localhost:9002') + await removeServerFromServerBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'localhost:' + servers[1].port) }) it('Should list all videos', async function () { diff --git a/server/tests/api/users/users-verification.ts b/server/tests/api/users/users-verification.ts index 514acf2e7..3b37a26cf 100644 --- a/server/tests/api/users/users-verification.ts +++ b/server/tests/api/users/users-verification.ts @@ -30,11 +30,12 @@ describe('Test users account verification', function () { before(async function () { this.timeout(30000) - await MockSmtpServer.Instance.collectEmails(emails) + const port = await MockSmtpServer.Instance.collectEmails(emails) const overrideConfig = { smtp: { - hostname: 'localhost' + hostname: 'localhost', + port } } server = await flushAndRunServer(1, overrideConfig) diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts index 68c1e9a8d..89904759a 100644 --- a/server/tests/api/videos/multiple-servers.ts +++ b/server/tests/api/videos/multiple-servers.ts @@ -9,18 +9,17 @@ import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/ import { addVideoChannel, checkTmpIsEmpty, - checkVideoFilesWereRemoved, cleanupTests, + checkVideoFilesWereRemoved, + cleanupTests, completeVideoCheck, createUser, dateIsValid, doubleFollow, flushAndRunMultipleServers, - flushTests, getLocalVideos, getVideo, getVideoChannelsList, getVideosList, - killallServers, rateVideo, removeVideo, ServerInfo, @@ -110,7 +109,7 @@ describe('Test multiple servers', function () { // All servers should have this video let publishedAt: string = null for (const server of servers) { - const isLocal = server.url === 'http://localhost:9001' + const isLocal = server.url === 'http://localhost:' + servers[0].port const checkAttributes = { name: 'my super name for server 1', category: 5, @@ -122,7 +121,7 @@ describe('Test multiple servers', function () { originallyPublishedAt: '2019-02-10T13:38:14.449Z', account: { name: 'root', - host: 'localhost:9001' + host: 'localhost:' + servers[0].port }, isLocal, publishedAt, @@ -187,7 +186,7 @@ describe('Test multiple servers', function () { // All servers should have this video for (const server of servers) { - const isLocal = server.url === 'http://localhost:9002' + const isLocal = server.url === 'http://localhost:' + servers[1].port const checkAttributes = { name: 'my super name for server 2', category: 4, @@ -198,7 +197,7 @@ describe('Test multiple servers', function () { support: 'my super support text for server 2', account: { name: 'user1', - host: 'localhost:9002' + host: 'localhost:' + servers[1].port }, isLocal, commentsEnabled: true, @@ -278,7 +277,7 @@ describe('Test multiple servers', function () { // All servers should have this video for (const server of servers) { - const isLocal = server.url === 'http://localhost:9003' + const isLocal = server.url === 'http://localhost:' + servers[2].port const res = await getVideosList(server.url) const videos = res.body.data @@ -306,7 +305,7 @@ describe('Test multiple servers', function () { support: 'my super support text for server 3', account: { name: 'root', - host: 'localhost:9003' + host: 'localhost:' + servers[2].port }, isLocal, duration: 5, @@ -340,7 +339,7 @@ describe('Test multiple servers', function () { support: 'my super support text for server 3-2', account: { name: 'root', - host: 'localhost:9003' + host: 'localhost:' + servers[2].port }, commentsEnabled: true, downloadEnabled: true, @@ -646,7 +645,7 @@ describe('Test multiple servers', function () { const videoUpdated = videos.find(video => video.name === 'my super video updated') expect(!!videoUpdated).to.be.true - const isLocal = server.url === 'http://localhost:9003' + const isLocal = server.url === 'http://localhost:' + servers[2].port const checkAttributes = { name: 'my super video updated', category: 10, @@ -658,7 +657,7 @@ describe('Test multiple servers', function () { originallyPublishedAt: '2019-02-11T13:38:14.449Z', account: { name: 'root', - host: 'localhost:9003' + host: 'localhost:' + servers[2].port }, isLocal, duration: 5, @@ -813,7 +812,7 @@ describe('Test multiple servers', function () { expect(comment).to.not.be.undefined expect(comment.inReplyToCommentId).to.be.null expect(comment.account.name).to.equal('root') - expect(comment.account.host).to.equal('localhost:9001') + expect(comment.account.host).to.equal('localhost:' + servers[0].port) expect(comment.totalReplies).to.equal(3) expect(dateIsValid(comment.createdAt as string)).to.be.true expect(dateIsValid(comment.updatedAt as string)).to.be.true @@ -824,7 +823,7 @@ describe('Test multiple servers', function () { expect(comment).to.not.be.undefined expect(comment.inReplyToCommentId).to.be.null expect(comment.account.name).to.equal('root') - expect(comment.account.host).to.equal('localhost:9003') + expect(comment.account.host).to.equal('localhost:' + servers[2].port) expect(comment.totalReplies).to.equal(0) expect(dateIsValid(comment.createdAt as string)).to.be.true expect(dateIsValid(comment.updatedAt as string)).to.be.true @@ -842,25 +841,25 @@ describe('Test multiple servers', function () { const tree: VideoCommentThreadTree = res2.body expect(tree.comment.text).equal('my super first comment') expect(tree.comment.account.name).equal('root') - expect(tree.comment.account.host).equal('localhost:9001') + expect(tree.comment.account.host).equal('localhost:' + servers[0].port) expect(tree.children).to.have.lengthOf(2) const firstChild = tree.children[0] expect(firstChild.comment.text).to.equal('my super answer to thread 1') expect(firstChild.comment.account.name).equal('root') - expect(firstChild.comment.account.host).equal('localhost:9002') + expect(firstChild.comment.account.host).equal('localhost:' + servers[1].port) expect(firstChild.children).to.have.lengthOf(1) childOfFirstChild = firstChild.children[0] expect(childOfFirstChild.comment.text).to.equal('my super answer to answer of thread 1') expect(childOfFirstChild.comment.account.name).equal('root') - expect(childOfFirstChild.comment.account.host).equal('localhost:9003') + expect(childOfFirstChild.comment.account.host).equal('localhost:' + servers[2].port) expect(childOfFirstChild.children).to.have.lengthOf(0) const secondChild = tree.children[1] expect(secondChild.comment.text).to.equal('my second answer to thread 1') expect(secondChild.comment.account.name).equal('root') - expect(secondChild.comment.account.host).equal('localhost:9003') + expect(secondChild.comment.account.host).equal('localhost:' + servers[2].port) expect(secondChild.children).to.have.lengthOf(0) } }) @@ -915,7 +914,7 @@ describe('Test multiple servers', function () { expect(comment).to.not.be.undefined expect(comment.inReplyToCommentId).to.be.null expect(comment.account.name).to.equal('root') - expect(comment.account.host).to.equal('localhost:9003') + expect(comment.account.host).to.equal('localhost:' + servers[2].port) expect(comment.totalReplies).to.equal(0) expect(dateIsValid(comment.createdAt as string)).to.be.true expect(dateIsValid(comment.updatedAt as string)).to.be.true @@ -971,7 +970,7 @@ describe('Test multiple servers', function () { const res = await getVideosList(server.url) const video = res.body.data.find(v => v.name === 'minimum parameters') - const isLocal = server.url === 'http://localhost:9002' + const isLocal = server.url === 'http://localhost:' + servers[1].port const checkAttributes = { name: 'minimum parameters', category: null, @@ -982,7 +981,7 @@ describe('Test multiple servers', function () { support: null, account: { name: 'root', - host: 'localhost:9002' + host: 'localhost:' + servers[1].port }, isLocal, duration: 5, diff --git a/server/tests/api/videos/services.ts b/server/tests/api/videos/services.ts index e9ad947b2..38e232e5f 100644 --- a/server/tests/api/videos/services.ts +++ b/server/tests/api/videos/services.ts @@ -27,13 +27,13 @@ describe('Test services', function () { }) it('Should have a valid oEmbed response', async function () { - const oembedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid + const oembedUrl = 'http://localhost:' + server.port + '/videos/watch/' + server.video.uuid const res = await getOEmbed(server.url, oembedUrl) const expectedHtml = '' - const expectedThumbnailUrl = 'http://localhost:9001/static/previews/' + server.video.uuid + '.jpg' + const expectedThumbnailUrl = 'http://localhost:' + server.port + '/static/previews/' + server.video.uuid + '.jpg' expect(res.body.html).to.equal(expectedHtml) expect(res.body.title).to.equal(server.video.name) @@ -46,14 +46,14 @@ describe('Test services', function () { }) it('Should have a valid oEmbed response with small max height query', async function () { - const oembedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid + const oembedUrl = 'http://localhost:' + server.port + '/videos/watch/' + server.video.uuid const format = 'json' const maxHeight = 50 const maxWidth = 50 const res = await getOEmbed(server.url, oembedUrl, format, maxHeight, maxWidth) const expectedHtml = '' expect(res.body.html).to.equal(expectedHtml) diff --git a/server/tests/api/videos/single-server.ts b/server/tests/api/videos/single-server.ts index 1f366b642..b0412f4df 100644 --- a/server/tests/api/videos/single-server.ts +++ b/server/tests/api/videos/single-server.ts @@ -47,7 +47,7 @@ describe('Test a single server', function () { support: 'my super support text', account: { name: 'root', - host: 'localhost:9001' + host: 'localhost:' + server.port }, isLocal: true, duration: 5, @@ -80,7 +80,7 @@ describe('Test a single server', function () { support: 'my super support text updated', account: { name: 'root', - host: 'localhost:9001' + host: 'localhost:' + server.port }, isLocal: true, tags: [ 'tagup1', 'tagup2' ], diff --git a/server/tests/api/videos/video-abuse.ts b/server/tests/api/videos/video-abuse.ts index 7318497d5..a2f3ee161 100644 --- a/server/tests/api/videos/video-abuse.ts +++ b/server/tests/api/videos/video-abuse.ts @@ -9,7 +9,6 @@ import { flushAndRunMultipleServers, getVideoAbusesList, getVideosList, - killallServers, reportVideoAbuse, ServerInfo, setAccessTokensToServers, @@ -90,7 +89,7 @@ describe('Test video abuses', function () { const abuse: VideoAbuse = res1.body.data[0] expect(abuse.reason).to.equal('my super bad reason') expect(abuse.reporterAccount.name).to.equal('root') - expect(abuse.reporterAccount.host).to.equal('localhost:9001') + expect(abuse.reporterAccount.host).to.equal('localhost:' + servers[0].port) expect(abuse.video.id).to.equal(servers[0].video.id) const res2 = await getVideoAbusesList(servers[1].url, servers[1].accessToken) @@ -118,7 +117,7 @@ describe('Test video abuses', function () { const abuse1: VideoAbuse = res1.body.data[0] expect(abuse1.reason).to.equal('my super bad reason') expect(abuse1.reporterAccount.name).to.equal('root') - expect(abuse1.reporterAccount.host).to.equal('localhost:9001') + expect(abuse1.reporterAccount.host).to.equal('localhost:' + servers[0].port) expect(abuse1.video.id).to.equal(servers[0].video.id) expect(abuse1.state.id).to.equal(VideoAbuseState.PENDING) expect(abuse1.state.label).to.equal('Pending') @@ -127,7 +126,7 @@ describe('Test video abuses', function () { const abuse2: VideoAbuse = res1.body.data[1] expect(abuse2.reason).to.equal('my super bad reason 2') expect(abuse2.reporterAccount.name).to.equal('root') - expect(abuse2.reporterAccount.host).to.equal('localhost:9001') + expect(abuse2.reporterAccount.host).to.equal('localhost:' + servers[0].port) expect(abuse2.video.id).to.equal(servers[1].video.id) expect(abuse2.state.id).to.equal(VideoAbuseState.PENDING) expect(abuse2.state.label).to.equal('Pending') @@ -141,7 +140,7 @@ describe('Test video abuses', function () { abuseServer2 = res2.body.data[0] expect(abuseServer2.reason).to.equal('my super bad reason 2') expect(abuseServer2.reporterAccount.name).to.equal('root') - expect(abuseServer2.reporterAccount.host).to.equal('localhost:9001') + expect(abuseServer2.reporterAccount.host).to.equal('localhost:' + servers[0].port) expect(abuseServer2.state.id).to.equal(VideoAbuseState.PENDING) expect(abuseServer2.state.label).to.equal('Pending') expect(abuseServer2.moderationComment).to.be.null diff --git a/server/tests/api/videos/video-channels.ts b/server/tests/api/videos/video-channels.ts index 345e96f43..f09148404 100644 --- a/server/tests/api/videos/video-channels.ts +++ b/server/tests/api/videos/video-channels.ts @@ -213,7 +213,7 @@ describe('Test video channels', function () { this.timeout(10000) for (const server of servers) { - const channelURI = 'second_video_channel@localhost:9001' + const channelURI = 'second_video_channel@localhost:' + server.port const res1 = await getVideoChannelVideos(server.url, server.accessToken, channelURI, 0, 5) expect(res1.body.total).to.equal(1) expect(res1.body.data).to.be.an('array') @@ -234,11 +234,11 @@ describe('Test video channels', function () { this.timeout(10000) for (const server of servers) { - const secondChannelURI = 'second_video_channel@localhost:9001' + const secondChannelURI = 'second_video_channel@localhost:' + server.port const res1 = await getVideoChannelVideos(server.url, server.accessToken, secondChannelURI, 0, 5) expect(res1.body.total).to.equal(0) - const channelURI = 'root_channel@localhost:9001' + const channelURI = 'root_channel@localhost:' + server.port const res2 = await getVideoChannelVideos(server.url, server.accessToken, channelURI, 0, 5) expect(res2.body.total).to.equal(1) diff --git a/server/tests/api/videos/video-comments.ts b/server/tests/api/videos/video-comments.ts index 22fd8c058..82182cc7c 100644 --- a/server/tests/api/videos/video-comments.ts +++ b/server/tests/api/videos/video-comments.ts @@ -66,8 +66,8 @@ describe('Test video comments', function () { expect(comment.videoId).to.equal(videoId) expect(comment.id).to.equal(comment.threadId) expect(comment.account.name).to.equal('root') - expect(comment.account.host).to.equal('localhost:9001') - expect(comment.account.url).to.equal('http://localhost:9001/accounts/root') + expect(comment.account.host).to.equal('localhost:' + server.port) + expect(comment.account.url).to.equal('http://localhost:' + server.port + '/accounts/root') expect(comment.totalReplies).to.equal(0) expect(dateIsValid(comment.createdAt as string)).to.be.true expect(dateIsValid(comment.updatedAt as string)).to.be.true @@ -86,7 +86,7 @@ describe('Test video comments', function () { expect(comment.videoId).to.equal(videoId) expect(comment.id).to.equal(comment.threadId) expect(comment.account.name).to.equal('root') - expect(comment.account.host).to.equal('localhost:9001') + expect(comment.account.host).to.equal('localhost:' + server.port) await testImage(server.url, 'avatar-resized', comment.account.avatar.path, '.png') diff --git a/server/tests/api/videos/video-hls.ts b/server/tests/api/videos/video-hls.ts index 22031c18b..4565d0ebe 100644 --- a/server/tests/api/videos/video-hls.ts +++ b/server/tests/api/videos/video-hls.ts @@ -5,13 +5,12 @@ import 'mocha' import { checkDirectoryIsEmpty, checkSegmentHash, - checkTmpIsEmpty, cleanupTests, + checkTmpIsEmpty, + cleanupTests, doubleFollow, flushAndRunMultipleServers, - flushTests, getPlaylist, getVideo, - killallServers, removeVideo, ServerInfo, setAccessTokensToServers, @@ -51,7 +50,7 @@ async function checkHlsPlaylist (servers: ServerInfo[], videoUUID: string) { { for (const resolution of resolutions) { - const res2 = await getPlaylist(`http://localhost:9001/static/streaming-playlists/hls/${videoUUID}/${resolution}.m3u8`) + const res2 = await getPlaylist(`http://localhost:${server.port}/static/streaming-playlists/hls/${videoUUID}/${resolution}.m3u8`) const subPlaylist = res2.text expect(subPlaylist).to.contain(`${videoUUID}-${resolution}-fragmented.mp4`) @@ -59,7 +58,7 @@ async function checkHlsPlaylist (servers: ServerInfo[], videoUUID: string) { } { - const baseUrl = 'http://localhost:9001/static/streaming-playlists/hls' + const baseUrl = 'http://localhost:' + server.port + '/static/streaming-playlists/hls' for (const resolution of resolutions) { await checkSegmentHash(baseUrl, baseUrl, videoUUID, resolution, hlsPlaylist) diff --git a/server/tests/api/videos/video-transcoder.ts b/server/tests/api/videos/video-transcoder.ts index 3cd43e99b..45a8c09f0 100644 --- a/server/tests/api/videos/video-transcoder.ts +++ b/server/tests/api/videos/video-transcoder.ts @@ -6,21 +6,21 @@ import { omit } from 'lodash' import { getMaxBitrate, VideoDetails, VideoResolution, VideoState } from '../../../../shared/models/videos' import { audio, getVideoFileBitrate, getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffmpeg-utils' import { - buildAbsoluteFixturePath, cleanupTests, + buildAbsoluteFixturePath, + cleanupTests, doubleFollow, flushAndRunMultipleServers, generateHighBitrateVideo, getMyVideos, getVideo, getVideosList, - killallServers, root, ServerInfo, setAccessTokensToServers, uploadVideo, webtorrentAdd } from '../../../../shared/extra-utils' -import { extname, join } from 'path' +import { join } from 'path' import { waitJobs } from '../../../../shared/extra-utils/server/jobs' import { VIDEO_TRANSCODING_FPS } from '../../../../server/initializers/constants' @@ -121,7 +121,7 @@ describe('Test video transcoding', function () { expect(videoDetails.files).to.have.lengthOf(4) - const path = join(root(), 'test2', 'videos', video.uuid + '-240.mp4') + const path = join(root(), 'test' + servers[1].internalServerNumber, 'videos', video.uuid + '-240.mp4') const probe = await audio.get(path) if (probe.audioStream) { @@ -152,7 +152,7 @@ describe('Test video transcoding', function () { const videoDetails: VideoDetails = res2.body expect(videoDetails.files).to.have.lengthOf(4) - const path = join(root(), 'test2', 'videos', video.uuid + '-240.mp4') + const path = join(root(), 'test' + servers[1].internalServerNumber, 'videos', video.uuid + '-240.mp4') const probe = await audio.get(path) expect(probe).to.not.have.property('audioStream') } @@ -179,7 +179,7 @@ describe('Test video transcoding', function () { expect(videoDetails.files).to.have.lengthOf(4) const fixturePath = buildAbsoluteFixturePath(videoAttributes.fixture) const fixtureVideoProbe = await audio.get(fixturePath) - const path = join(root(), 'test2', 'videos', video.uuid + '-240.mp4') + const path = join(root(), 'test' + servers[1].internalServerNumber, 'videos', video.uuid + '-240.mp4') const videoProbe = await audio.get(path) if (videoProbe.audioStream && fixtureVideoProbe.audioStream) { const toOmit = [ 'max_bit_rate', 'duration', 'duration_ts', 'nb_frames', 'start_time', 'start_pts' ] @@ -216,13 +216,13 @@ describe('Test video transcoding', function () { expect(videoDetails.files[ 3 ].fps).to.be.below(31) for (const resolution of [ '240', '360', '480' ]) { - const path = join(root(), 'test2', 'videos', video.uuid + '-' + resolution + '.mp4') + const path = join(root(), 'test' + servers[1].internalServerNumber, 'videos', video.uuid + '-' + resolution + '.mp4') const fps = await getVideoFileFPS(path) expect(fps).to.be.below(31) } - const path = join(root(), 'test2', 'videos', video.uuid + '-720.mp4') + const path = join(root(), 'test' + servers[1].internalServerNumber, 'videos', video.uuid + '-720.mp4') const fps = await getVideoFileFPS(path) expect(fps).to.be.above(58).and.below(62) @@ -310,7 +310,7 @@ describe('Test video transcoding', function () { const video = res.body.data.find(v => v.name === videoAttributes.name) for (const resolution of ['240', '360', '480', '720', '1080']) { - const path = join(root(), 'test2', 'videos', video.uuid + '-' + resolution + '.mp4') + const path = join(root(), 'test' + servers[1].internalServerNumber, 'videos', video.uuid + '-' + resolution + '.mp4') const bitrate = await getVideoFileBitrate(path) const fps = await getVideoFileFPS(path) const resolution2 = await getVideoFileResolution(path) diff --git a/server/tests/cli/optimize-old-videos.ts b/server/tests/cli/optimize-old-videos.ts index 5e12c0089..3822fca42 100644 --- a/server/tests/cli/optimize-old-videos.ts +++ b/server/tests/cli/optimize-old-videos.ts @@ -8,14 +8,16 @@ import { doubleFollow, execCLI, flushAndRunMultipleServers, - flushTests, generateHighBitrateVideo, + generateHighBitrateVideo, getEnvCli, getVideo, getVideosList, - killallServers, root, + root, ServerInfo, setAccessTokensToServers, - uploadVideo, viewVideo, wait + uploadVideo, + viewVideo, + wait } from '../../../shared/extra-utils' import { waitJobs } from '../../../shared/extra-utils/server/jobs' import { getVideoFileBitrate, getVideoFileFPS, getVideoFileResolution } from '../../helpers/ffmpeg-utils' @@ -102,7 +104,7 @@ describe('Test optimize old videos', function () { expect(file.size).to.be.below(5000000) - const path = join(root(), 'test1', 'videos', video.uuid + '-' + file.resolution.id + '.mp4') + const path = join(root(), 'test' + servers[0].internalServerNumber, 'videos', video.uuid + '-' + file.resolution.id + '.mp4') const bitrate = await getVideoFileBitrate(path) const fps = await getVideoFileFPS(path) const resolution = await getVideoFileResolution(path) diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index ed41bfa48..3992735e1 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts @@ -284,7 +284,7 @@ function cleanupTests (servers: ServerInfo[]) { } 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.internalServerNumber, 'logs/peertube.log') while (true) { const buf = await readFile(logfile) diff --git a/shared/extra-utils/users/user-notifications.ts b/shared/extra-utils/users/user-notifications.ts index 495ff80d9..f7de542bf 100644 --- a/shared/extra-utils/users/user-notifications.ts +++ b/shared/extra-utils/users/user-notifications.ts @@ -380,7 +380,7 @@ async function checkNewCommentOnMyVideo (base: CheckerBaseParams, uuid: string, } } - const commentUrl = `http://localhost:9001/videos/watch/${uuid};threadId=${threadId}` + const commentUrl = `http://localhost:${base.server.port}/videos/watch/${uuid};threadId=${threadId}` function emailFinder (email: object) { return email[ 'text' ].indexOf(commentUrl) !== -1 } From 48f07b4a4091cb10dc4d179118e155f3a118dca8 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 26 Apr 2019 08:50:52 +0200 Subject: [PATCH 3/5] All API tests in parallel --- scripts/travis.sh | 6 +- server/tests/api/activitypub/client.ts | 11 +- server/tests/api/activitypub/fetch.ts | 17 ++- server/tests/api/activitypub/refresher.ts | 46 ++++---- server/tests/api/activitypub/security.ts | 106 ++++++++++-------- server/tests/api/index-2.ts | 2 - server/tests/api/index-3.ts | 1 - server/tests/api/index-4.ts | 2 - server/tests/api/index.ts | 12 +- server/tests/api/server/config.ts | 19 ++-- server/tests/api/server/contact-form.ts | 2 +- server/tests/api/server/email.ts | 8 +- server/tests/api/server/follows-moderation.ts | 4 +- server/tests/api/server/follows.ts | 2 +- server/tests/api/server/handle-down.ts | 74 ++++++------ server/tests/api/server/logs.ts | 2 +- server/tests/api/travis-1.sh | 4 +- server/tests/api/travis-2.sh | 9 ++ server/tests/api/travis-3.sh | 8 ++ server/tests/api/travis-4.sh | 9 ++ server/tests/api/users/user-subscriptions.ts | 34 +++--- .../tests/api/users/users-multiple-servers.ts | 18 +-- server/tests/api/users/users.ts | 6 +- server/tests/api/videos/multiple-servers.ts | 2 +- server/tests/api/videos/single-server.ts | 19 ++-- .../api/videos/video-change-ownership.ts | 8 +- server/tests/api/videos/video-channels.ts | 8 +- server/tests/api/videos/video-hls.ts | 4 +- server/tests/api/videos/video-playlists.ts | 4 +- .../tests/api/videos/videos-views-cleaner.ts | 16 +-- 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 +- 34 files changed, 286 insertions(+), 222 deletions(-) delete mode 100644 server/tests/api/index-2.ts delete mode 100644 server/tests/api/index-3.ts delete mode 100644 server/tests/api/index-4.ts create mode 100644 server/tests/api/travis-2.sh create mode 100644 server/tests/api/travis-3.sh create mode 100644 server/tests/api/travis-4.sh diff --git a/scripts/travis.sh b/scripts/travis.sh index 67d8b5d7e..772d3906a 100755 --- a/scripts/travis.sh +++ b/scripts/travis.sh @@ -23,13 +23,13 @@ elif [ "$1" = "api-1" ]; then sh ./server/tests/api/travis-1.sh elif [ "$1" = "api-2" ]; then npm run build:server - mocha --timeout 5000 --exit --require ts-node/register --bail server/tests/api/index-2.ts + sh ./server/tests/api/travis-2.sh elif [ "$1" = "api-3" ]; then npm run build:server - mocha --timeout 5000 --exit --require ts-node/register --bail server/tests/api/index-3.ts + sh ./server/tests/api/travis-3.sh elif [ "$1" = "api-4" ]; then npm run build:server - mocha --timeout 5000 --exit --require ts-node/register --bail server/tests/api/index-4.ts + sh ./server/tests/api/travis-4.sh elif [ "$1" = "lint" ]; then npm run tslint -- --project ./tsconfig.json -c ./tslint.json server.ts "server/**/*.ts" "shared/**/*.ts" diff --git a/server/tests/api/activitypub/client.ts b/server/tests/api/activitypub/client.ts index edf588c16..34c6be49b 100644 --- a/server/tests/api/activitypub/client.ts +++ b/server/tests/api/activitypub/client.ts @@ -3,6 +3,7 @@ import * as chai from 'chai' import 'mocha' import { + cleanupTests, doubleFollow, flushAndRunMultipleServers, flushTests, @@ -39,7 +40,7 @@ describe('Test activitypub', function () { const object = res.body expect(object.type).to.equal('Person') - expect(object.id).to.equal('http://localhost:9001/accounts/root') + expect(object.id).to.equal('http://localhost:' + servers[0].port + '/accounts/root') expect(object.name).to.equal('root') expect(object.preferredUsername).to.equal('root') }) @@ -49,17 +50,17 @@ describe('Test activitypub', function () { const object = res.body expect(object.type).to.equal('Video') - expect(object.id).to.equal('http://localhost:9001/videos/watch/' + videoUUID) + expect(object.id).to.equal('http://localhost:' + servers[0].port + '/videos/watch/' + videoUUID) expect(object.name).to.equal('video') }) it('Should redirect to the origin video object', async function () { const res = await makeActivityPubGetRequest(servers[1].url, '/videos/watch/' + videoUUID, 302) - expect(res.header.location).to.equal('http://localhost:9001/videos/watch/' + videoUUID) + expect(res.header.location).to.equal('http://localhost:' + servers[0].port + '/videos/watch/' + videoUUID) }) - after(function () { - killallServers(servers) + after(async function () { + await cleanupTests(servers) }) }) diff --git a/server/tests/api/activitypub/fetch.ts b/server/tests/api/activitypub/fetch.ts index 7240bb0fb..3a1c0d321 100644 --- a/server/tests/api/activitypub/fetch.ts +++ b/server/tests/api/activitypub/fetch.ts @@ -3,6 +3,7 @@ import 'mocha' import { + cleanupTests, closeAllSequelize, createUser, doubleFollow, @@ -48,8 +49,16 @@ describe('Test ActivityPub fetcher', function () { const badVideoUUID = res.body.video.uuid await uploadVideo(servers[0].url, userAccessToken, { name: 'video user' }) - await setActorField(1, 'http://localhost:9001/accounts/user1', 'url', 'http://localhost:9002/accounts/user1') - await setVideoField(1, badVideoUUID, 'url', 'http://localhost:9003/videos/watch/' + badVideoUUID) + { + const to = 'http://localhost:' + servers[0].port + '/accounts/user1' + const value = 'http://localhost:' + servers[1].port + '/accounts/user1' + await setActorField(servers[0].internalServerNumber, to, 'url', value) + } + + { + const value = 'http://localhost:' + servers[2].port + '/videos/watch/' + badVideoUUID + await setVideoField(servers[0].internalServerNumber, badVideoUUID, 'url', value) + } }) it('Should add only the video with a valid actor URL', async function () { @@ -78,7 +87,9 @@ describe('Test ActivityPub fetcher', function () { }) after(async function () { - killallServers(servers) + this.timeout(10000) + + await cleanupTests(servers) await closeAllSequelize(servers) }) diff --git a/server/tests/api/activitypub/refresher.ts b/server/tests/api/activitypub/refresher.ts index 9be9aa495..921ee874c 100644 --- a/server/tests/api/activitypub/refresher.ts +++ b/server/tests/api/activitypub/refresher.ts @@ -2,13 +2,14 @@ import 'mocha' import { + cleanupTests, closeAllSequelize, createVideoPlaylist, doubleFollow, flushAndRunMultipleServers, generateUserAccessToken, getVideo, getVideoPlaylist, - killallServers, rateVideo, + killallServers, reRunServer, ServerInfo, setAccessTokensToServers, @@ -48,26 +49,26 @@ describe('Test AP refresher', function () { } { - const a1 = await generateUserAccessToken(servers[1], 'user1') - await uploadVideo(servers[1].url, a1, { name: 'video4' }) + const a1 = await generateUserAccessToken(servers[ 1 ], 'user1') + await uploadVideo(servers[ 1 ].url, a1, { name: 'video4' }) - const a2 = await generateUserAccessToken(servers[1], 'user2') - await uploadVideo(servers[1].url, a2, { name: 'video5' }) + const a2 = await generateUserAccessToken(servers[ 1 ], 'user2') + await uploadVideo(servers[ 1 ].url, a2, { name: 'video5' }) } { - const playlistAttrs = { displayName: 'playlist1', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].videoChannel.id } - const res = await createVideoPlaylist({ url: servers[1].url, token: servers[1].accessToken, playlistAttrs }) + const playlistAttrs = { displayName: 'playlist1', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[ 1 ].videoChannel.id } + const res = await createVideoPlaylist({ url: servers[ 1 ].url, token: servers[ 1 ].accessToken, playlistAttrs }) playlistUUID1 = res.body.videoPlaylist.uuid } { - const playlistAttrs = { displayName: 'playlist2', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].videoChannel.id } - const res = await createVideoPlaylist({ url: servers[1].url, token: servers[1].accessToken, playlistAttrs }) + const playlistAttrs = { displayName: 'playlist2', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[ 1 ].videoChannel.id } + const res = await createVideoPlaylist({ url: servers[ 1 ].url, token: servers[ 1 ].accessToken, playlistAttrs }) playlistUUID2 = res.body.videoPlaylist.uuid } - await doubleFollow(servers[0], servers[1]) + await doubleFollow(servers[ 0 ], servers[ 1 ]) }) describe('Videos refresher', function () { @@ -78,7 +79,7 @@ describe('Test AP refresher', function () { await wait(10000) // Change UUID so the remote server returns a 404 - await setVideoField(2, videoUUID1, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174f') + await setVideoField(servers[ 1 ].internalServerNumber, videoUUID1, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174f') await getVideo(servers[ 0 ].url, videoUUID1) await getVideo(servers[ 0 ].url, videoUUID2) @@ -94,7 +95,7 @@ describe('Test AP refresher', function () { killallServers([ servers[ 1 ] ]) - await setVideoField(2, videoUUID3, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174e') + await setVideoField(servers[ 1 ].internalServerNumber, videoUUID3, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174e') // Video will need a refresh await wait(10000) @@ -121,15 +122,16 @@ describe('Test AP refresher', function () { await wait(10000) // Change actor name so the remote server returns a 404 - await setActorField(2, 'http://localhost:9002/accounts/user2', 'preferredUsername', 'toto') + const to = 'http://localhost:' + servers[ 1 ].port + '/accounts/user2' + await setActorField(servers[ 1 ].internalServerNumber, to, 'preferredUsername', 'toto') - await getAccount(servers[ 0 ].url, 'user1@localhost:9002') - await getAccount(servers[ 0 ].url, 'user2@localhost:9002') + await getAccount(servers[ 0 ].url, 'user1@localhost:' + servers[ 1 ].port) + await getAccount(servers[ 0 ].url, 'user2@localhost:' + servers[ 1 ].port) await waitJobs(servers) - await getAccount(servers[ 0 ].url, 'user1@localhost:9002', 200) - await getAccount(servers[ 0 ].url, 'user2@localhost:9002', 404) + await getAccount(servers[ 0 ].url, 'user1@localhost:' + servers[ 1 ].port, 200) + await getAccount(servers[ 0 ].url, 'user2@localhost:' + servers[ 1 ].port, 404) }) }) @@ -141,7 +143,7 @@ describe('Test AP refresher', function () { await wait(10000) // Change UUID so the remote server returns a 404 - await setPlaylistField(2, playlistUUID2, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b178e') + await setPlaylistField(servers[ 1 ].internalServerNumber, playlistUUID2, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b178e') await getVideoPlaylist(servers[ 0 ].url, playlistUUID1) await getVideoPlaylist(servers[ 0 ].url, playlistUUID2) @@ -153,7 +155,11 @@ describe('Test AP refresher', function () { }) }) - after(function () { - killallServers(servers) + after(async function () { + this.timeout(10000) + + await cleanupTests(servers) + + await closeAllSequelize(servers) }) }) diff --git a/server/tests/api/activitypub/security.ts b/server/tests/api/activitypub/security.ts index 11e6859bf..dc960c5c3 100644 --- a/server/tests/api/activitypub/security.ts +++ b/server/tests/api/activitypub/security.ts @@ -3,9 +3,9 @@ import 'mocha' import { + cleanupTests, closeAllSequelize, flushAndRunMultipleServers, - flushTests, killallServers, ServerInfo, setActorField @@ -18,18 +18,26 @@ import { makeFollowRequest, makePOSTAPRequest } from '../../../../shared/extra-u const expect = chai.expect -function setKeysOfServer2 (serverNumber: number, publicKey: string, privateKey: string) { +function setKeysOfServer (onServer: ServerInfo, ofServer: ServerInfo, publicKey: string, privateKey: string) { return Promise.all([ - setActorField(serverNumber, 'http://localhost:9002/accounts/peertube', 'publicKey', publicKey), - setActorField(serverNumber, 'http://localhost:9002/accounts/peertube', 'privateKey', privateKey) + setActorField(onServer.internalServerNumber, 'http://localhost:' + ofServer.port + '/accounts/peertube', 'publicKey', publicKey), + setActorField(onServer.internalServerNumber, 'http://localhost:' + ofServer.port + '/accounts/peertube', 'privateKey', privateKey) ]) } -function setKeysOfServer3 (serverNumber: number, publicKey: string, privateKey: string) { - return Promise.all([ - setActorField(serverNumber, 'http://localhost:9003/accounts/peertube', 'publicKey', publicKey), - setActorField(serverNumber, 'http://localhost:9003/accounts/peertube', 'privateKey', privateKey) - ]) +function getAnnounceWithoutContext (server2: ServerInfo) { + const json = require('./json/peertube/announce-without-context.json') + const result: typeof json = {} + + for (const key of Object.keys(json)) { + if (Array.isArray(json[key])) { + result[key] = json[key].map(v => v.replace(':9002', `:${server2.port}`)) + } else { + result[ key ] = json[ key ].replace(':9002', `:${server2.port}`) + } + } + + return result } describe('Test ActivityPub security', function () { @@ -38,13 +46,13 @@ describe('Test ActivityPub security', function () { const keys = require('./json/peertube/keys.json') const invalidKeys = require('./json/peertube/invalid-keys.json') - const baseHttpSignature = { + const baseHttpSignature = () => ({ algorithm: HTTP_SIGNATURE.ALGORITHM, authorizationHeaderName: HTTP_SIGNATURE.HEADER_NAME, - keyId: 'acct:peertube@localhost:9002', + keyId: 'acct:peertube@localhost:' + servers[1].port, key: keys.privateKey, headers: HTTP_SIGNATURE.HEADERS_TO_SIGN - } + }) // --------------------------------------------------------------- @@ -55,56 +63,56 @@ describe('Test ActivityPub security', function () { url = servers[0].url + '/inbox' - await setKeysOfServer2(1, keys.publicKey, keys.privateKey) + await setKeysOfServer(servers[0], servers[1], keys.publicKey, keys.privateKey) - const to = { url: 'http://localhost:9001/accounts/peertube' } - const by = { url: 'http://localhost:9002/accounts/peertube', privateKey: keys.privateKey } + const to = { url: 'http://localhost:' + servers[0].port + '/accounts/peertube' } + const by = { url: 'http://localhost:' + servers[1].port + '/accounts/peertube', privateKey: keys.privateKey } await makeFollowRequest(to, by) }) describe('When checking HTTP signature', function () { it('Should fail with an invalid digest', async function () { - const body = activityPubContextify(require('./json/peertube/announce-without-context.json')) + const body = activityPubContextify(getAnnounceWithoutContext(servers[1])) const headers = { Digest: buildDigest({ hello: 'coucou' }) } - const { response } = await makePOSTAPRequest(url, body, baseHttpSignature, headers) + const { response } = await makePOSTAPRequest(url, body, baseHttpSignature(), headers) expect(response.statusCode).to.equal(403) }) it('Should fail with an invalid date', async function () { - const body = activityPubContextify(require('./json/peertube/announce-without-context.json')) + const body = activityPubContextify(getAnnounceWithoutContext(servers[1])) const headers = buildGlobalHeaders(body) headers['date'] = 'Wed, 21 Oct 2015 07:28:00 GMT' - const { response } = await makePOSTAPRequest(url, body, baseHttpSignature, headers) + const { response } = await makePOSTAPRequest(url, body, baseHttpSignature(), headers) expect(response.statusCode).to.equal(403) }) it('Should fail with bad keys', async function () { - await setKeysOfServer2(1, invalidKeys.publicKey, invalidKeys.privateKey) - await setKeysOfServer2(2, invalidKeys.publicKey, invalidKeys.privateKey) + await setKeysOfServer(servers[0], servers[1], invalidKeys.publicKey, invalidKeys.privateKey) + await setKeysOfServer(servers[1], servers[1], invalidKeys.publicKey, invalidKeys.privateKey) - const body = activityPubContextify(require('./json/peertube/announce-without-context.json')) + const body = activityPubContextify(getAnnounceWithoutContext(servers[1])) const headers = buildGlobalHeaders(body) - const { response } = await makePOSTAPRequest(url, body, baseHttpSignature, headers) + const { response } = await makePOSTAPRequest(url, body, baseHttpSignature(), headers) expect(response.statusCode).to.equal(403) }) it('Should succeed with a valid HTTP signature', async function () { - await setKeysOfServer2(1, keys.publicKey, keys.privateKey) - await setKeysOfServer2(2, keys.publicKey, keys.privateKey) + await setKeysOfServer(servers[0], servers[1], keys.publicKey, keys.privateKey) + await setKeysOfServer(servers[1], servers[1], keys.publicKey, keys.privateKey) - const body = activityPubContextify(require('./json/peertube/announce-without-context.json')) + const body = activityPubContextify(getAnnounceWithoutContext(servers[1])) const headers = buildGlobalHeaders(body) - const { response } = await makePOSTAPRequest(url, body, baseHttpSignature, headers) + const { response } = await makePOSTAPRequest(url, body, baseHttpSignature(), headers) expect(response.statusCode).to.equal(204) }) @@ -112,28 +120,28 @@ describe('Test ActivityPub security', function () { describe('When checking Linked Data Signature', function () { before(async () => { - await setKeysOfServer3(3, keys.publicKey, keys.privateKey) + await setKeysOfServer(servers[2], servers[2], keys.publicKey, keys.privateKey) - const to = { url: 'http://localhost:9001/accounts/peertube' } - const by = { url: 'http://localhost:9003/accounts/peertube', privateKey: keys.privateKey } + const to = { url: 'http://localhost:' + servers[0].port + '/accounts/peertube' } + const by = { url: 'http://localhost:' + servers[2].port + '/accounts/peertube', privateKey: keys.privateKey } await makeFollowRequest(to, by) }) it('Should fail with bad keys', async function () { this.timeout(10000) - await setKeysOfServer3(1, invalidKeys.publicKey, invalidKeys.privateKey) - await setKeysOfServer3(3, invalidKeys.publicKey, invalidKeys.privateKey) + await setKeysOfServer(servers[0], servers[2], invalidKeys.publicKey, invalidKeys.privateKey) + await setKeysOfServer(servers[2], servers[2], invalidKeys.publicKey, invalidKeys.privateKey) - const body = require('./json/peertube/announce-without-context.json') - body.actor = 'http://localhost:9003/accounts/peertube' + const body = getAnnounceWithoutContext(servers[1]) + body.actor = 'http://localhost:' + servers[2].port + '/accounts/peertube' - const signer: any = { privateKey: invalidKeys.privateKey, url: 'http://localhost:9003/accounts/peertube' } + const signer: any = { privateKey: invalidKeys.privateKey, url: 'http://localhost:' + servers[2].port + '/accounts/peertube' } const signedBody = await buildSignedActivity(signer, body) const headers = buildGlobalHeaders(signedBody) - const { response } = await makePOSTAPRequest(url, signedBody, baseHttpSignature, headers) + const { response } = await makePOSTAPRequest(url, signedBody, baseHttpSignature(), headers) expect(response.statusCode).to.equal(403) }) @@ -141,20 +149,20 @@ describe('Test ActivityPub security', function () { it('Should fail with an altered body', async function () { this.timeout(10000) - await setKeysOfServer3(1, keys.publicKey, keys.privateKey) - await setKeysOfServer3(3, keys.publicKey, keys.privateKey) + await setKeysOfServer(servers[0], servers[2], keys.publicKey, keys.privateKey) + await setKeysOfServer(servers[0], servers[2], keys.publicKey, keys.privateKey) - const body = require('./json/peertube/announce-without-context.json') - body.actor = 'http://localhost:9003/accounts/peertube' + const body = getAnnounceWithoutContext(servers[1]) + body.actor = 'http://localhost:' + servers[2].port + '/accounts/peertube' - const signer: any = { privateKey: keys.privateKey, url: 'http://localhost:9003/accounts/peertube' } + const signer: any = { privateKey: keys.privateKey, url: 'http://localhost:' + servers[2].port + '/accounts/peertube' } const signedBody = await buildSignedActivity(signer, body) - signedBody.actor = 'http://localhost:9003/account/peertube' + signedBody.actor = 'http://localhost:' + servers[2].port + '/account/peertube' const headers = buildGlobalHeaders(signedBody) - const { response } = await makePOSTAPRequest(url, signedBody, baseHttpSignature, headers) + const { response } = await makePOSTAPRequest(url, signedBody, baseHttpSignature(), headers) expect(response.statusCode).to.equal(403) }) @@ -162,22 +170,24 @@ describe('Test ActivityPub security', function () { it('Should succeed with a valid signature', async function () { this.timeout(10000) - const body = require('./json/peertube/announce-without-context.json') - body.actor = 'http://localhost:9003/accounts/peertube' + const body = getAnnounceWithoutContext(servers[1]) + body.actor = 'http://localhost:' + servers[2].port + '/accounts/peertube' - const signer: any = { privateKey: keys.privateKey, url: 'http://localhost:9003/accounts/peertube' } + const signer: any = { privateKey: keys.privateKey, url: 'http://localhost:' + servers[2].port + '/accounts/peertube' } const signedBody = await buildSignedActivity(signer, body) const headers = buildGlobalHeaders(signedBody) - const { response } = await makePOSTAPRequest(url, signedBody, baseHttpSignature, headers) + const { response } = await makePOSTAPRequest(url, signedBody, baseHttpSignature(), headers) expect(response.statusCode).to.equal(204) }) }) after(async function () { - killallServers(servers) + this.timeout(10000) + + await cleanupTests(servers) await closeAllSequelize(servers) }) diff --git a/server/tests/api/index-2.ts b/server/tests/api/index-2.ts deleted file mode 100644 index ed93faa91..000000000 --- a/server/tests/api/index-2.ts +++ /dev/null @@ -1,2 +0,0 @@ -import './server' -import './users' diff --git a/server/tests/api/index-3.ts b/server/tests/api/index-3.ts deleted file mode 100644 index 39823b82c..000000000 --- a/server/tests/api/index-3.ts +++ /dev/null @@ -1 +0,0 @@ -import './videos' diff --git a/server/tests/api/index-4.ts b/server/tests/api/index-4.ts deleted file mode 100644 index 7d8be2b3d..000000000 --- a/server/tests/api/index-4.ts +++ /dev/null @@ -1,2 +0,0 @@ -import './redundancy' -import './activitypub' diff --git a/server/tests/api/index.ts b/server/tests/api/index.ts index bc140f860..bac77ab2e 100644 --- a/server/tests/api/index.ts +++ b/server/tests/api/index.ts @@ -1,5 +1,9 @@ // Order of the tests we want to execute -import './index-1' -import './index-2' -import './index-3' -import './index-4' +import './activitypub' +import './check-params' +import './notifications' +import './redundancy' +import './search' +import './server' +import './users' +import './videos' diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts index c0d11914b..ca389b7b6 100644 --- a/server/tests/api/server/config.ts +++ b/server/tests/api/server/config.ts @@ -11,9 +11,9 @@ import { getAbout, getConfig, getCustomConfig, - killallServers, + killallServers, parallelTests, registerUser, - reRunServer, + reRunServer, ServerInfo, setAccessTokensToServers, updateCustomConfig } from '../../../../shared/extra-utils' @@ -21,7 +21,7 @@ import { ServerConfig } from '../../../../shared/models' const expect = chai.expect -function checkInitialConfig (data: CustomConfig) { +function checkInitialConfig (server: ServerInfo, data: CustomConfig) { expect(data.instance.name).to.equal('PeerTube') expect(data.instance.shortDescription).to.equal( 'PeerTube, a federated (ActivityPub) video streaming platform using P2P (BitTorrent) directly in the web browser ' + @@ -45,7 +45,7 @@ function checkInitialConfig (data: CustomConfig) { expect(data.signup.limit).to.equal(4) expect(data.signup.requiresEmailVerification).to.be.false - expect(data.admin.email).to.equal('admin1@example.com') + expect(data.admin.email).to.equal('admin' + server.internalServerNumber + '@example.com') expect(data.contactForm.enabled).to.be.true expect(data.user.videoQuota).to.equal(5242880) @@ -89,7 +89,11 @@ function checkUpdatedConfig (data: CustomConfig) { expect(data.signup.limit).to.equal(5) expect(data.signup.requiresEmailVerification).to.be.false - expect(data.admin.email).to.equal('superadmin1@example.com') + // We override admin email in parallel tests, so skip this exception + if (parallelTests() === false) { + expect(data.admin.email).to.equal('superadmin1@example.com') + } + expect(data.contactForm.enabled).to.be.false expect(data.user.videoQuota).to.equal(5242881) @@ -118,6 +122,7 @@ describe('Test config', function () { before(async function () { this.timeout(30000) + server = await flushAndRunServer(1) await setAccessTokensToServers([ server ]) }) @@ -160,7 +165,7 @@ describe('Test config', function () { const res = await getCustomConfig(server.url, server.accessToken) const data = res.body as CustomConfig - checkInitialConfig(data) + checkInitialConfig(server, data) }) it('Should update the customized configuration', async function () { @@ -297,7 +302,7 @@ describe('Test config', function () { const res = await getCustomConfig(server.url, server.accessToken) const data = res.body - checkInitialConfig(data) + checkInitialConfig(server, data) }) after(async function () { diff --git a/server/tests/api/server/contact-form.ts b/server/tests/api/server/contact-form.ts index 0a1c49ef5..87e55060c 100644 --- a/server/tests/api/server/contact-form.ts +++ b/server/tests/api/server/contact-form.ts @@ -54,7 +54,7 @@ describe('Test contact form', function () { expect(email['from'][0]['address']).equal('test-admin@localhost') expect(email['from'][0]['name']).equal('toto@example.com') - expect(email['to'][0]['address']).equal('admin1@example.com') + expect(email['to'][0]['address']).equal('admin' + server.internalServerNumber + '@example.com') expect(email['subject']).contains('Contact form') expect(email['text']).contains('my super message') }) diff --git a/server/tests/api/server/email.ts b/server/tests/api/server/email.ts index 9ccb1c36f..5929a3adb 100644 --- a/server/tests/api/server/email.ts +++ b/server/tests/api/server/email.ts @@ -37,15 +37,17 @@ describe('Test emails', function () { username: 'user_1', password: 'super_password' } + let emailPort: number before(async function () { this.timeout(30000) - await MockSmtpServer.Instance.collectEmails(emails) + emailPort = await MockSmtpServer.Instance.collectEmails(emails) const overrideConfig = { smtp: { - hostname: 'localhost' + hostname: 'localhost', + port: emailPort } } server = await flushAndRunServer(1, overrideConfig) @@ -134,7 +136,7 @@ describe('Test emails', function () { expect(email['from'][0]['name']).equal('localhost:' + server.port) expect(email['from'][0]['address']).equal('test-admin@localhost') - expect(email['to'][0]['address']).equal('admin1@example.com') + expect(email['to'][0]['address']).equal('admin' + server.internalServerNumber + '@example.com') expect(email['subject']).contains('abuse') expect(email['text']).contains(videoUUID) }) diff --git a/server/tests/api/server/follows-moderation.ts b/server/tests/api/server/follows-moderation.ts index fc20f8961..a82acdb34 100644 --- a/server/tests/api/server/follows-moderation.ts +++ b/server/tests/api/server/follows-moderation.ts @@ -29,7 +29,7 @@ async function checkServer1And2HasFollowers (servers: ServerInfo[], state = 'acc const follow = res.body.data[0] as ActorFollow expect(follow.state).to.equal(state) - expect(follow.follower.url).to.equal('http://localhost:' + servers[0].port + 'accounts/peertube') + expect(follow.follower.url).to.equal('http://localhost:' + servers[0].port + '/accounts/peertube') expect(follow.following.url).to.equal('http://localhost:' + servers[1].port + '/accounts/peertube') } @@ -39,7 +39,7 @@ async function checkServer1And2HasFollowers (servers: ServerInfo[], state = 'acc const follow = res.body.data[0] as ActorFollow expect(follow.state).to.equal(state) - expect(follow.follower.url).to.equal('http://localhost:' + servers[0].port + 'accounts/peertube') + expect(follow.follower.url).to.equal('http://localhost:' + servers[0].port + '/accounts/peertube') expect(follow.following.url).to.equal('http://localhost:' + servers[1].port + '/accounts/peertube') } } diff --git a/server/tests/api/server/follows.ts b/server/tests/api/server/follows.ts index d4155667f..e8d6f5138 100644 --- a/server/tests/api/server/follows.ts +++ b/server/tests/api/server/follows.ts @@ -141,7 +141,7 @@ describe('Test follows', function () { it('Should search followers on server 2', async function () { { - const res = await getFollowersListPaginationAndSort(servers[ 2 ].url, 0, 5, 'createdAt', '9001') + const res = await getFollowersListPaginationAndSort(servers[ 2 ].url, 0, 5, 'createdAt', servers[0].port + '') const follows = res.body.data expect(res.body.total).to.equal(1) diff --git a/server/tests/api/server/handle-down.ts b/server/tests/api/server/handle-down.ts index 9a8bc08f9..068654d8c 100644 --- a/server/tests/api/server/handle-down.ts +++ b/server/tests/api/server/handle-down.ts @@ -60,48 +60,50 @@ describe('Test handle downs', function () { privacy: VideoPrivacy.UNLISTED }) - const checkAttributes = { - name: 'my super name for server 1', - category: 5, - licence: 4, - language: 'ja', - nsfw: true, - description: 'my super description for server 1', - support: 'my super support text for server 1', - account: { - name: 'root', - host: 'localhost:' + servers[0].port - }, - isLocal: false, - duration: 10, - tags: [ 'tag1p1', 'tag2p1' ], - privacy: VideoPrivacy.PUBLIC, - commentsEnabled: true, - downloadEnabled: true, - channel: { - name: 'root_channel', - displayName: 'Main root channel', - description: '', - isLocal: false - }, - fixture: 'video_short1.webm', - files: [ - { - resolution: 720, - size: 572456 - } - ] - } - - const unlistedCheckAttributes = immutableAssign(checkAttributes, { - privacy: VideoPrivacy.UNLISTED - }) + let checkAttributes: any + let unlistedCheckAttributes: any before(async function () { this.timeout(30000) servers = await flushAndRunMultipleServers(3) + checkAttributes = { + name: 'my super name for server 1', + category: 5, + licence: 4, + language: 'ja', + nsfw: true, + description: 'my super description for server 1', + support: 'my super support text for server 1', + account: { + name: 'root', + host: 'localhost:' + servers[0].port + }, + isLocal: false, + duration: 10, + tags: [ 'tag1p1', 'tag2p1' ], + privacy: VideoPrivacy.PUBLIC, + commentsEnabled: true, + downloadEnabled: true, + channel: { + name: 'root_channel', + displayName: 'Main root channel', + description: '', + isLocal: false + }, + fixture: 'video_short1.webm', + files: [ + { + resolution: 720, + size: 572456 + } + ] + } + unlistedCheckAttributes = immutableAssign(checkAttributes, { + privacy: VideoPrivacy.UNLISTED + }) + // Get the access tokens await setAccessTokensToServers(servers) }) diff --git a/server/tests/api/server/logs.ts b/server/tests/api/server/logs.ts index 3644fa0d3..68f442199 100644 --- a/server/tests/api/server/logs.ts +++ b/server/tests/api/server/logs.ts @@ -45,7 +45,7 @@ describe('Test logs', function () { }) it('Should get logs with an end date', async function () { - this.timeout(10000) + this.timeout(20000) await uploadVideo(server.url, server.accessToken, { name: 'video 3' }) await waitJobs([ server ]) diff --git a/server/tests/api/travis-1.sh b/server/tests/api/travis-1.sh index 0673bb2bf..f7332795c 100644 --- a/server/tests/api/travis-1.sh +++ b/server/tests/api/travis-1.sh @@ -2,9 +2,9 @@ set -eu +checkParamFiles=$(find server/tests/api/check-params -type f | grep -v index.ts | xargs echo) notificationsFiles=$(find server/tests/api/notifications -type f | grep -v index.ts | xargs echo) searchFiles=$(find server/tests/api/search -type f | grep -v index.ts | xargs echo) -checkParamFiles=$(find server/tests/api/check-params -type f | grep -v index.ts | xargs echo) -MOCHA_PARALLEL=true mocha-parallel-tests --max-parallel 4 --timeout 5000 --exit --require ts-node/register --bail \ +MOCHA_PARALLEL=true mocha-parallel-tests --max-parallel 3 --timeout 5000 --exit --require ts-node/register --bail \ $notificationsFiles $searchFiles $checkParamFiles diff --git a/server/tests/api/travis-2.sh b/server/tests/api/travis-2.sh new file mode 100644 index 000000000..abeb48144 --- /dev/null +++ b/server/tests/api/travis-2.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env sh + +set -eu + +serverFiles=$(find server/tests/api/server -type f | grep -v index.ts | xargs echo) +usersFiles=$(find server/tests/api/users -type f | grep -v index.ts | xargs echo) + +MOCHA_PARALLEL=true mocha-parallel-tests --max-parallel 3 --timeout 5000 --exit --require ts-node/register --bail \ + $serverFiles $usersFiles diff --git a/server/tests/api/travis-3.sh b/server/tests/api/travis-3.sh new file mode 100644 index 000000000..81e6c2e4b --- /dev/null +++ b/server/tests/api/travis-3.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env sh + +set -eu + +videosFiles=$(find server/tests/api/videos -type f | grep -v index.ts | xargs echo) + +MOCHA_PARALLEL=true mocha-parallel-tests --max-parallel 3 --timeout 5000 --exit --require ts-node/register --bail \ + $videosFiles diff --git a/server/tests/api/travis-4.sh b/server/tests/api/travis-4.sh new file mode 100644 index 000000000..24bf5b71c --- /dev/null +++ b/server/tests/api/travis-4.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env sh + +set -eu + +redundancyFiles=$(find server/tests/api/redundancy -type f | grep -v index.ts | xargs echo) +activitypubFiles=$(find server/tests/api/activitypub -type f | grep -v index.ts | xargs echo) + +MOCHA_PARALLEL=true mocha-parallel-tests --max-parallel 3 --timeout 5000 --exit --require ts-node/register --bail \ + $redundancyFiles $activitypubFiles diff --git a/server/tests/api/users/user-subscriptions.ts b/server/tests/api/users/user-subscriptions.ts index 48811e647..c8a89d6be 100644 --- a/server/tests/api/users/user-subscriptions.ts +++ b/server/tests/api/users/user-subscriptions.ts @@ -71,8 +71,8 @@ describe('Test users subscriptions', function () { it('User of server 1 should follow user of server 3 and root of server 1', async function () { this.timeout(60000) - await addUserSubscription(servers[0].url, users[0].accessToken, 'user3_channel@localhost:9003') - await addUserSubscription(servers[0].url, users[0].accessToken, 'root_channel@localhost:9001') + await addUserSubscription(servers[0].url, users[0].accessToken, 'user3_channel@localhost:' + servers[2].port) + await addUserSubscription(servers[0].url, users[0].accessToken, 'root_channel@localhost:' + servers[0].port) await waitJobs(servers) @@ -116,22 +116,22 @@ describe('Test users subscriptions', function () { it('Should get subscription', async function () { { - const res = await getUserSubscription(servers[ 0 ].url, users[ 0 ].accessToken, 'user3_channel@localhost:9003') + const res = await getUserSubscription(servers[ 0 ].url, users[ 0 ].accessToken, 'user3_channel@localhost:' + servers[2].port) const videoChannel: VideoChannel = res.body expect(videoChannel.name).to.equal('user3_channel') - expect(videoChannel.host).to.equal('localhost:9003') + expect(videoChannel.host).to.equal('localhost:' + servers[2].port) expect(videoChannel.displayName).to.equal('Main user3 channel') expect(videoChannel.followingCount).to.equal(0) expect(videoChannel.followersCount).to.equal(1) } { - const res = await getUserSubscription(servers[ 0 ].url, users[ 0 ].accessToken, 'root_channel@localhost:9001') + const res = await getUserSubscription(servers[ 0 ].url, users[ 0 ].accessToken, 'root_channel@localhost:' + servers[0].port) const videoChannel: VideoChannel = res.body expect(videoChannel.name).to.equal('root_channel') - expect(videoChannel.host).to.equal('localhost:9001') + expect(videoChannel.host).to.equal('localhost:' + servers[0].port) expect(videoChannel.displayName).to.equal('Main root channel') expect(videoChannel.followingCount).to.equal(0) expect(videoChannel.followersCount).to.equal(1) @@ -140,19 +140,19 @@ describe('Test users subscriptions', function () { it('Should return the existing subscriptions', async function () { const uris = [ - 'user3_channel@localhost:9003', - 'root2_channel@localhost:9001', - 'root_channel@localhost:9001', - 'user3_channel@localhost:9001' + 'user3_channel@localhost:' + servers[2].port, + 'root2_channel@localhost:' + servers[0].port, + 'root_channel@localhost:' + servers[0].port, + 'user3_channel@localhost:' + servers[0].port ] const res = await areSubscriptionsExist(servers[ 0 ].url, users[ 0 ].accessToken, uris) const body = res.body - expect(body['user3_channel@localhost:9003']).to.be.true - expect(body['root2_channel@localhost:9001']).to.be.false - expect(body['root_channel@localhost:9001']).to.be.true - expect(body['user3_channel@localhost:9001']).to.be.false + expect(body['user3_channel@localhost:' + servers[2].port]).to.be.true + expect(body['root2_channel@localhost:' + servers[0].port]).to.be.false + expect(body['root_channel@localhost:' + servers[0].port]).to.be.true + expect(body['user3_channel@localhost:' + servers[0].port]).to.be.false }) it('Should list subscription videos', async function () { @@ -291,7 +291,7 @@ describe('Test users subscriptions', function () { it('Should remove user of server 3 subscription', async function () { this.timeout(30000) - await removeUserSubscription(servers[0].url, users[0].accessToken, 'user3_channel@localhost:9003') + await removeUserSubscription(servers[0].url, users[0].accessToken, 'user3_channel@localhost:' + servers[2].port) await waitJobs(servers) }) @@ -312,7 +312,7 @@ describe('Test users subscriptions', function () { it('Should remove the root subscription and not display the videos anymore', async function () { this.timeout(30000) - await removeUserSubscription(servers[0].url, users[0].accessToken, 'root_channel@localhost:9001') + await removeUserSubscription(servers[0].url, users[0].accessToken, 'root_channel@localhost:' + servers[0].port) await waitJobs(servers) @@ -340,7 +340,7 @@ describe('Test users subscriptions', function () { it('Should follow user of server 3 again', async function () { this.timeout(60000) - await addUserSubscription(servers[0].url, users[0].accessToken, 'user3_channel@localhost:9003') + await addUserSubscription(servers[0].url, users[0].accessToken, 'user3_channel@localhost:' + servers[2].port) await waitJobs(servers) diff --git a/server/tests/api/users/users-multiple-servers.ts b/server/tests/api/users/users-multiple-servers.ts index 9a971adb3..988fdad3f 100644 --- a/server/tests/api/users/users-multiple-servers.ts +++ b/server/tests/api/users/users-multiple-servers.ts @@ -151,13 +151,13 @@ describe('Test users with multiple servers', function () { for (const server of servers) { const resAccounts = await getAccountsList(server.url, '-createdAt') - const rootServer1List = resAccounts.body.data.find(a => a.name === 'root' && a.host === 'localhost:9001') as Account + const rootServer1List = resAccounts.body.data.find(a => a.name === 'root' && a.host === 'localhost:' + servers[0].port) as Account expect(rootServer1List).not.to.be.undefined const resAccount = await getAccount(server.url, rootServer1List.name + '@' + rootServer1List.host) const rootServer1Get = resAccount.body as Account expect(rootServer1Get.name).to.equal('root') - expect(rootServer1Get.host).to.equal('localhost:9001') + expect(rootServer1Get.host).to.equal('localhost:' + servers[0].port) expect(rootServer1Get.displayName).to.equal('my super display name') expect(rootServer1Get.description).to.equal('my super description updated') @@ -188,12 +188,12 @@ describe('Test users with multiple servers', function () { for (const server of servers) { const resAccounts = await getAccountsList(server.url, '-createdAt') - const accountDeleted = resAccounts.body.data.find(a => a.name === 'user1' && a.host === 'localhost:9001') as Account + const accountDeleted = resAccounts.body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port) as Account expect(accountDeleted).not.to.be.undefined const resVideoChannels = await getVideoChannelsList(server.url, 0, 10) const videoChannelDeleted = resVideoChannels.body.data.find(a => { - return a.displayName === 'Main user1 channel' && a.host === 'localhost:9001' + return a.displayName === 'Main user1 channel' && a.host === 'localhost:' + servers[0].port }) as VideoChannel expect(videoChannelDeleted).not.to.be.undefined } @@ -205,12 +205,12 @@ describe('Test users with multiple servers', function () { for (const server of servers) { const resAccounts = await getAccountsList(server.url, '-createdAt') - const accountDeleted = resAccounts.body.data.find(a => a.name === 'user1' && a.host === 'localhost:9001') as Account + const accountDeleted = resAccounts.body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port) as Account expect(accountDeleted).to.be.undefined const resVideoChannels = await getVideoChannelsList(server.url, 0, 10) const videoChannelDeleted = resVideoChannels.body.data.find(a => { - return a.name === 'Main user1 channel' && a.host === 'localhost:9001' + return a.name === 'Main user1 channel' && a.host === 'localhost:' + servers[0].port }) as VideoChannel expect(videoChannelDeleted).to.be.undefined } @@ -218,14 +218,14 @@ describe('Test users with multiple servers', function () { it('Should not have actor files', async () => { for (const server of servers) { - await checkActorFilesWereRemoved(userAccountUUID, server.serverNumber) - await checkActorFilesWereRemoved(userVideoChannelUUID, server.serverNumber) + await checkActorFilesWereRemoved(userAccountUUID, server.internalServerNumber) + await checkActorFilesWereRemoved(userVideoChannelUUID, server.internalServerNumber) } }) it('Should not have video files', async () => { for (const server of servers) { - await checkVideoFilesWereRemoved(videoUUID, server.serverNumber) + await checkVideoFilesWereRemoved(videoUUID, server.internalServerNumber) } }) diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index c8e32f3f5..c1a24b838 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts @@ -316,7 +316,7 @@ describe('Test users', function () { const rootUser = users[ 1 ] expect(rootUser.username).to.equal('root') - expect(rootUser.email).to.equal('admin1@example.com') + expect(rootUser.email).to.equal('admin' + server.internalServerNumber + '@example.com') expect(user.nsfwPolicy).to.equal('display') userId = user.id @@ -334,7 +334,7 @@ describe('Test users', function () { const user = users[ 0 ] expect(user.username).to.equal('root') - expect(user.email).to.equal('admin1@example.com') + expect(user.email).to.equal('admin' + server.internalServerNumber + '@example.com') expect(user.roleLabel).to.equal('Administrator') expect(user.nsfwPolicy).to.equal('display') }) @@ -379,7 +379,7 @@ describe('Test users', function () { expect(users.length).to.equal(2) expect(users[ 0 ].username).to.equal('root') - expect(users[ 0 ].email).to.equal('admin1@example.com') + expect(users[ 0 ].email).to.equal('admin' + server.internalServerNumber + '@example.com') expect(users[ 0 ].nsfwPolicy).to.equal('display') expect(users[ 1 ].username).to.equal('user_1') diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts index 89904759a..09b461200 100644 --- a/server/tests/api/videos/multiple-servers.ts +++ b/server/tests/api/videos/multiple-servers.ts @@ -109,7 +109,7 @@ describe('Test multiple servers', function () { // All servers should have this video let publishedAt: string = null for (const server of servers) { - const isLocal = server.url === 'http://localhost:' + servers[0].port + const isLocal = server.port === servers[0].port const checkAttributes = { name: 'my super name for server 1', category: 5, diff --git a/server/tests/api/videos/single-server.ts b/server/tests/api/videos/single-server.ts index b0412f4df..d8f394ac7 100644 --- a/server/tests/api/videos/single-server.ts +++ b/server/tests/api/videos/single-server.ts @@ -37,7 +37,7 @@ describe('Test a single server', function () { let videoUUID = '' let videosListBase: any[] = null - const getCheckAttributes = { + const getCheckAttributes = () => ({ name: 'my super name', category: 2, licence: 6, @@ -68,9 +68,9 @@ describe('Test a single server', function () { size: 218910 } ] - } + }) - const updateCheckAttributes = { + const updateCheckAttributes = () => ({ name: 'my super video updated', category: 4, licence: 2, @@ -101,7 +101,7 @@ describe('Test a single server', function () { size: 292677 } ] - } + }) before(async function () { this.timeout(30000) @@ -182,7 +182,7 @@ describe('Test a single server', function () { expect(res.body.data.length).to.equal(1) const video = res.body.data[0] - await completeVideoCheck(server.url, video, getCheckAttributes) + await completeVideoCheck(server.url, video, getCheckAttributes()) }) it('Should get the video by UUID', async function () { @@ -191,7 +191,7 @@ describe('Test a single server', function () { const res = await getVideo(server.url, videoUUID) const video = res.body - await completeVideoCheck(server.url, video, getCheckAttributes) + await completeVideoCheck(server.url, video, getCheckAttributes()) }) it('Should have the views updated', async function () { @@ -376,7 +376,7 @@ describe('Test a single server', function () { const res = await getVideo(server.url, videoId) const video = res.body - await completeVideoCheck(server.url, video, updateCheckAttributes) + await completeVideoCheck(server.url, video, updateCheckAttributes()) }) it('Should update only the tags of a video', async function () { @@ -388,7 +388,7 @@ describe('Test a single server', function () { const res = await getVideo(server.url, videoId) const video = res.body - await completeVideoCheck(server.url, video, Object.assign(updateCheckAttributes, attributes)) + await completeVideoCheck(server.url, video, Object.assign(updateCheckAttributes(), attributes)) }) it('Should update only the description of a video', async function () { @@ -400,7 +400,8 @@ describe('Test a single server', function () { const res = await getVideo(server.url, videoId) const video = res.body - await completeVideoCheck(server.url, video, Object.assign(updateCheckAttributes, attributes)) + const expectedAttributes = Object.assign(updateCheckAttributes(), { tags: [ 'supertag', 'tag1', 'tag2' ] }, attributes) + await completeVideoCheck(server.url, video, expectedAttributes) }) it('Should like a video', async function () { diff --git a/server/tests/api/videos/video-change-ownership.ts b/server/tests/api/videos/video-change-ownership.ts index 1c0327d40..3a3add71b 100644 --- a/server/tests/api/videos/video-change-ownership.ts +++ b/server/tests/api/videos/video-change-ownership.ts @@ -4,7 +4,8 @@ import * as chai from 'chai' import 'mocha' import { acceptChangeOwnership, - changeVideoOwnership, cleanupTests, + changeVideoOwnership, + cleanupTests, createUser, doubleFollow, flushAndRunMultipleServers, @@ -13,7 +14,6 @@ import { getVideo, getVideoChangeOwnershipList, getVideosList, - killallServers, refuseChangeOwnership, ServerInfo, setAccessTokensToServers, @@ -203,8 +203,8 @@ describe('Test video change ownership - nominal', function () { } }) - after(function () { - killallServers(servers) + after(async function () { + await cleanupTests(servers) }) }) diff --git a/server/tests/api/videos/video-channels.ts b/server/tests/api/videos/video-channels.ts index f09148404..41fe3be5c 100644 --- a/server/tests/api/videos/video-channels.ts +++ b/server/tests/api/videos/video-channels.ts @@ -41,7 +41,7 @@ describe('Test video channels', function () { let videoUUID: string before(async function () { - this.timeout(30000) + this.timeout(60000) servers = await flushAndRunMultipleServers(2) @@ -213,7 +213,7 @@ describe('Test video channels', function () { this.timeout(10000) for (const server of servers) { - const channelURI = 'second_video_channel@localhost:' + server.port + const channelURI = 'second_video_channel@localhost:' + servers[0].port const res1 = await getVideoChannelVideos(server.url, server.accessToken, channelURI, 0, 5) expect(res1.body.total).to.equal(1) expect(res1.body.data).to.be.an('array') @@ -234,11 +234,11 @@ describe('Test video channels', function () { this.timeout(10000) for (const server of servers) { - const secondChannelURI = 'second_video_channel@localhost:' + server.port + const secondChannelURI = 'second_video_channel@localhost:' + servers[0].port const res1 = await getVideoChannelVideos(server.url, server.accessToken, secondChannelURI, 0, 5) expect(res1.body.total).to.equal(0) - const channelURI = 'root_channel@localhost:' + server.port + const channelURI = 'root_channel@localhost:' + servers[0].port const res2 = await getVideoChannelVideos(server.url, server.accessToken, channelURI, 0, 5) expect(res2.body.total).to.equal(1) diff --git a/server/tests/api/videos/video-hls.ts b/server/tests/api/videos/video-hls.ts index 4565d0ebe..504c50dee 100644 --- a/server/tests/api/videos/video-hls.ts +++ b/server/tests/api/videos/video-hls.ts @@ -50,7 +50,7 @@ async function checkHlsPlaylist (servers: ServerInfo[], videoUUID: string) { { for (const resolution of resolutions) { - const res2 = await getPlaylist(`http://localhost:${server.port}/static/streaming-playlists/hls/${videoUUID}/${resolution}.m3u8`) + const res2 = await getPlaylist(`http://localhost:${servers[0].port}/static/streaming-playlists/hls/${videoUUID}/${resolution}.m3u8`) const subPlaylist = res2.text expect(subPlaylist).to.contain(`${videoUUID}-${resolution}-fragmented.mp4`) @@ -58,7 +58,7 @@ async function checkHlsPlaylist (servers: ServerInfo[], videoUUID: string) { } { - const baseUrl = 'http://localhost:' + server.port + '/static/streaming-playlists/hls' + const baseUrl = 'http://localhost:' + servers[0].port + '/static/streaming-playlists/hls' for (const resolution of resolutions) { await checkSegmentHash(baseUrl, baseUrl, videoUUID, resolution, hlsPlaylist) diff --git a/server/tests/api/videos/video-playlists.ts b/server/tests/api/videos/video-playlists.ts index e4d817ff8..83a2f3d4d 100644 --- a/server/tests/api/videos/video-playlists.ts +++ b/server/tests/api/videos/video-playlists.ts @@ -358,7 +358,7 @@ describe('Test video playlists', function () { for (const server of servers) { const results = [ - await getAccountPlaylistsList(server.url, 'root@localhost:9002', 0, 5, '-createdAt'), + await getAccountPlaylistsList(server.url, 'root@localhost:' + servers[1].port, 0, 5, '-createdAt'), await getVideoPlaylistsList(server.url, 0, 2, '-createdAt') ] @@ -757,7 +757,7 @@ describe('Test video playlists', function () { this.timeout(30000) for (const server of servers) { - await checkPlaylistFilesWereRemoved(playlistServer1UUID, server.serverNumber) + await checkPlaylistFilesWereRemoved(playlistServer1UUID, server.internalServerNumber) } }) diff --git a/server/tests/api/videos/videos-views-cleaner.ts b/server/tests/api/videos/videos-views-cleaner.ts index c21d46d56..fbddd40f4 100644 --- a/server/tests/api/videos/videos-views-cleaner.ts +++ b/server/tests/api/videos/videos-views-cleaner.ts @@ -10,7 +10,7 @@ import { flushAndRunServer, ServerInfo, setAccessTokensToServers, - uploadVideo, uploadVideoAndGetId, viewVideo, wait, countVideoViewsOf, doubleFollow, waitJobs, cleanupTests + uploadVideo, uploadVideoAndGetId, viewVideo, wait, countVideoViewsOf, doubleFollow, waitJobs, cleanupTests, closeAllSequelize } from '../../../../shared/extra-utils' import { getVideosOverview } from '../../../../shared/extra-utils/overviews/overviews' import { VideosOverview } from '../../../../shared/models/overviews' @@ -58,14 +58,14 @@ describe('Test video views cleaner', function () { { for (const server of servers) { - const total = await countVideoViewsOf(server.serverNumber, videoIdServer1) + const total = await countVideoViewsOf(server.internalServerNumber, videoIdServer1) expect(total).to.equal(2) } } { for (const server of servers) { - const total = await countVideoViewsOf(server.serverNumber, videoIdServer2) + const total = await countVideoViewsOf(server.internalServerNumber, videoIdServer2) expect(total).to.equal(2) } } @@ -74,8 +74,6 @@ describe('Test video views cleaner', function () { it('Should clean old video views', async function () { this.timeout(50000) - this.timeout(50000) - killallServers([ servers[0] ]) await reRunServer(servers[0], { views: { videos: { remote: { max_age: '5 seconds' } } } }) @@ -86,21 +84,23 @@ describe('Test video views cleaner', function () { { for (const server of servers) { - const total = await countVideoViewsOf(server.serverNumber, videoIdServer1) + const total = await countVideoViewsOf(server.internalServerNumber, videoIdServer1) expect(total).to.equal(2) } } { - const totalServer1 = await countVideoViewsOf(servers[0].serverNumber, videoIdServer2) + const totalServer1 = await countVideoViewsOf(servers[0].internalServerNumber, videoIdServer2) expect(totalServer1).to.equal(0) - const totalServer2 = await countVideoViewsOf(servers[1].serverNumber, videoIdServer2) + const totalServer2 = await countVideoViewsOf(servers[1].internalServerNumber, videoIdServer2) expect(totalServer2).to.equal(2) } }) after(async function () { + await closeAllSequelize(servers) + await cleanupTests(servers) }) }) 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) From f88392cf680c30943f91d79d96e65277dfb0c7f0 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 15 May 2019 15:37:31 +0200 Subject: [PATCH 4/5] Decrease max parallel tests for travis --- scripts/travis.sh | 8 ++++---- server/tests/api/travis-1.sh | 2 +- server/tests/api/travis-2.sh | 2 +- server/tests/api/travis-3.sh | 2 +- server/tests/api/travis-4.sh | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/scripts/travis.sh b/scripts/travis.sh index 772d3906a..c38bd2cab 100755 --- a/scripts/travis.sh +++ b/scripts/travis.sh @@ -20,16 +20,16 @@ elif [ "$1" = "cli" ]; then mocha --timeout 5000 --exit --require ts-node/register --bail server/tests/cli/index.ts elif [ "$1" = "api-1" ]; then npm run build:server - sh ./server/tests/api/travis-1.sh + sh ./server/tests/api/travis-1.sh 2 elif [ "$1" = "api-2" ]; then npm run build:server - sh ./server/tests/api/travis-2.sh + sh ./server/tests/api/travis-2.sh 2 elif [ "$1" = "api-3" ]; then npm run build:server - sh ./server/tests/api/travis-3.sh + sh ./server/tests/api/travis-3.sh 2 elif [ "$1" = "api-4" ]; then npm run build:server - sh ./server/tests/api/travis-4.sh + sh ./server/tests/api/travis-4.sh 2 elif [ "$1" = "lint" ]; then npm run tslint -- --project ./tsconfig.json -c ./tslint.json server.ts "server/**/*.ts" "shared/**/*.ts" diff --git a/server/tests/api/travis-1.sh b/server/tests/api/travis-1.sh index f7332795c..c9918d58e 100644 --- a/server/tests/api/travis-1.sh +++ b/server/tests/api/travis-1.sh @@ -6,5 +6,5 @@ checkParamFiles=$(find server/tests/api/check-params -type f | grep -v index.ts notificationsFiles=$(find server/tests/api/notifications -type f | grep -v index.ts | xargs echo) searchFiles=$(find server/tests/api/search -type f | grep -v index.ts | xargs echo) -MOCHA_PARALLEL=true mocha-parallel-tests --max-parallel 3 --timeout 5000 --exit --require ts-node/register --bail \ +MOCHA_PARALLEL=true mocha-parallel-tests --max-parallel $1 --timeout 5000 --exit --require ts-node/register --bail \ $notificationsFiles $searchFiles $checkParamFiles diff --git a/server/tests/api/travis-2.sh b/server/tests/api/travis-2.sh index abeb48144..82c1864b4 100644 --- a/server/tests/api/travis-2.sh +++ b/server/tests/api/travis-2.sh @@ -5,5 +5,5 @@ set -eu serverFiles=$(find server/tests/api/server -type f | grep -v index.ts | xargs echo) usersFiles=$(find server/tests/api/users -type f | grep -v index.ts | xargs echo) -MOCHA_PARALLEL=true mocha-parallel-tests --max-parallel 3 --timeout 5000 --exit --require ts-node/register --bail \ +MOCHA_PARALLEL=true mocha-parallel-tests --max-parallel $1 --timeout 5000 --exit --require ts-node/register --bail \ $serverFiles $usersFiles diff --git a/server/tests/api/travis-3.sh b/server/tests/api/travis-3.sh index 81e6c2e4b..c0e558d34 100644 --- a/server/tests/api/travis-3.sh +++ b/server/tests/api/travis-3.sh @@ -4,5 +4,5 @@ set -eu videosFiles=$(find server/tests/api/videos -type f | grep -v index.ts | xargs echo) -MOCHA_PARALLEL=true mocha-parallel-tests --max-parallel 3 --timeout 5000 --exit --require ts-node/register --bail \ +MOCHA_PARALLEL=true mocha-parallel-tests --max-parallel $1 --timeout 5000 --exit --require ts-node/register --bail \ $videosFiles diff --git a/server/tests/api/travis-4.sh b/server/tests/api/travis-4.sh index 24bf5b71c..875986182 100644 --- a/server/tests/api/travis-4.sh +++ b/server/tests/api/travis-4.sh @@ -5,5 +5,5 @@ set -eu redundancyFiles=$(find server/tests/api/redundancy -type f | grep -v index.ts | xargs echo) activitypubFiles=$(find server/tests/api/activitypub -type f | grep -v index.ts | xargs echo) -MOCHA_PARALLEL=true mocha-parallel-tests --max-parallel 3 --timeout 5000 --exit --require ts-node/register --bail \ +MOCHA_PARALLEL=true mocha-parallel-tests --max-parallel $1 --timeout 5000 --exit --require ts-node/register --bail \ $redundancyFiles $activitypubFiles From d183ee9bda2588f07032ca4a2fce58651e684abf Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 15 May 2019 17:17:14 +0200 Subject: [PATCH 5/5] Don't use parallel tests with test suite 1 and 3 --- server/tests/api/travis-1.sh | 2 +- server/tests/api/travis-3.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/server/tests/api/travis-1.sh b/server/tests/api/travis-1.sh index c9918d58e..db4021b25 100644 --- a/server/tests/api/travis-1.sh +++ b/server/tests/api/travis-1.sh @@ -6,5 +6,5 @@ checkParamFiles=$(find server/tests/api/check-params -type f | grep -v index.ts notificationsFiles=$(find server/tests/api/notifications -type f | grep -v index.ts | xargs echo) searchFiles=$(find server/tests/api/search -type f | grep -v index.ts | xargs echo) -MOCHA_PARALLEL=true mocha-parallel-tests --max-parallel $1 --timeout 5000 --exit --require ts-node/register --bail \ +MOCHA_PARALLEL=true mocha --timeout 5000 --exit --require ts-node/register --bail \ $notificationsFiles $searchFiles $checkParamFiles diff --git a/server/tests/api/travis-3.sh b/server/tests/api/travis-3.sh index c0e558d34..82457222c 100644 --- a/server/tests/api/travis-3.sh +++ b/server/tests/api/travis-3.sh @@ -4,5 +4,5 @@ set -eu videosFiles=$(find server/tests/api/videos -type f | grep -v index.ts | xargs echo) -MOCHA_PARALLEL=true mocha-parallel-tests --max-parallel $1 --timeout 5000 --exit --require ts-node/register --bail \ +MOCHA_PARALLEL=true mocha --timeout 5000 --exit --require ts-node/register --bail \ $videosFiles