diff --git a/.travis.yml b/.travis.yml index dcf7247b2d50bbf7e6b426e5ef1691ad5a78df8d..8d61fc10f96bfea07dde02ea7d4a842003f5e1ad 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,7 @@ addons: - ubuntu-toolchain-r-test packages: - g++-4.9 - postgresql: "9.4" + postgresql: "9.6" cache: directories: diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts index 3d80c629e293fe98cb5a0beb3b89637c004cee48..2a2ec606a5f8ef137b39fdc6dfa1deb1dcf5ae6c 100644 --- a/server/tests/api/check-params/config.ts +++ b/server/tests/api/check-params/config.ts @@ -6,7 +6,7 @@ import { CustomConfig } from '../../../../shared/models/server/custom-config.mod import { createUser, flushTests, killallServers, makeDeleteRequest, makeGetRequest, makePutBodyRequest, flushAndRunServer, ServerInfo, - setAccessTokensToServers, userLogin, immutableAssign + setAccessTokensToServers, userLogin, immutableAssign, cleanupTests } from '../../../../shared/extra-utils' describe('Test config API validators', function () { @@ -181,7 +181,7 @@ describe('Test config API validators', function () { }) it('Should fail if email disabled and signup requires email verification', async function () { - // opposite scenario - succcess when enable enabled - covered via tests/api/users/user-verification.ts + // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts const newUpdateParams = immutableAssign(updateParams, { signup: { enabled: true, @@ -229,7 +229,7 @@ describe('Test config API validators', function () { }) }) - after(function () { - killallServers([ server ]) + after(async function () { + await cleanupTests([ server ]) }) }) diff --git a/server/tests/api/check-params/contact-form.ts b/server/tests/api/check-params/contact-form.ts index 6c7781f13c0e2727e8475a24f1cdcf289f585447..55004020fc256f445c94d6a26f13d3e096c2e84b 100644 --- a/server/tests/api/check-params/contact-form.ts +++ b/server/tests/api/check-params/contact-form.ts @@ -9,7 +9,7 @@ import { reRunServer, flushAndRunServer, ServerInfo, - setAccessTokensToServers + setAccessTokensToServers, cleanupTests } from '../../../../shared/extra-utils' import { checkBadCountPagination, @@ -28,13 +28,14 @@ describe('Test contact form API validators', function () { fromEmail: 'toto@example.com', body: 'Hello, how are you?' } + let emailPort: number // --------------------------------------------------------------- before(async function () { this.timeout(60000) - await MockSmtpServer.Instance.collectEmails(emails) + emailPort = await MockSmtpServer.Instance.collectEmails(emails) // Email is disabled server = await flushAndRunServer(1) @@ -50,7 +51,7 @@ describe('Test contact form API validators', function () { killallServers([ server ]) // Contact form is disabled - await reRunServer(server, { smtp: { hostname: 'localhost' }, contact_form: { enabled: false } }) + await reRunServer(server, { smtp: { hostname: 'localhost', port: emailPort }, contact_form: { enabled: false } }) await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 409 })) }) @@ -60,7 +61,7 @@ describe('Test contact form API validators', function () { killallServers([ server ]) // Email & contact form enabled - await reRunServer(server, { smtp: { hostname: 'localhost' } }) + await reRunServer(server, { smtp: { hostname: 'localhost', port: emailPort } }) await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromEmail: 'badEmail' })) await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromEmail: 'badEmail@' })) @@ -83,8 +84,9 @@ describe('Test contact form API validators', function () { await sendContactForm(immutableAssign(defaultBody, { url: server.url })) }) - after(function () { + after(async function () { MockSmtpServer.Instance.kill() - killallServers([ server ]) + + // await cleanupTests([ server ]) }) }) diff --git a/server/tests/api/check-params/debug.ts b/server/tests/api/check-params/debug.ts index dd00ed9e1a6ced30ca85fee77d289768752ea1c8..8dad267233f01fbc26c10d8df208ec5a2205f94d 100644 --- a/server/tests/api/check-params/debug.ts +++ b/server/tests/api/check-params/debug.ts @@ -9,7 +9,7 @@ import { flushAndRunServer, ServerInfo, setAccessTokensToServers, - userLogin + userLogin, cleanupTests } from '../../../../shared/extra-utils' import { makeGetRequest } from '../../../../shared/extra-utils/requests/requests' @@ -65,7 +65,7 @@ describe('Test debug API validators', function () { }) }) - after(function () { - killallServers([ server ]) + after(async function () { + await cleanupTests([ server ]) }) }) diff --git a/server/tests/api/check-params/follows.ts b/server/tests/api/check-params/follows.ts index 02f47c2bb1909da27f73b8a299eec1ea6a1f4e4c..2eb54cb0a7ee1f90f29155d3ee923f835ffd3873 100644 --- a/server/tests/api/check-params/follows.ts +++ b/server/tests/api/check-params/follows.ts @@ -3,7 +3,13 @@ import 'mocha' import { - createUser, flushTests, killallServers, makeDeleteRequest, makePostBodyRequest, flushAndRunServer, ServerInfo, setAccessTokensToServers, + cleanupTests, + createUser, + flushAndRunServer, + makeDeleteRequest, + makePostBodyRequest, + ServerInfo, + setAccessTokensToServers, userLogin } from '../../../../shared/extra-utils' import { @@ -295,7 +301,7 @@ describe('Test server follows API validators', function () { }) }) - after(function () { - killallServers([ server ]) + after(async function () { + await cleanupTests([ server ]) }) }) diff --git a/server/tests/api/check-params/jobs.ts b/server/tests/api/check-params/jobs.ts index ec2be0b9f8f5e01aada8a8dd0d3e3d8dee05fdcc..c7013951424d69a43012600acdfb63e9c41a7740 100644 --- a/server/tests/api/check-params/jobs.ts +++ b/server/tests/api/check-params/jobs.ts @@ -9,7 +9,8 @@ import { flushAndRunServer, ServerInfo, setAccessTokensToServers, - userLogin + userLogin, + cleanupTests } from '../../../../shared/extra-utils' import { checkBadCountPagination, @@ -80,7 +81,7 @@ describe('Test jobs API validators', function () { }) }) - after(function () { - killallServers([ server ]) + after(async function () { + await cleanupTests([ server ]) }) }) diff --git a/server/tests/api/check-params/logs.ts b/server/tests/api/check-params/logs.ts index 46cb2392d9fbdc389867f6e0e8586f6ef809a511..f9d96bcc0785089cc428ec7979c1f4aa5804ee46 100644 --- a/server/tests/api/check-params/logs.ts +++ b/server/tests/api/check-params/logs.ts @@ -9,7 +9,8 @@ import { flushAndRunServer, ServerInfo, setAccessTokensToServers, - userLogin + userLogin, + cleanupTests } from '../../../../shared/extra-utils' import { makeGetRequest } from '../../../../shared/extra-utils/requests/requests' @@ -104,7 +105,7 @@ describe('Test logs API validators', function () { }) }) - after(function () { - killallServers([ server ]) + after(async function () { + await cleanupTests([ server ]) }) }) diff --git a/server/tests/api/check-params/redundancy.ts b/server/tests/api/check-params/redundancy.ts index 8f930fbbc436d22ed535373e73651bc02d1686fb..6471da8404c9016dc4aaba92314b2c8dc57f40e0 100644 --- a/server/tests/api/check-params/redundancy.ts +++ b/server/tests/api/check-params/redundancy.ts @@ -3,6 +3,7 @@ import 'mocha' import { + cleanupTests, createUser, doubleFollow, flushAndRunMultipleServers, @@ -43,7 +44,7 @@ describe('Test server redundancy API validators', function () { it('Should fail with an invalid token', async function () { await makePutBodyRequest({ url: servers[0].url, - path: path + '/localhost:9002', + path: path + '/localhost:' + servers[1].port, fields: { redundancyAllowed: true }, token: 'fake_token', statusCodeExpected: 401 @@ -53,7 +54,7 @@ describe('Test server redundancy API validators', function () { it('Should fail if the user is not an administrator', async function () { await makePutBodyRequest({ url: servers[0].url, - path: path + '/localhost:9002', + path: path + '/localhost:' + servers[1].port, fields: { redundancyAllowed: true }, token: userAccessToken, statusCodeExpected: 403 @@ -73,7 +74,7 @@ describe('Test server redundancy API validators', function () { it('Should fail without de redundancyAllowed param', async function () { await makePutBodyRequest({ url: servers[0].url, - path: path + '/localhost:9002', + path: path + '/localhost:' + servers[1].port, fields: { blabla: true }, token: servers[0].accessToken, statusCodeExpected: 400 @@ -83,7 +84,7 @@ describe('Test server redundancy API validators', function () { it('Should succeed with the correct parameters', async function () { await makePutBodyRequest({ url: servers[0].url, - path: path + '/localhost:9002', + path: path + '/localhost:' + servers[1].port, fields: { redundancyAllowed: true }, token: servers[0].accessToken, statusCodeExpected: 204 @@ -91,7 +92,7 @@ describe('Test server redundancy API validators', function () { }) }) - after(function () { - killallServers(servers) + after(async function () { + await cleanupTests(servers) }) }) diff --git a/server/tests/api/check-params/search.ts b/server/tests/api/check-params/search.ts index 816719779e4f6e4ef68ae42349e88097534d0937..8ad9d98bf62db01ee566e66e6a899dadaec31c03 100644 --- a/server/tests/api/check-params/search.ts +++ b/server/tests/api/check-params/search.ts @@ -2,7 +2,7 @@ import 'mocha' -import { flushTests, immutableAssign, killallServers, makeGetRequest, flushAndRunServer, ServerInfo } from '../../../../shared/extra-utils' +import { cleanupTests, flushAndRunServer, immutableAssign, makeGetRequest, ServerInfo } from '../../../../shared/extra-utils' import { checkBadCountPagination, checkBadSortPagination, @@ -144,7 +144,7 @@ describe('Test videos API validator', function () { }) }) - after(function () { - killallServers([ server ]) + after(async function () { + await cleanupTests([ server ]) }) }) diff --git a/server/tests/api/check-params/services.ts b/server/tests/api/check-params/services.ts index 33580ddb126eae7aafbabdaebe409541f4c334c7..d15753aedd61d2319cb00117fedfc3b5d16e803d 100644 --- a/server/tests/api/check-params/services.ts +++ b/server/tests/api/check-params/services.ts @@ -3,10 +3,9 @@ import 'mocha' import { - flushTests, - killallServers, - makeGetRequest, + cleanupTests, flushAndRunServer, + makeGetRequest, ServerInfo, setAccessTokensToServers, uploadVideo @@ -40,47 +39,47 @@ describe('Test services API validators', function () { }) it('Should fail with an invalid video id', async function () { - const embedUrl = 'http://localhost:9001/videos/watch/blabla' + const embedUrl = `http://localhost:${server.port}/videos/watch/blabla` await checkParamEmbed(server, embedUrl) }) it('Should fail with an unknown video', async function () { - const embedUrl = 'http://localhost:9001/videos/watch/88fc0165-d1f0-4a35-a51a-3b47f668689c' + const embedUrl = `http://localhost:${server.port}/videos/watch/88fc0165-d1f0-4a35-a51a-3b47f668689c` await checkParamEmbed(server, embedUrl, 404) }) it('Should fail with an invalid path', async function () { - const embedUrl = 'http://localhost:9001/videos/watchs/' + server.video.uuid + const embedUrl = `http://localhost:${server.port}/videos/watchs/${server.video.uuid}` await checkParamEmbed(server, embedUrl) }) it('Should fail with an invalid max height', async function () { - const embedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid + const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}` await checkParamEmbed(server, embedUrl, 400, { maxheight: 'hello' }) }) it('Should fail with an invalid max width', async function () { - const embedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid + const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}` await checkParamEmbed(server, embedUrl, 400, { maxwidth: 'hello' }) }) it('Should fail with an invalid format', async function () { - const embedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid + const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}` await checkParamEmbed(server, embedUrl, 400, { format: 'blabla' }) }) it('Should fail with a non supported format', async function () { - const embedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid + const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}` await checkParamEmbed(server, embedUrl, 501, { format: 'xml' }) }) it('Should succeed with the correct params', async function () { - const embedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid + const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}` const query = { format: 'json', maxheight: 400, @@ -91,8 +90,8 @@ describe('Test services API validators', function () { }) }) - after(function () { - killallServers([ server ]) + after(async function () { + await cleanupTests([ server ]) }) }) diff --git a/server/tests/api/check-params/user-notifications.ts b/server/tests/api/check-params/user-notifications.ts index 32619d7e16aa076aa6270e693dac188cd0e92e75..14ee20d451128076e84f8bc35cc6f588eb9e8d03 100644 --- a/server/tests/api/check-params/user-notifications.ts +++ b/server/tests/api/check-params/user-notifications.ts @@ -4,13 +4,12 @@ import 'mocha' import * as io from 'socket.io-client' import { - flushTests, + cleanupTests, + flushAndRunServer, immutableAssign, - killallServers, makeGetRequest, makePostBodyRequest, makePutBodyRequest, - flushAndRunServer, ServerInfo, setAccessTokensToServers, wait @@ -234,7 +233,7 @@ describe('Test user notifications API validators', function () { describe('When connecting to my notification socket', function () { it('Should fail with no token', function (next) { - const socket = io('http://localhost:9001/user-notifications', { reconnection: false }) + const socket = io(`http://localhost:${server.port}/user-notifications`, { reconnection: false }) socket.on('error', () => { socket.removeListener('error', this) @@ -249,7 +248,7 @@ describe('Test user notifications API validators', function () { }) it('Should fail with an invalid token', function (next) { - const socket = io('http://localhost:9001/user-notifications', { + const socket = io(`http://localhost:${server.port}/user-notifications`, { query: { accessToken: 'bad_access_token' }, reconnection: false }) @@ -267,7 +266,7 @@ describe('Test user notifications API validators', function () { }) it('Should success with the correct token', function (next) { - const socket = io('http://localhost:9001/user-notifications', { + const socket = io(`http://localhost:${server.port}/user-notifications`, { query: { accessToken: server.accessToken }, reconnection: false }) @@ -286,7 +285,7 @@ describe('Test user notifications API validators', function () { }) }) - after(function () { - killallServers([ server ]) + after(async function () { + await cleanupTests([ server ]) }) }) diff --git a/server/tests/api/check-params/user-subscriptions.ts b/server/tests/api/check-params/user-subscriptions.ts index 1fe67fa7c40f8bff98251603a5b28915f9bf0846..fa36c40780c7be91b9e0b663907107ab30a4d766 100644 --- a/server/tests/api/check-params/user-subscriptions.ts +++ b/server/tests/api/check-params/user-subscriptions.ts @@ -3,13 +3,12 @@ import 'mocha' import { + cleanupTests, createUser, - flushTests, - killallServers, + flushAndRunServer, makeDeleteRequest, makeGetRequest, makePostBodyRequest, - flushAndRunServer, ServerInfo, setAccessTokensToServers, userLogin @@ -113,7 +112,7 @@ describe('Test user subscriptions API validators', function () { await makePostBodyRequest({ url: server.url, path, - fields: { uri: 'user1_channel@localhost:9001' }, + fields: { uri: 'user1_channel@localhost:' + server.port }, statusCodeExpected: 401 }) }) @@ -151,7 +150,7 @@ describe('Test user subscriptions API validators', function () { url: server.url, path, token: server.accessToken, - fields: { uri: 'user1_channel@localhost:9001' }, + fields: { uri: 'user1_channel@localhost:' + server.port }, statusCodeExpected: 204 }) @@ -163,7 +162,7 @@ describe('Test user subscriptions API validators', function () { it('Should fail with a non authenticated user', async function () { await makeGetRequest({ url: server.url, - path: path + '/user1_channel@localhost:9001', + path: path + '/user1_channel@localhost:' + server.port, statusCodeExpected: 401 }) }) @@ -194,7 +193,7 @@ describe('Test user subscriptions API validators', function () { it('Should fail with an unknown subscription', async function () { await makeGetRequest({ url: server.url, - path: path + '/root1@localhost:9001', + path: path + '/root1@localhost:' + server.port, token: server.accessToken, statusCodeExpected: 404 }) @@ -203,7 +202,7 @@ describe('Test user subscriptions API validators', function () { it('Should succeed with the correct parameters', async function () { await makeGetRequest({ url: server.url, - path: path + '/user1_channel@localhost:9001', + path: path + '/user1_channel@localhost:' + server.port, token: server.accessToken, statusCodeExpected: 200 }) @@ -243,7 +242,7 @@ describe('Test user subscriptions API validators', function () { await makeGetRequest({ url: server.url, path: existPath, - query: { 'uris[]': 'coucou@localhost:9001' }, + query: { 'uris[]': 'coucou@localhost:' + server.port }, token: server.accessToken, statusCodeExpected: 200 }) @@ -254,7 +253,7 @@ describe('Test user subscriptions API validators', function () { it('Should fail with a non authenticated user', async function () { await makeDeleteRequest({ url: server.url, - path: path + '/user1_channel@localhost:9001', + path: path + '/user1_channel@localhost:' + server.port, statusCodeExpected: 401 }) }) @@ -285,7 +284,7 @@ describe('Test user subscriptions API validators', function () { it('Should fail with an unknown subscription', async function () { await makeDeleteRequest({ url: server.url, - path: path + '/root1@localhost:9001', + path: path + '/root1@localhost:' + server.port, token: server.accessToken, statusCodeExpected: 404 }) @@ -294,14 +293,14 @@ describe('Test user subscriptions API validators', function () { it('Should succeed with the correct parameters', async function () { await makeDeleteRequest({ url: server.url, - path: path + '/user1_channel@localhost:9001', + path: path + '/user1_channel@localhost:' + server.port, token: server.accessToken, statusCodeExpected: 204 }) }) }) - after(function () { - killallServers([ server ]) + after(async function () { + await cleanupTests([ server ]) }) }) diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts index d2fea65f61d3d5dde755b5ac50b5350a0805b682..5935104a58cfb8898c57158c610fde4c559ff56c 100644 --- a/server/tests/api/check-params/users.ts +++ b/server/tests/api/check-params/users.ts @@ -7,6 +7,7 @@ import { UserRole, VideoImport, VideoImportState } from '../../../../shared' import { blockUser, + cleanupTests, createUser, deleteMe, flushAndRunServer, @@ -14,7 +15,6 @@ import { getMyUserVideoRating, getUsersList, immutableAssign, - killallServers, makeGetRequest, makePostBodyRequest, makePutBodyRequest, @@ -713,7 +713,7 @@ describe('Test users API validators', function () { }) it('Should fail if we register a user with the same email', async function () { - const fields = immutableAssign(baseCorrectParams, { email: 'admin1@example.com' }) + const fields = immutableAssign(baseCorrectParams, { email: 'admin' + server.internalServerNumber + '@example.com' }) await makePostBodyRequest({ url: server.url, @@ -897,7 +897,7 @@ describe('Test users API validators', function () { }) }) - after(function () { - killallServers([ server, serverWithRegistrationDisabled ]) + after(async function () { + await cleanupTests([ server, serverWithRegistrationDisabled ]) }) }) diff --git a/server/tests/api/check-params/video-abuses.ts b/server/tests/api/check-params/video-abuses.ts index e2813d470cf5c8ef6b0a48e55b3e9d224331de62..bf29f8d4d9126369d1b6521716932419cffec828 100644 --- a/server/tests/api/check-params/video-abuses.ts +++ b/server/tests/api/check-params/video-abuses.ts @@ -3,13 +3,12 @@ import 'mocha' import { + cleanupTests, createUser, deleteVideoAbuse, - flushTests, - killallServers, + flushAndRunServer, makeGetRequest, makePostBodyRequest, - flushAndRunServer, ServerInfo, setAccessTokensToServers, updateVideoAbuse, @@ -188,7 +187,7 @@ describe('Test video abuses API validators', function () { }) }) - after(function () { - killallServers([ server ]) + after(async function () { + await cleanupTests([ server ]) }) }) diff --git a/server/tests/api/check-params/video-blacklist.ts b/server/tests/api/check-params/video-blacklist.ts index f9c7d9e9a51bdd6c129283eeb442ffe506f714bb..6466888fb5386623139f645f0c7701666591e5ac 100644 --- a/server/tests/api/check-params/video-blacklist.ts +++ b/server/tests/api/check-params/video-blacklist.ts @@ -3,6 +3,7 @@ import 'mocha' import { + cleanupTests, createUser, doubleFollow, flushAndRunMultipleServers, @@ -247,7 +248,7 @@ describe('Test video blacklist API validators', function () { }) }) - after(function () { - killallServers(servers) + after(async function () { + await cleanupTests(servers) }) }) diff --git a/server/tests/api/check-params/video-captions.ts b/server/tests/api/check-params/video-captions.ts index 64265865a9fd027161df9128eef690b4ede4374b..4a373d43de15ff244d1132002e9e230d67b1c1a2 100644 --- a/server/tests/api/check-params/video-captions.ts +++ b/server/tests/api/check-params/video-captions.ts @@ -2,13 +2,12 @@ import 'mocha' import { + cleanupTests, createUser, - flushTests, - killallServers, + flushAndRunServer, makeDeleteRequest, makeGetRequest, makeUploadRequest, - flushAndRunServer, ServerInfo, setAccessTokensToServers, uploadVideo, @@ -269,7 +268,7 @@ describe('Test video captions API validator', function () { }) }) - after(function () { - killallServers([ server ]) + after(async function () { + await cleanupTests([ server ]) }) }) diff --git a/server/tests/api/check-params/video-channels.ts b/server/tests/api/check-params/video-channels.ts index 06da4f54138034b5ca2e59f5b7ea3db51c898d2e..65bc2061382a3a1a3af50e1fa4d91058b3b6949c 100644 --- a/server/tests/api/check-params/video-channels.ts +++ b/server/tests/api/check-params/video-channels.ts @@ -4,19 +4,16 @@ import * as chai from 'chai' import { omit } from 'lodash' import 'mocha' import { + cleanupTests, createUser, deleteVideoChannel, - flushTests, + flushAndRunServer, getAccountVideoChannelsList, - getMyUserInformation, - getVideoChannelsList, immutableAssign, - killallServers, makeGetRequest, makePostBodyRequest, makePutBodyRequest, makeUploadRequest, - flushAndRunServer, ServerInfo, setAccessTokensToServers, userLogin @@ -26,7 +23,6 @@ import { checkBadSortPagination, checkBadStartPagination } from '../../../../shared/extra-utils/requests/check-api-params' -import { User } from '../../../../shared/models/users' import { join } from 'path' const expect = chai.expect @@ -310,7 +306,7 @@ describe('Test video channels API validator', function () { }) }) - after(function () { - killallServers([ server ]) + after(async function () { + await cleanupTests([ server ]) }) }) diff --git a/server/tests/api/check-params/video-comments.ts b/server/tests/api/check-params/video-comments.ts index dfa4c29b64e85f29d3f85bc85c44e7aedf815df6..5cf90bacc25407fde6b9a44de5a529b0182bdbb6 100644 --- a/server/tests/api/check-params/video-comments.ts +++ b/server/tests/api/check-params/video-comments.ts @@ -3,9 +3,9 @@ import * as chai from 'chai' import 'mocha' import { + cleanupTests, createUser, flushAndRunServer, - killallServers, makeDeleteRequest, makeGetRequest, makePostBodyRequest, @@ -258,7 +258,7 @@ describe('Test video comments API validator', function () { it('Should return conflict on comment thread add') }) - after(function () { - killallServers([ server ]) + after(async function () { + await cleanupTests([ server ]) }) }) diff --git a/server/tests/api/check-params/video-imports.ts b/server/tests/api/check-params/video-imports.ts index 82fdc06670a34164796a61628c9a42e648b093a6..8ff115e7bb352baa6f33aecc3c359eadaba1c3ad 100644 --- a/server/tests/api/check-params/video-imports.ts +++ b/server/tests/api/check-params/video-imports.ts @@ -5,15 +5,14 @@ import 'mocha' import { join } from 'path' import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum' import { + cleanupTests, createUser, - flushTests, + flushAndRunServer, getMyUserInformation, immutableAssign, - killallServers, makeGetRequest, makePostBodyRequest, makeUploadRequest, - flushAndRunServer, ServerInfo, setAccessTokensToServers, updateCustomSubConfig, @@ -311,7 +310,7 @@ describe('Test video imports API validator', function () { }) }) - after(function () { - killallServers([ server ]) + after(async function () { + await cleanupTests([ server ]) }) }) diff --git a/server/tests/api/check-params/video-playlists.ts b/server/tests/api/check-params/video-playlists.ts index 0edb51682b09dbe130d0ba6baa1694e644fdb09c..b7b94c035bbc7e9f08f527eeeff81e0ef682d099 100644 --- a/server/tests/api/check-params/video-playlists.ts +++ b/server/tests/api/check-params/video-playlists.ts @@ -3,20 +3,20 @@ import 'mocha' import { addVideoInPlaylist, + cleanupTests, createVideoPlaylist, deleteVideoPlaylist, - flushTests, + flushAndRunServer, generateUserAccessToken, getAccountPlaylistsListWithToken, getVideoPlaylist, immutableAssign, - killallServers, makeGetRequest, removeVideoFromPlaylist, reorderVideosPlaylist, - flushAndRunServer, ServerInfo, - setAccessTokensToServers, setDefaultVideoChannel, + setAccessTokensToServers, + setDefaultVideoChannel, updateVideoPlaylist, updateVideoPlaylistElement, uploadVideoAndGetId @@ -668,7 +668,7 @@ describe('Test video playlists API validator', function () { }) }) - after(function () { - killallServers([ server ]) + after(async function () { + await cleanupTests([ server ]) }) }) diff --git a/server/tests/api/check-params/videos-filter.ts b/server/tests/api/check-params/videos-filter.ts index 82cc0f638e2fa4d015299d08c7d09c047bcf4b80..babef82234f79cb8856012fe3bdb08d0d14bf25d 100644 --- a/server/tests/api/check-params/videos-filter.ts +++ b/server/tests/api/check-params/videos-filter.ts @@ -2,14 +2,14 @@ import 'mocha' import { + cleanupTests, createUser, createVideoPlaylist, - flushTests, - killallServers, - makeGetRequest, flushAndRunServer, + makeGetRequest, ServerInfo, - setAccessTokensToServers, setDefaultVideoChannel, + setAccessTokensToServers, + setDefaultVideoChannel, userLogin } from '../../../../shared/extra-utils' import { UserRole } from '../../../../shared/models/users' @@ -129,7 +129,7 @@ describe('Test videos filters', function () { }) }) - after(function () { - killallServers([ server ]) + after(async function () { + await cleanupTests([ server ]) }) }) diff --git a/server/tests/api/check-params/videos-history.ts b/server/tests/api/check-params/videos-history.ts index 32f65f5103bd4ddeda781ad3dcfbc84824ec5dfe..3739e3fad8151e9b9cab280992ffb38edc42c011 100644 --- a/server/tests/api/check-params/videos-history.ts +++ b/server/tests/api/check-params/videos-history.ts @@ -5,12 +5,11 @@ import 'mocha' import { checkBadCountPagination, checkBadStartPagination, - flushTests, - killallServers, + cleanupTests, + flushAndRunServer, makeGetRequest, makePostBodyRequest, makePutBodyRequest, - flushAndRunServer, ServerInfo, setAccessTokensToServers, uploadVideo @@ -126,7 +125,7 @@ describe('Test videos history API validator', function () { }) }) - after(function () { - killallServers([ server ]) + after(async function () { + await cleanupTests([ server ]) }) }) diff --git a/server/tests/api/check-params/videos.ts b/server/tests/api/check-params/videos.ts index bc321e91fc00398296524195ef16e6349cca28d4..51e592a15ca29967c2df0578cce69149a230ae1f 100644 --- a/server/tests/api/check-params/videos.ts +++ b/server/tests/api/check-params/videos.ts @@ -6,16 +6,28 @@ import 'mocha' import { join } from 'path' import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum' import { - createUser, flushTests, getMyUserInformation, getVideo, getVideosList, immutableAssign, killallServers, makeDeleteRequest, - makeGetRequest, makeUploadRequest, makePutBodyRequest, removeVideo, uploadVideo, - flushAndRunServer, ServerInfo, setAccessTokensToServers, userLogin, updateCustomSubConfig + cleanupTests, + createUser, + flushAndRunServer, + getMyUserInformation, + getVideo, + getVideosList, + immutableAssign, + makeDeleteRequest, + makeGetRequest, + makePutBodyRequest, + makeUploadRequest, + removeVideo, + ServerInfo, + setAccessTokensToServers, + userLogin, + root } from '../../../../shared/extra-utils' import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../../../shared/extra-utils/requests/check-api-params' -import { getAccountsList } from '../../../../shared/extra-utils/users/accounts' const expect = chai.expect @@ -166,7 +178,7 @@ describe('Test videos API validator', function () { describe('When adding a video', function () { let baseCorrectParams const baseCorrectAttaches = { - 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.webm') + 'videofile': join(root(), 'server', 'tests', 'fixtures', 'video_short.webm') } before(function () { @@ -326,15 +338,15 @@ describe('Test videos API validator', function () { await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) }) - it('Should fail without an incorrect input file', async function () { + it('Should fail with an incorrect input file', async function () { const fields = baseCorrectParams let attaches = { - 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short_fake.webm') + 'videofile': join(root(), 'server', 'tests', 'fixtures', 'video_short_fake.webm') } await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) attaches = { - 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.mkv') + 'videofile': join(root(), 'server', 'tests', 'fixtures', 'video_short.mkv') } await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) }) @@ -342,8 +354,8 @@ describe('Test videos API validator', function () { it('Should fail with an incorrect thumbnail file', async function () { const fields = baseCorrectParams const attaches = { - 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png'), - 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4') + 'thumbnailfile': join(root(), 'server', 'tests', 'fixtures', 'avatar.png'), + 'videofile': join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') } await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) @@ -352,8 +364,8 @@ describe('Test videos API validator', function () { it('Should fail with a big thumbnail file', async function () { const fields = baseCorrectParams const attaches = { - 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png'), - 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4') + 'thumbnailfile': join(root(), 'server', 'tests', 'fixtures', 'avatar-big.png'), + 'videofile': join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') } await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) @@ -362,8 +374,8 @@ describe('Test videos API validator', function () { it('Should fail with an incorrect preview file', async function () { const fields = baseCorrectParams const attaches = { - 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png'), - 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4') + 'previewfile': join(root(), 'server', 'tests', 'fixtures', 'avatar.png'), + 'videofile': join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') } await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) @@ -372,8 +384,8 @@ describe('Test videos API validator', function () { it('Should fail with a big preview file', async function () { const fields = baseCorrectParams const attaches = { - 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png'), - 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4') + 'previewfile': join(root(), 'server', 'tests', 'fixtures', 'avatar-big.png'), + 'videofile': join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') } await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) @@ -398,7 +410,7 @@ describe('Test videos API validator', function () { { const attaches = immutableAssign(baseCorrectAttaches, { - videofile: join(__dirname, '..', '..', 'fixtures', 'video_short.mp4') + videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') }) await makeUploadRequest({ @@ -413,7 +425,7 @@ describe('Test videos API validator', function () { { const attaches = immutableAssign(baseCorrectAttaches, { - videofile: join(__dirname, '..', '..', 'fixtures', 'video_short.ogv') + videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.ogv') }) await makeUploadRequest({ @@ -550,7 +562,7 @@ describe('Test videos API validator', function () { it('Should fail with an incorrect thumbnail file', async function () { const fields = baseCorrectParams const attaches = { - 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png') + 'thumbnailfile': join(root(), 'server', 'tests', 'fixtures', 'avatar.png') } await makeUploadRequest({ @@ -566,7 +578,7 @@ describe('Test videos API validator', function () { it('Should fail with a big thumbnail file', async function () { const fields = baseCorrectParams const attaches = { - 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png') + 'thumbnailfile': join(root(), 'server', 'tests', 'fixtures', 'avatar-big.png') } await makeUploadRequest({ @@ -582,7 +594,7 @@ describe('Test videos API validator', function () { it('Should fail with an incorrect preview file', async function () { const fields = baseCorrectParams const attaches = { - 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png') + 'previewfile': join(root(), 'server', 'tests', 'fixtures', 'avatar.png') } await makeUploadRequest({ @@ -598,7 +610,7 @@ describe('Test videos API validator', function () { it('Should fail with a big preview file', async function () { const fields = baseCorrectParams const attaches = { - 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png') + 'previewfile': join(root(), 'server', 'tests', 'fixtures', 'avatar-big.png') } await makeUploadRequest({ @@ -728,7 +740,7 @@ describe('Test videos API validator', function () { }) }) - after(function () { - killallServers([ server ]) + after(async function () { + await cleanupTests([ server ]) }) }) diff --git a/server/tests/api/notifications/user-notifications.ts b/server/tests/api/notifications/user-notifications.ts index eb4fdb87c9545b1f8eefaffb92b37269d364bf29..3874b0aab4cd19777ad5d452aa62ad9e2c0028da 100644 --- a/server/tests/api/notifications/user-notifications.ts +++ b/server/tests/api/notifications/user-notifications.ts @@ -19,7 +19,7 @@ import { userLogin, wait, getCustomConfig, - updateCustomConfig, getVideoThreadComments, getVideoCommentThreads, follow + updateCustomConfig, getVideoThreadComments, getVideoCommentThreads, follow, cleanupTests } from '../../../../shared/extra-utils' import { killallServers, ServerInfo, uploadVideo } from '../../../../shared/extra-utils/index' import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login' @@ -1295,9 +1295,9 @@ describe('Test users notifications', function () { }) }) - after(function () { + after(async function () { MockSmtpServer.Instance.kill() - killallServers(servers) + await cleanupTests(servers) }) }) diff --git a/server/tests/api/redundancy/redundancy.ts b/server/tests/api/redundancy/redundancy.ts index 280a4c64b5b0df431075a3ae3d65a1f67fb011ab..e31329c255fbf97426f1b806beb8375e40ddd03a 100644 --- a/server/tests/api/redundancy/redundancy.ts +++ b/server/tests/api/redundancy/redundancy.ts @@ -5,7 +5,7 @@ import 'mocha' import { VideoDetails } from '../../../../shared/models/videos' import { checkSegmentHash, - checkVideoFilesWereRemoved, + checkVideoFilesWereRemoved, cleanupTests, doubleFollow, flushAndRunMultipleServers, getFollowingListPaginationAndSort, @@ -52,7 +52,7 @@ function checkMagnetWebseeds (file: { magnetUri: string, resolution: { id: numbe expect(parsed.urlList).to.have.lengthOf(baseWebseeds.length) } -async function runServers (strategy: VideoRedundancyStrategy, additionalParams: any = {}) { +async function flushAndRunServers (strategy: VideoRedundancyStrategy, additionalParams: any = {}) { const config = { transcoding: { hls: { @@ -264,10 +264,6 @@ async function disableRedundancyOnServer1 () { expect(server2.following.hostRedundancyAllowed).to.be.false } -async function cleanServers () { - killallServers(servers) -} - describe('Test videos redundancy', function () { describe('With most-views strategy', function () { @@ -276,7 +272,7 @@ describe('Test videos redundancy', function () { before(function () { this.timeout(120000) - return runServers(strategy) + return flushAndRunServers(strategy) }) it('Should have 1 webseed on the first video', async function () { @@ -315,8 +311,8 @@ describe('Test videos redundancy', function () { await checkVideoFilesWereRemoved(video1Server2UUID, servers[0].serverNumber, [ 'videos', join('playlists', 'hls') ]) }) - after(function () { - return cleanServers() + after(async function () { + return cleanupTests(servers) }) }) @@ -326,7 +322,7 @@ describe('Test videos redundancy', function () { before(function () { this.timeout(120000) - return runServers(strategy) + return flushAndRunServers(strategy) }) it('Should have 1 webseed on the first video', async function () { @@ -365,8 +361,8 @@ describe('Test videos redundancy', function () { await checkVideoFilesWereRemoved(video1Server2UUID, servers[0].serverNumber, [ 'videos' ]) }) - after(function () { - return cleanServers() + after(async function () { + await cleanupTests(servers) }) }) @@ -376,7 +372,7 @@ describe('Test videos redundancy', function () { before(function () { this.timeout(120000) - return runServers(strategy, { min_views: 3 }) + return flushAndRunServers(strategy, { min_views: 3 }) }) it('Should have 1 webseed on the first video', async function () { @@ -435,8 +431,8 @@ describe('Test videos redundancy', function () { } }) - after(function () { - return cleanServers() + after(async function () { + await cleanupTests(servers) }) }) @@ -468,7 +464,7 @@ describe('Test videos redundancy', function () { before(async function () { this.timeout(120000) - await runServers(strategy, { min_lifetime: '7 seconds', min_views: 0 }) + await flushAndRunServers(strategy, { min_lifetime: '7 seconds', min_views: 0 }) await enableRedundancyOnServer1() }) @@ -498,8 +494,8 @@ describe('Test videos redundancy', function () { await checkNotContains([ servers[1], servers[2] ], 'http%3A%2F%2Flocalhost%3A9001') }) - after(function () { - return killallServers([ servers[1], servers[2] ]) + after(async function () { + await cleanupTests(servers) }) }) @@ -510,7 +506,7 @@ describe('Test videos redundancy', function () { before(async function () { this.timeout(120000) - await runServers(strategy, { min_lifetime: '7 seconds', min_views: 0 }) + await flushAndRunServers(strategy, { min_lifetime: '7 seconds', min_views: 0 }) await enableRedundancyOnServer1() @@ -569,8 +565,8 @@ describe('Test videos redundancy', function () { await checkVideoFilesWereRemoved(video1Server2UUID, servers[0].serverNumber, [ join('redundancy', 'hls') ]) }) - after(function () { - return cleanServers() + after(async function () { + await cleanupTests(servers) }) }) }) diff --git a/server/tests/api/search/search-activitypub-video-channels.ts b/server/tests/api/search/search-activitypub-video-channels.ts index c5662f049a95759e19d0eae99e735c88e06cc1e0..4d1ceb767aacc194ef652113a886e446cab57cf3 100644 --- a/server/tests/api/search/search-activitypub-video-channels.ts +++ b/server/tests/api/search/search-activitypub-video-channels.ts @@ -3,7 +3,7 @@ import * as chai from 'chai' import 'mocha' import { - addVideoChannel, + addVideoChannel, cleanupTests, createUser, deleteVideoChannel, flushAndRunMultipleServers, @@ -205,7 +205,7 @@ describe('Test a ActivityPub video channels search', function () { expect(res.body.data).to.have.lengthOf(0) }) - after(function () { - killallServers(servers) + after(async function () { + await cleanupTests(servers) }) }) diff --git a/server/tests/api/search/search-activitypub-videos.ts b/server/tests/api/search/search-activitypub-videos.ts index 5c2a44ad5383c9cb6e3a939624e5207673584c13..e039961cb5d4d279b68a27da0e6ecc54b9249868 100644 --- a/server/tests/api/search/search-activitypub-videos.ts +++ b/server/tests/api/search/search-activitypub-videos.ts @@ -15,7 +15,7 @@ import { updateVideo, uploadVideo, wait, - searchVideo + searchVideo, cleanupTests } from '../../../../shared/extra-utils' import { waitJobs } from '../../../../shared/extra-utils/server/jobs' import { Video, VideoPrivacy } from '../../../../shared/models/videos' @@ -149,7 +149,7 @@ describe('Test a ActivityPub videos search', function () { expect(res.body.data).to.have.lengthOf(0) }) - after(function () { - killallServers(servers) + after(async function () { + await cleanupTests(servers) }) }) diff --git a/server/tests/api/search/search-videos.ts b/server/tests/api/search/search-videos.ts index d1520a9aa8c767733f961ca7c813461169f61308..1a086b33affdfee1b3b1ddfebcb43bde2f9cb9c8 100644 --- a/server/tests/api/search/search-videos.ts +++ b/server/tests/api/search/search-videos.ts @@ -12,7 +12,8 @@ import { setAccessTokensToServers, uploadVideo, wait, - immutableAssign + immutableAssign, + cleanupTests } from '../../../../shared/extra-utils' const expect = chai.expect @@ -405,7 +406,7 @@ describe('Test a videos search', function () { } }) - after(function () { - killallServers([ server ]) + after(async function () { + await cleanupTests([ server ]) }) }) diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts index d8137b3397350e4b1f70e185986c1817768846de..c0d11914bf2d047557c1c57b68701b498500d8ce 100644 --- a/server/tests/api/server/config.ts +++ b/server/tests/api/server/config.ts @@ -5,15 +5,15 @@ import * as chai from 'chai' import { About } from '../../../../shared/models/server/about.model' import { CustomConfig } from '../../../../shared/models/server/custom-config.model' import { + cleanupTests, deleteCustomConfig, + flushAndRunServer, getAbout, - killallServers, - reRunServer, - flushTests, getConfig, getCustomConfig, + killallServers, registerUser, - flushAndRunServer, + reRunServer, setAccessTokensToServers, updateCustomConfig } from '../../../../shared/extra-utils' @@ -300,7 +300,7 @@ describe('Test config', function () { checkInitialConfig(data) }) - after(function () { - killallServers([ server ]) + after(async function () { + await cleanupTests([ server ]) }) }) diff --git a/server/tests/api/server/contact-form.ts b/server/tests/api/server/contact-form.ts index 26ebb4ed7a21d8bcd324a37292a9329a149c56dd..ba51198b3de72b35d3de072342c41647e8236479 100644 --- a/server/tests/api/server/contact-form.ts +++ b/server/tests/api/server/contact-form.ts @@ -2,7 +2,15 @@ import * as chai from 'chai' import 'mocha' -import { flushTests, killallServers, flushAndRunServer, ServerInfo, setAccessTokensToServers, wait } from '../../../../shared/extra-utils' +import { + flushTests, + killallServers, + flushAndRunServer, + ServerInfo, + setAccessTokensToServers, + wait, + cleanupTests +} from '../../../../shared/extra-utils' import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email' import { waitJobs } from '../../../../shared/extra-utils/server/jobs' import { sendContactForm } from '../../../../shared/extra-utils/server/contact-form' @@ -78,8 +86,9 @@ describe('Test contact form', function () { }) }) - after(function () { + after(async function () { MockSmtpServer.Instance.kill() - killallServers([ server ]) + + await cleanupTests([ server ]) }) }) diff --git a/server/tests/api/server/email.ts b/server/tests/api/server/email.ts index 1158ceb0ed5304152e45f4f2b828ebb580c8c700..bacdf1b1b7fd9cd3d2ae41fbecd999f62c9cc28a 100644 --- a/server/tests/api/server/email.ts +++ b/server/tests/api/server/email.ts @@ -18,7 +18,7 @@ import { flushTests, killallServers, ServerInfo, - setAccessTokensToServers + setAccessTokensToServers, cleanupTests } from '../../../../shared/extra-utils' import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email' import { waitJobs } from '../../../../shared/extra-utils/server/jobs' @@ -256,8 +256,9 @@ describe('Test emails', function () { }) }) - after(function () { + after(async function () { MockSmtpServer.Instance.kill() - killallServers([ server ]) + + await cleanupTests([ server ]) }) }) diff --git a/server/tests/api/server/follow-constraints.ts b/server/tests/api/server/follow-constraints.ts index cf40018b38b4bc06f21295d01e66d4038e14f08f..4285a9e7a864f18ee71caa84072801cec1ca48bc 100644 --- a/server/tests/api/server/follow-constraints.ts +++ b/server/tests/api/server/follow-constraints.ts @@ -12,7 +12,7 @@ import { killallServers, ServerInfo, setAccessTokensToServers, - uploadVideo + uploadVideo, cleanupTests } from '../../../../shared/extra-utils' import { unfollow } from '../../../../shared/extra-utils/server/follows' import { userLogin } from '../../../../shared/extra-utils/users/login' @@ -219,7 +219,7 @@ describe('Test follow constraints', function () { }) }) - after(function () { - killallServers(servers) + after(async function () { + await cleanupTests(servers) }) }) diff --git a/server/tests/api/server/follows-moderation.ts b/server/tests/api/server/follows-moderation.ts index ae8716184f5b522f7ad7e0fc2993425b117cb640..2a3a4d5c823516c1ddc9e5147bcad733c9d192a6 100644 --- a/server/tests/api/server/follows-moderation.ts +++ b/server/tests/api/server/follows-moderation.ts @@ -3,7 +3,7 @@ import * as chai from 'chai' import 'mocha' import { - acceptFollower, + acceptFollower, cleanupTests, flushAndRunMultipleServers, killallServers, ServerInfo, @@ -189,7 +189,7 @@ describe('Test follows moderation', function () { } }) - after(function () { - killallServers(servers) + after(async function () { + await cleanupTests(servers) }) }) diff --git a/server/tests/api/server/follows.ts b/server/tests/api/server/follows.ts index f1b4a450ef1740e12a42f9e103c1a8b7e9cc5247..397093cdbd275d974bbc6b1be65b796c7135bda9 100644 --- a/server/tests/api/server/follows.ts +++ b/server/tests/api/server/follows.ts @@ -4,7 +4,7 @@ import * as chai from 'chai' import 'mocha' import { Video, VideoPrivacy } from '../../../../shared/models/videos' import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model' -import { completeVideoCheck } from '../../../../shared/extra-utils' +import { cleanupTests, completeVideoCheck } from '../../../../shared/extra-utils' import { flushAndRunMultipleServers, getVideosList, @@ -435,7 +435,7 @@ describe('Test follows', function () { }) - after(function () { - killallServers(servers) + after(async function () { + await cleanupTests(servers) }) }) diff --git a/server/tests/api/server/handle-down.ts b/server/tests/api/server/handle-down.ts index d0f700bdada74701da6ce0e3ee18ac0a171c08b3..19010dbc17dc3bdbe5f034056cbb42c64380fdc8 100644 --- a/server/tests/api/server/handle-down.ts +++ b/server/tests/api/server/handle-down.ts @@ -7,6 +7,7 @@ import { VideoPrivacy } from '../../../../shared/models/videos' import { VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model' import { + cleanupTests, completeVideoCheck, flushAndRunMultipleServers, getVideo, @@ -296,7 +297,7 @@ describe('Test handle downs', function () { } }) - after(function () { - killallServers(servers) + after(async function () { + await cleanupTests(servers) }) }) diff --git a/server/tests/api/server/jobs.ts b/server/tests/api/server/jobs.ts index 01f561b0dffde38ebef29b63e778fa958581788e..6346546261a3b12c25fe2b0cdc30737d99b13d1c 100644 --- a/server/tests/api/server/jobs.ts +++ b/server/tests/api/server/jobs.ts @@ -2,7 +2,7 @@ import * as chai from 'chai' import 'mocha' -import { killallServers, ServerInfo, setAccessTokensToServers } from '../../../../shared/extra-utils/index' +import { cleanupTests, killallServers, ServerInfo, setAccessTokensToServers } from '../../../../shared/extra-utils/index' import { doubleFollow } from '../../../../shared/extra-utils/server/follows' import { getJobsList, getJobsListPaginationAndSort, waitJobs } from '../../../../shared/extra-utils/server/jobs' import { flushAndRunMultipleServers } from '../../../../shared/extra-utils/server/servers' @@ -56,7 +56,7 @@ describe('Test jobs', function () { expect(dateIsValid(job.finishedOn)).to.be.true }) - after(function () { - killallServers(servers) + after(async function () { + await cleanupTests(servers) }) }) diff --git a/server/tests/api/server/logs.ts b/server/tests/api/server/logs.ts index 5ca35220596bf33475d17bf6a88442f223c4d984..3644fa0d307de2bef79348383e274bf9219023ee 100644 --- a/server/tests/api/server/logs.ts +++ b/server/tests/api/server/logs.ts @@ -2,7 +2,14 @@ import * as chai from 'chai' import 'mocha' -import { flushTests, killallServers, flushAndRunServer, ServerInfo, setAccessTokensToServers } from '../../../../shared/extra-utils/index' +import { + flushTests, + killallServers, + flushAndRunServer, + ServerInfo, + setAccessTokensToServers, + cleanupTests +} from '../../../../shared/extra-utils/index' import { waitJobs } from '../../../../shared/extra-utils/server/jobs' import { uploadVideo } from '../../../../shared/extra-utils/videos/videos' import { getLogs } from '../../../../shared/extra-utils/logs/logs' @@ -84,7 +91,7 @@ describe('Test logs', function () { } }) - after(function () { - killallServers([ server ]) + after(async function () { + await cleanupTests([ server ]) }) }) diff --git a/server/tests/api/server/no-client.ts b/server/tests/api/server/no-client.ts index 226fbfda41e174e97155a8db2ac22f807458567d..86edeb2891c18ad4f1067573d92b78a9b9738854 100644 --- a/server/tests/api/server/no-client.ts +++ b/server/tests/api/server/no-client.ts @@ -1,11 +1,7 @@ import 'mocha' import * as request from 'supertest' -import { - flushTests, - killallServers, - ServerInfo -} from '../../../../shared/extra-utils' -import { flushAndRunServer } from '../../../../shared/extra-utils/server/servers' +import { ServerInfo } from '../../../../shared/extra-utils' +import { cleanupTests, flushAndRunServer } from '../../../../shared/extra-utils/server/servers' describe('Start and stop server without web client routes', function () { let server: ServerInfo @@ -23,7 +19,7 @@ describe('Start and stop server without web client routes', function () { return req.expect(404) }) - after(function () { - killallServers([ server ]) + after(async function () { + await cleanupTests([ server ]) }) }) diff --git a/server/tests/api/server/reverse-proxy.ts b/server/tests/api/server/reverse-proxy.ts index e55b12bfcf4ef0a5c9ce021130aacb5da1774876..9875382374e527087fe6dad511fb266cef3c932e 100644 --- a/server/tests/api/server/reverse-proxy.ts +++ b/server/tests/api/server/reverse-proxy.ts @@ -2,28 +2,10 @@ import 'mocha' import * as chai from 'chai' -import { About } from '../../../../shared/models/server/about.model' -import { CustomConfig } from '../../../../shared/models/server/custom-config.model' -import { - deleteCustomConfig, - getAbout, - getVideo, - killallServers, - login, - reRunServer, - uploadVideo, - userLogin, - viewVideo, - wait -} from '../../../../shared/extra-utils' -const expect = chai.expect +import { cleanupTests, getVideo, uploadVideo, userLogin, viewVideo, wait } from '../../../../shared/extra-utils' +import { flushAndRunServer, setAccessTokensToServers } from '../../../../shared/extra-utils/index' -import { - getConfig, - flushTests, - flushAndRunServer, - registerUser, getCustomConfig, setAccessTokensToServers, updateCustomConfig -} from '../../../../shared/extra-utils/index' +const expect = chai.expect describe('Test application behind a reverse proxy', function () { let server = null @@ -100,7 +82,7 @@ describe('Test application behind a reverse proxy', function () { await userLogin(server, user, 429) }) - after(function () { - killallServers([ server ]) + after(async function () { + await cleanupTests([ server ]) }) }) diff --git a/server/tests/api/server/stats.ts b/server/tests/api/server/stats.ts index bd3d2155c5b3e3c84ea48f7a2f359265eb0e23e3..a01cd4b389de4aef5d606fe42ceec15e852b939c 100644 --- a/server/tests/api/server/stats.ts +++ b/server/tests/api/server/stats.ts @@ -4,6 +4,7 @@ import * as chai from 'chai' import 'mocha' import { ServerStats } from '../../../../shared/models/server/server-stats.model' import { + cleanupTests, createUser, doubleFollow, flushAndRunMultipleServers, @@ -95,7 +96,7 @@ describe('Test stats (excluding redundancy)', function () { expect(data.totalInstanceFollowers).to.equal(0) }) - after(function () { - killallServers(servers) + after(async function () { + await cleanupTests(servers) }) }) diff --git a/server/tests/api/server/tracker.ts b/server/tests/api/server/tracker.ts index 1b4e190f1b8a6b969920eae0848a2bae0a2f6148..9d7eec8ca508ffb367f06adbd2528d1e68a3b923 100644 --- a/server/tests/api/server/tracker.ts +++ b/server/tests/api/server/tracker.ts @@ -2,8 +2,16 @@ import * as magnetUtil from 'magnet-uri' import 'mocha' -import { getVideo, killallServers, reRunServer, flushAndRunServer, ServerInfo, uploadVideo } from '../../../../shared/extra-utils' -import { flushTests, setAccessTokensToServers } from '../../../../shared/extra-utils/index' +import { + cleanupTests, + flushAndRunServer, + getVideo, + killallServers, + reRunServer, + ServerInfo, + uploadVideo +} from '../../../../shared/extra-utils' +import { setAccessTokensToServers } from '../../../../shared/extra-utils/index' import { VideoDetails } from '../../../../shared/models/videos' import * as WebTorrent from 'webtorrent' @@ -82,7 +90,7 @@ describe('Test tracker', function () { }) }) - after(function () { - killallServers([ server ]) + after(async function () { + await cleanupTests([ server ]) }) }) diff --git a/server/tests/api/users/blocklist.ts b/server/tests/api/users/blocklist.ts index 34eabf2e6cad79d0316d471ce0266cf765f6e57b..fbc57e0ef690a74f4f1d8cd56ddd40f0d6224fdb 100644 --- a/server/tests/api/users/blocklist.ts +++ b/server/tests/api/users/blocklist.ts @@ -4,6 +4,7 @@ import * as chai from 'chai' import 'mocha' import { AccountBlock, ServerBlock, Video } from '../../../../shared/index' import { + cleanupTests, createUser, doubleFollow, flushAndRunMultipleServers, @@ -498,7 +499,7 @@ describe('Test blocklist', function () { }) }) - after(function () { - killallServers(servers) + after(async function () { + await cleanupTests(servers) }) }) diff --git a/server/tests/api/users/user-subscriptions.ts b/server/tests/api/users/user-subscriptions.ts index ee5abd6b73e183dbcb3aba49dc5c1640bb9ade18..48811e647d172606b4db54aee8fce30270dd8212 100644 --- a/server/tests/api/users/user-subscriptions.ts +++ b/server/tests/api/users/user-subscriptions.ts @@ -3,6 +3,7 @@ import * as chai from 'chai' import 'mocha' import { + cleanupTests, createUser, doubleFollow, flushAndRunMultipleServers, @@ -368,7 +369,7 @@ describe('Test users subscriptions', function () { } }) - after(function () { - killallServers(servers) + after(async function () { + await cleanupTests(servers) }) }) diff --git a/server/tests/api/users/users-multiple-servers.ts b/server/tests/api/users/users-multiple-servers.ts index 7097d90d1feb6aef1754025d9126481aec4f4843..9a971adb39350d557938d55314c9c51c8428d66f 100644 --- a/server/tests/api/users/users-multiple-servers.ts +++ b/server/tests/api/users/users-multiple-servers.ts @@ -5,7 +5,7 @@ import 'mocha' import { Account } from '../../../../shared/models/actors' import { checkTmpIsEmpty, - checkVideoFilesWereRemoved, + checkVideoFilesWereRemoved, cleanupTests, createUser, doubleFollow, flushAndRunMultipleServers, @@ -235,7 +235,7 @@ describe('Test users with multiple servers', function () { } }) - after(function () { - killallServers(servers) + after(async function () { + await cleanupTests(servers) }) }) diff --git a/server/tests/api/users/users-verification.ts b/server/tests/api/users/users-verification.ts index 295caae978dd13f71397ef69dcc16b05a2308723..514acf2e7daf2de90b9262e1caab68c04b39f04d 100644 --- a/server/tests/api/users/users-verification.ts +++ b/server/tests/api/users/users-verification.ts @@ -4,7 +4,7 @@ import * as chai from 'chai' import 'mocha' import { registerUser, flushTests, getUserInformation, getMyUserInformation, killallServers, - userLogin, login, flushAndRunServer, ServerInfo, verifyEmail, updateCustomSubConfig, wait + userLogin, login, flushAndRunServer, ServerInfo, verifyEmail, updateCustomSubConfig, wait, cleanupTests } from '../../../../shared/extra-utils' import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login' import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email' @@ -120,8 +120,9 @@ describe('Test users account verification', function () { await userLogin(server, user2) }) - after(function () { + after(async function () { MockSmtpServer.Instance.kill() - killallServers([ server ]) + + await cleanupTests([ server ]) }) }) diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index 8efff12ad4c9754f7221c17cef227851cdf8cb22..e7291740ba596e117bb52b68c0859cad0a24b6f3 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts @@ -5,9 +5,10 @@ import 'mocha' import { User, UserRole } from '../../../../shared/index' import { blockUser, + cleanupTests, createUser, deleteMe, - flushTests, + flushAndRunServer, getAccountRatings, getBlacklistedVideosList, getMyUserInformation, @@ -17,14 +18,12 @@ import { getUsersList, getUsersListPaginationAndSort, getVideosList, - killallServers, login, makePutBodyRequest, rateVideo, registerUser, removeUser, removeVideo, - flushAndRunServer, ServerInfo, testImage, unblockUser, @@ -677,7 +676,7 @@ describe('Test users', function () { }) }) - after(function () { - killallServers([ server ]) + after(async function () { + await cleanupTests([ server ]) }) }) diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts index 50b231555e1419fb92fef92009bba7396fadb56a..68c1e9a8de3e531345f68d3f69c95cfb9548c0fa 100644 --- a/server/tests/api/videos/multiple-servers.ts +++ b/server/tests/api/videos/multiple-servers.ts @@ -9,7 +9,7 @@ import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/ import { addVideoChannel, checkTmpIsEmpty, - checkVideoFilesWereRemoved, + checkVideoFilesWereRemoved, cleanupTests, completeVideoCheck, createUser, dateIsValid, @@ -1029,7 +1029,7 @@ describe('Test multiple servers', function () { }) }) - after(function () { - killallServers(servers) + after(async function () { + await cleanupTests(servers) }) }) diff --git a/server/tests/api/videos/services.ts b/server/tests/api/videos/services.ts index 1397347d1ba34cff04633393e8c48094f21e44f2..e9ad947b2dc3bd34270c33937bcb788893908246 100644 --- a/server/tests/api/videos/services.ts +++ b/server/tests/api/videos/services.ts @@ -2,16 +2,8 @@ import * as chai from 'chai' import 'mocha' -import { - flushTests, - getOEmbed, - getVideosList, - killallServers, - ServerInfo, - setAccessTokensToServers, - uploadVideo -} from '../../../../shared/extra-utils/index' -import { flushAndRunServer } from '../../../../shared/extra-utils/server/servers' +import { getOEmbed, getVideosList, ServerInfo, setAccessTokensToServers, uploadVideo } from '../../../../shared/extra-utils/index' +import { cleanupTests, flushAndRunServer } from '../../../../shared/extra-utils/server/servers' const expect = chai.expect @@ -74,7 +66,7 @@ describe('Test services', function () { expect(res.body).to.not.have.property('thumbnail_height') }) - after(function () { - killallServers([ server ]) + after(async function () { + await cleanupTests([ server ]) }) }) diff --git a/server/tests/api/videos/single-server.ts b/server/tests/api/videos/single-server.ts index db2a3779fdc03f93796e0f1817debed1735f7189..1f366b642f07a3e1d9858f0d3ecd08ea6d54ba5b 100644 --- a/server/tests/api/videos/single-server.ts +++ b/server/tests/api/videos/single-server.ts @@ -6,8 +6,9 @@ import 'mocha' import { VideoPrivacy } from '../../../../shared/models/videos' import { checkVideoFilesWereRemoved, + cleanupTests, completeVideoCheck, - flushTests, + flushAndRunServer, getVideo, getVideoCategories, getVideoLanguages, @@ -17,10 +18,8 @@ import { getVideosListPagination, getVideosListSort, getVideosWithFilters, - killallServers, rateVideo, removeVideo, - flushAndRunServer, ServerInfo, setAccessTokensToServers, testImage, @@ -424,7 +423,7 @@ describe('Test a single server', function () { expect(video.dislikes).to.equal(1) }) - after(function () { - killallServers([ server ]) + after(async function () { + await cleanupTests([ server ]) }) }) diff --git a/server/tests/api/videos/video-abuse.ts b/server/tests/api/videos/video-abuse.ts index 06bb31348fd9fdde1d77547066318b5e31571477..7318497d59f352c47d141044b4ee35689c16656c 100644 --- a/server/tests/api/videos/video-abuse.ts +++ b/server/tests/api/videos/video-abuse.ts @@ -4,6 +4,7 @@ import * as chai from 'chai' import 'mocha' import { VideoAbuse, VideoAbuseState } from '../../../../shared/models/videos' import { + cleanupTests, deleteVideoAbuse, flushAndRunMultipleServers, getVideoAbusesList, @@ -172,7 +173,7 @@ describe('Test video abuses', function () { expect(res.body.data.length).to.equal(0) }) - after(function () { - killallServers(servers) + after(async function () { + await cleanupTests(servers) }) }) diff --git a/server/tests/api/videos/video-blacklist.ts b/server/tests/api/videos/video-blacklist.ts index cb15d1a52a7e0f1d3f0ed941bca98a5ed2b1d9d1..e907bbdc0dbffd4dc69f12d5646ac698fbaa3042 100644 --- a/server/tests/api/videos/video-blacklist.ts +++ b/server/tests/api/videos/video-blacklist.ts @@ -4,7 +4,7 @@ import * as chai from 'chai' import { orderBy } from 'lodash' import 'mocha' import { - addVideoToBlacklist, + addVideoToBlacklist, cleanupTests, createUser, flushAndRunMultipleServers, getBlacklistedVideosList, @@ -425,7 +425,7 @@ describe('Test video blacklist', function () { }) }) - after(function () { - killallServers(servers) + after(async function () { + await cleanupTests(servers) }) }) diff --git a/server/tests/api/videos/video-captions.ts b/server/tests/api/videos/video-captions.ts index c6f59762ac669a54a1c5d799bf87cffbf200c2ae..5e13f59490b6db178e516c6f836919213621ebdc 100644 --- a/server/tests/api/videos/video-captions.ts +++ b/server/tests/api/videos/video-captions.ts @@ -3,7 +3,7 @@ import * as chai from 'chai' import 'mocha' import { - checkVideoFilesWereRemoved, + checkVideoFilesWereRemoved, cleanupTests, doubleFollow, flushAndRunMultipleServers, removeVideo, @@ -195,7 +195,7 @@ describe('Test video captions', function () { await checkVideoFilesWereRemoved(videoUUID, 1) }) - after(function () { - killallServers(servers) + after(async function () { + await cleanupTests(servers) }) }) diff --git a/server/tests/api/videos/video-change-ownership.ts b/server/tests/api/videos/video-change-ownership.ts index db12206779bce30890ed3e9d5187f0f237ca52d6..1c0327d4089043edd680b26777c3673cc0e4e836 100644 --- a/server/tests/api/videos/video-change-ownership.ts +++ b/server/tests/api/videos/video-change-ownership.ts @@ -4,7 +4,7 @@ import * as chai from 'chai' import 'mocha' import { acceptChangeOwnership, - changeVideoOwnership, + changeVideoOwnership, cleanupTests, createUser, doubleFollow, flushAndRunMultipleServers, @@ -297,7 +297,7 @@ describe('Test video change ownership - quota too small', function () { await acceptChangeOwnership(server.url, secondUserAccessToken, lastRequestChangeOwnershipId, channelId, 403) }) - after(function () { - killallServers([server]) + after(async function () { + await cleanupTests([ server ]) }) }) diff --git a/server/tests/api/videos/video-channels.ts b/server/tests/api/videos/video-channels.ts index 60b84e443783f0f7697879e419ea53333a38c32a..345e96f438b90cefab4c1bc6202e88e445a29091 100644 --- a/server/tests/api/videos/video-channels.ts +++ b/server/tests/api/videos/video-channels.ts @@ -4,6 +4,7 @@ import * as chai from 'chai' import 'mocha' import { User, Video } from '../../../../shared/index' import { + cleanupTests, createUser, doubleFollow, flushAndRunMultipleServers, @@ -277,7 +278,7 @@ describe('Test video channels', function () { } }) - after(function () { - killallServers(servers) + after(async function () { + await cleanupTests(servers) }) }) diff --git a/server/tests/api/videos/video-comments.ts b/server/tests/api/videos/video-comments.ts index 50224ee473b1ab6216b36caa368e1df8c6d580f8..22fd8c0585c6a8ea6685ec0f5b6ae5b7e38cf641 100644 --- a/server/tests/api/videos/video-comments.ts +++ b/server/tests/api/videos/video-comments.ts @@ -3,11 +3,9 @@ import * as chai from 'chai' import 'mocha' import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model' -import { testImage } from '../../../../shared/extra-utils' +import { cleanupTests, testImage } from '../../../../shared/extra-utils' import { dateIsValid, - flushTests, - killallServers, flushAndRunServer, ServerInfo, setAccessTokensToServers, @@ -199,7 +197,7 @@ describe('Test video comments', function () { expect(res.body.data[1].totalReplies).to.equal(0) }) - after(function () { - killallServers([ server ]) + after(async function () { + await cleanupTests([ server ]) }) }) diff --git a/server/tests/api/videos/video-description.ts b/server/tests/api/videos/video-description.ts index 333d539f4605af9db5b19893404d2d47721e22af..db4d278bf15adcafcbfff0fac7f06f956274ce7e 100644 --- a/server/tests/api/videos/video-description.ts +++ b/server/tests/api/videos/video-description.ts @@ -3,6 +3,7 @@ import * as chai from 'chai' import 'mocha' import { + cleanupTests, flushAndRunMultipleServers, getVideo, getVideoDescription, @@ -99,7 +100,7 @@ describe('Test video description', function () { } }) - after(function () { - killallServers(servers) + after(async function () { + await cleanupTests(servers) }) }) diff --git a/server/tests/api/videos/video-hls.ts b/server/tests/api/videos/video-hls.ts index 0ac84a6561593e334fdf62d59dda292128a9d41d..22031c18bf0f61e84a457d2e0ee2c442298c431c 100644 --- a/server/tests/api/videos/video-hls.ts +++ b/server/tests/api/videos/video-hls.ts @@ -5,7 +5,7 @@ import 'mocha' import { checkDirectoryIsEmpty, checkSegmentHash, - checkTmpIsEmpty, + checkTmpIsEmpty, cleanupTests, doubleFollow, flushAndRunMultipleServers, flushTests, @@ -128,7 +128,7 @@ describe('Test HLS videos', function () { } }) - after(function () { - killallServers(servers) + after(async function () { + await cleanupTests(servers) }) }) diff --git a/server/tests/api/videos/video-imports.ts b/server/tests/api/videos/video-imports.ts index 49a28e207ca2d2083fac71be623590fb0c0e4a5c..1233ed6eb9ab07588407e01580ec9bcd6b90067c 100644 --- a/server/tests/api/videos/video-imports.ts +++ b/server/tests/api/videos/video-imports.ts @@ -4,6 +4,7 @@ import * as chai from 'chai' import 'mocha' import { VideoDetails, VideoImport, VideoPrivacy } from '../../../../shared/models/videos' import { + cleanupTests, doubleFollow, flushAndRunMultipleServers, getMyUserInformation, @@ -241,7 +242,7 @@ describe('Test video imports', function () { } }) - after(function () { - killallServers(servers) + after(async function () { + await cleanupTests(servers) }) }) diff --git a/server/tests/api/videos/video-nsfw.ts b/server/tests/api/videos/video-nsfw.ts index 811705212b360f7878ee50b3bb3f161c2a807ce4..ad6a4b43f3e7eeaf578135c218d39ed08fc90102 100644 --- a/server/tests/api/videos/video-nsfw.ts +++ b/server/tests/api/videos/video-nsfw.ts @@ -2,25 +2,18 @@ import * as chai from 'chai' import 'mocha' -import { - flushTests, - getVideosList, - killallServers, - ServerInfo, - setAccessTokensToServers, - uploadVideo -} from '../../../../shared/extra-utils/index' +import { cleanupTests, getVideosList, ServerInfo, setAccessTokensToServers, uploadVideo } from '../../../../shared/extra-utils/index' import { userLogin } from '../../../../shared/extra-utils/users/login' import { createUser } from '../../../../shared/extra-utils/users/users' import { getMyVideos } from '../../../../shared/extra-utils/videos/videos' import { + flushAndRunServer, getAccountVideos, getConfig, getCustomConfig, getMyUserInformation, getVideoChannelVideos, getVideosListWithToken, - flushAndRunServer, searchVideo, searchVideoWithToken, updateCustomConfig, @@ -241,7 +234,7 @@ describe('Test video NSFW policy', function () { }) }) - after(function () { - killallServers([ server ]) + after(async function () { + await cleanupTests([ server ]) }) }) diff --git a/server/tests/api/videos/video-playlists.ts b/server/tests/api/videos/video-playlists.ts index ea349f09beb583a2c8f8a5364f2d197cfca4b6a4..9285682999beac7c0d19e50f029a9f8311adf434 100644 --- a/server/tests/api/videos/video-playlists.ts +++ b/server/tests/api/videos/video-playlists.ts @@ -5,7 +5,7 @@ import 'mocha' import { addVideoChannel, addVideoInPlaylist, - checkPlaylistFilesWereRemoved, + checkPlaylistFilesWereRemoved, cleanupTests, createUser, createVideoPlaylist, deleteVideoChannel, @@ -860,7 +860,7 @@ describe('Test video playlists', function () { } }) - after(function () { - killallServers(servers) + after(async function () { + await cleanupTests(servers) }) }) diff --git a/server/tests/api/videos/video-privacy.ts b/server/tests/api/videos/video-privacy.ts index a823993b2d67761b0a17af5af591c3ae26bcd8f8..ef1cf0f071ed23f7544f32013aecc1c2d27ddf71 100644 --- a/server/tests/api/videos/video-privacy.ts +++ b/server/tests/api/videos/video-privacy.ts @@ -4,6 +4,7 @@ import * as chai from 'chai' import 'mocha' import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum' import { + cleanupTests, flushAndRunMultipleServers, getVideosList, killallServers, @@ -152,7 +153,7 @@ describe('Test video privacy', function () { } }) - after(function () { - killallServers(servers) + after(async function () { + await cleanupTests(servers) }) }) diff --git a/server/tests/api/videos/video-schedule-update.ts b/server/tests/api/videos/video-schedule-update.ts index d7301a1377ed88bb8cf910d1df60d43faba8b3bf..64f657780b979f4497ec9de2b4d39696d6f0e001 100644 --- a/server/tests/api/videos/video-schedule-update.ts +++ b/server/tests/api/videos/video-schedule-update.ts @@ -4,6 +4,7 @@ import * as chai from 'chai' import 'mocha' import { VideoPrivacy } from '../../../../shared/models/videos' import { + cleanupTests, doubleFollow, flushAndRunMultipleServers, getMyVideos, @@ -165,7 +166,7 @@ describe('Test video update scheduler', function () { } }) - after(function () { - killallServers(servers) + after(async function () { + await cleanupTests(servers) }) }) diff --git a/server/tests/api/videos/video-transcoder.ts b/server/tests/api/videos/video-transcoder.ts index 92888f1376fc7606ad149bf90f442a21107a6962..3cd43e99bdf4dc6bd23ab21ba30fb9478df87068 100644 --- a/server/tests/api/videos/video-transcoder.ts +++ b/server/tests/api/videos/video-transcoder.ts @@ -6,7 +6,7 @@ import { omit } from 'lodash' import { getMaxBitrate, VideoDetails, VideoResolution, VideoState } from '../../../../shared/models/videos' import { audio, getVideoFileBitrate, getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffmpeg-utils' import { - buildAbsoluteFixturePath, + buildAbsoluteFixturePath, cleanupTests, doubleFollow, flushAndRunMultipleServers, generateHighBitrateVideo, @@ -349,7 +349,7 @@ describe('Test video transcoding', function () { } }) - after(function () { - killallServers(servers) + after(async function () { + await cleanupTests(servers) }) }) diff --git a/server/tests/api/videos/videos-filter.ts b/server/tests/api/videos/videos-filter.ts index 179610595c40a832355ca52f449f003b30e6ac28..e1e65260fe1868198f795a9f9dcc419e65b9b645 100644 --- a/server/tests/api/videos/videos-filter.ts +++ b/server/tests/api/videos/videos-filter.ts @@ -3,6 +3,7 @@ import * as chai from 'chai' import 'mocha' import { + cleanupTests, createUser, doubleFollow, flushAndRunMultipleServers, @@ -119,7 +120,7 @@ describe('Test videos filter validator', function () { }) }) - after(function () { - killallServers(servers) + after(async function () { + await cleanupTests(servers) }) }) diff --git a/server/tests/api/videos/videos-history.ts b/server/tests/api/videos/videos-history.ts index 2a904c6592530c622f531741f5fbaa839f6db5be..c7e55c1ab7625a2dbe043e9a0f4e281e30716b7a 100644 --- a/server/tests/api/videos/videos-history.ts +++ b/server/tests/api/videos/videos-history.ts @@ -3,12 +3,13 @@ import * as chai from 'chai' import 'mocha' import { + cleanupTests, createUser, - flushTests, + flushAndRunServer, getVideosListWithToken, getVideoWithToken, - killallServers, reRunServer, - flushAndRunServer, + killallServers, + reRunServer, searchVideoWithToken, ServerInfo, setAccessTokensToServers, @@ -220,7 +221,7 @@ describe('Test videos history', function () { expect(res.body.total).to.equal(0) }) - after(function () { - killallServers([ server ]) + after(async function () { + await cleanupTests([ server ]) }) }) diff --git a/server/tests/api/videos/videos-overview.ts b/server/tests/api/videos/videos-overview.ts index c63725d71dbcdb8ffdd7cd1fecce43834dc6f251..975a5c87a5ab4b2e8256daaeb48831f031cc93e4 100644 --- a/server/tests/api/videos/videos-overview.ts +++ b/server/tests/api/videos/videos-overview.ts @@ -2,7 +2,7 @@ import * as chai from 'chai' import 'mocha' -import { flushAndRunServer, killallServers, ServerInfo, setAccessTokensToServers, uploadVideo } from '../../../../shared/extra-utils' +import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers, uploadVideo } from '../../../../shared/extra-utils' import { getVideosOverview } from '../../../../shared/extra-utils/overviews/overviews' import { VideosOverview } from '../../../../shared/models/overviews' @@ -87,7 +87,7 @@ describe('Test a videos overview', function () { expect(overview.channels[0].channel.name).to.equal('root_channel') }) - after(function () { - killallServers([ server ]) + after(async function () { + await cleanupTests([ server ]) }) }) diff --git a/server/tests/api/videos/videos-views-cleaner.ts b/server/tests/api/videos/videos-views-cleaner.ts index 80cecdd236caa928b5f5329ad218f3833feb735e..c21d46d569f58d1701b4868492d36f2267c25704 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 + uploadVideo, uploadVideoAndGetId, viewVideo, wait, countVideoViewsOf, doubleFollow, waitJobs, cleanupTests } from '../../../../shared/extra-utils' import { getVideosOverview } from '../../../../shared/extra-utils/overviews/overviews' import { VideosOverview } from '../../../../shared/models/overviews' @@ -100,7 +100,7 @@ describe('Test video views cleaner', function () { } }) - after(function () { - killallServers(servers) + after(async function () { + await cleanupTests(servers) }) }) diff --git a/server/tests/cli/create-import-video-file-job.ts b/server/tests/cli/create-import-video-file-job.ts index 191d4b4609bde03ecf519446b9dc1362b6fc7760..0d378c1aa16d2688ada8658f015cf8074c5bd1fc 100644 --- a/server/tests/cli/create-import-video-file-job.ts +++ b/server/tests/cli/create-import-video-file-job.ts @@ -4,6 +4,7 @@ import 'mocha' import * as chai from 'chai' import { VideoDetails, VideoFile } from '../../../shared/models/videos' import { + cleanupTests, doubleFollow, execCLI, flushAndRunMultipleServers, @@ -130,7 +131,7 @@ describe('Test create import video jobs', function () { } }) - after(function () { - killallServers(servers) + after(async function () { + await cleanupTests(servers) }) }) diff --git a/server/tests/cli/create-transcoding-job.ts b/server/tests/cli/create-transcoding-job.ts index 61c310bc3fefb4b91fa565723af27fc03622b711..1c0e10066143ca270bf3430e6e8709dc0016690a 100644 --- a/server/tests/cli/create-transcoding-job.ts +++ b/server/tests/cli/create-transcoding-job.ts @@ -4,6 +4,7 @@ import 'mocha' import * as chai from 'chai' import { VideoDetails } from '../../../shared/models/videos' import { + cleanupTests, doubleFollow, execCLI, flushAndRunMultipleServers, @@ -124,7 +125,7 @@ describe('Test create transcoding jobs', function () { } }) - after(function () { - killallServers(servers) + after(async function () { + await cleanupTests(servers) }) }) diff --git a/server/tests/cli/optimize-old-videos.ts b/server/tests/cli/optimize-old-videos.ts index 14625f8c0b97f9acbac9f7abc916dfad163c734f..5e12c008912e779067d4f215dc7b6011e5e9d52a 100644 --- a/server/tests/cli/optimize-old-videos.ts +++ b/server/tests/cli/optimize-old-videos.ts @@ -4,6 +4,7 @@ import 'mocha' import * as chai from 'chai' import { getMaxBitrate, Video, VideoDetails, VideoResolution } from '../../../shared/models/videos' import { + cleanupTests, doubleFollow, execCLI, flushAndRunMultipleServers, @@ -112,7 +113,7 @@ describe('Test optimize old videos', function () { } }) - after(function () { - killallServers(servers) + after(async function () { + await cleanupTests(servers) }) }) diff --git a/server/tests/cli/peertube.ts b/server/tests/cli/peertube.ts index 0c11945e0dbba49b6c5d4cc7a9c1e62af87e4414..80bbc98d57382a0bd1b58a48a4ccc41d88663da1 100644 --- a/server/tests/cli/peertube.ts +++ b/server/tests/cli/peertube.ts @@ -10,7 +10,7 @@ import { killallServers, flushAndRunServer, ServerInfo, - setAccessTokensToServers + setAccessTokensToServers, cleanupTests } from '../../../shared/extra-utils' describe('Test CLI wrapper', function () { @@ -46,6 +46,6 @@ describe('Test CLI wrapper', function () { await execCLI(cmd + ` auth del ${server.url}`) - killallServers([ server ]) + await cleanupTests([ server ]) }) }) diff --git a/server/tests/cli/reset-password.ts b/server/tests/cli/reset-password.ts index 1d64238141df8636d8b9dc1cdc8c7ee6249fc91b..6abb6738f6dbb6e9e2024f17d9b241eb215e89fe 100644 --- a/server/tests/cli/reset-password.ts +++ b/server/tests/cli/reset-password.ts @@ -1,13 +1,12 @@ import 'mocha' import { + cleanupTests, createUser, execCLI, - flushTests, + flushAndRunServer, getEnvCli, - killallServers, login, - flushAndRunServer, ServerInfo, setAccessTokensToServers } from '../../../shared/extra-utils' @@ -32,7 +31,7 @@ describe('Test reset password scripts', function () { await login(server.url, server.client, { username: 'user_1', password: 'coucou' }, 200) }) - after(function () { - killallServers([ server ]) + after(async function () { + await cleanupTests([ server ]) }) }) diff --git a/server/tests/cli/update-host.ts b/server/tests/cli/update-host.ts index dd594779bb2c75fb5c9dea6f1743ef5ce08156a2..55c43b32fca83fdd50331f41b46854e8369842c9 100644 --- a/server/tests/cli/update-host.ts +++ b/server/tests/cli/update-host.ts @@ -7,17 +7,17 @@ import { waitJobs } from '../../../shared/extra-utils/server/jobs' import { addVideoCommentThread } from '../../../shared/extra-utils/videos/video-comments' import { addVideoChannel, + cleanupTests, createUser, execCLI, - flushTests, + flushAndRunServer, getEnvCli, getVideo, getVideoChannelsList, getVideosList, killallServers, makeActivityPubGetRequest, - parseTorrentVideo, - flushAndRunServer, + parseTorrentVideo, reRunServer, ServerInfo, setAccessTokensToServers, uploadVideo @@ -70,7 +70,7 @@ describe('Test update host scripts', function () { killallServers([ server ]) // Run server with standard configuration - server = await flushAndRunServer(2) + await reRunServer(server) const env = getEnvCli(server) await execCLI(`${env} npm run update-host`) @@ -146,7 +146,7 @@ describe('Test update host scripts', function () { } }) - after(function () { - killallServers([ server ]) + after(async function () { + await cleanupTests([ server ]) }) }) diff --git a/server/tests/client.ts b/server/tests/client.ts index cdf0ce2ced59e11b18caa903d72a63229970a5bc..778dcd08e549f59176ca9c6efa7a516a0bc390eb 100644 --- a/server/tests/client.ts +++ b/server/tests/client.ts @@ -4,12 +4,11 @@ import 'mocha' import * as chai from 'chai' import * as request from 'supertest' import { - flushTests, + cleanupTests, + flushAndRunServer, getCustomConfig, getVideosList, - killallServers, makeHTMLRequest, - flushAndRunServer, ServerInfo, serverLogin, updateCustomConfig, @@ -145,7 +144,7 @@ describe('Test a client controllers', function () { checkIndexTags(res.text, 'PeerTube updated', 'my short description', 'body { background-color: red; }') }) - after(function () { - killallServers([ server ]) + after(async function () { + await cleanupTests([ server ]) }) }) diff --git a/server/tests/feeds/feeds.ts b/server/tests/feeds/feeds.ts index fc6543474eb3aa9a0270d42eff46b4c96c6a3694..0dcdf09cf1bdedcd986b711871fd3545389b0920 100644 --- a/server/tests/feeds/feeds.ts +++ b/server/tests/feeds/feeds.ts @@ -3,6 +3,7 @@ import * as chai from 'chai' import 'mocha' import { + cleanupTests, createUser, doubleFollow, flushAndRunMultipleServers, @@ -207,7 +208,7 @@ describe('Test syndication feeds', () => { }) }) - after(function () { - killallServers(servers) + after(async function () { + await cleanupTests(servers) }) }) diff --git a/server/tests/misc-endpoints.ts b/server/tests/misc-endpoints.ts index d5c7d9dd40a8fc654e7d64828a9ec184406200ba..ed406e1bc6b9f4b727a740268e083365e168b54c 100644 --- a/server/tests/misc-endpoints.ts +++ b/server/tests/misc-endpoints.ts @@ -4,11 +4,10 @@ import 'mocha' import * as chai from 'chai' import { addVideoChannel, + cleanupTests, createUser, - flushTests, - killallServers, - makeGetRequest, flushAndRunServer, + makeGetRequest, ServerInfo, setAccessTokensToServers, uploadVideo @@ -171,7 +170,7 @@ describe('Test misc endpoints', function () { }) }) - after(function () { - killallServers([ server ]) + after(async function () { + await cleanupTests([ server ]) }) }) diff --git a/shared/core-utils/miscs/miscs.ts b/shared/core-utils/miscs/miscs.ts new file mode 100644 index 0000000000000000000000000000000000000000..c668e44c14908c58bc3c32b71c23180f4e95cd63 --- /dev/null +++ b/shared/core-utils/miscs/miscs.ts @@ -0,0 +1,7 @@ +function randomInt (low: number, high: number) { + return Math.floor(Math.random() * (high - low) + low) +} + +export { + randomInt +} diff --git a/shared/extra-utils/miscs/email-child-process.js b/shared/extra-utils/miscs/email-child-process.js index 40ae37d70bfca1561c77c6a0873daeff314f612f..088a5a08c034440b2b88c724b7ce9b2b8e44576d 100644 --- a/shared/extra-utils/miscs/email-child-process.js +++ b/shared/extra-utils/miscs/email-child-process.js @@ -6,7 +6,7 @@ process.on('message', (msg) => { if (msg.start) { const maildev = new MailDev({ ip: '127.0.0.1', - smtp: 1025, + smtp: msg.port, disableWeb: true, silent: true }) diff --git a/shared/extra-utils/miscs/email.ts b/shared/extra-utils/miscs/email.ts index f9f1bd95b05736543b21e096cdca528b8dbd631a..b2a1093da5e07509b13b4d8d53026252a56c3642 100644 --- a/shared/extra-utils/miscs/email.ts +++ b/shared/extra-utils/miscs/email.ts @@ -1,4 +1,6 @@ -import { fork, ChildProcess } from 'child_process' +import { ChildProcess, fork } from 'child_process' +import { randomInt } from '../../core-utils/miscs/miscs' +import { parallelTests } from '../server/servers' class MockSmtpServer { @@ -20,7 +22,9 @@ class MockSmtpServer { } collectEmails (emailsCollection: object[]) { - return new Promise((res, rej) => { + return new Promise<number>((res, rej) => { + const port = parallelTests() ? randomInt(1000, 2000) : 1025 + if (this.started) { this.emails = emailsCollection return res() @@ -28,7 +32,7 @@ class MockSmtpServer { // ensure maildev isn't started until // unexpected exit can be reported to test runner - this.emailChildProcess.send({ start: true }) + this.emailChildProcess.send({ start: true, port }) this.emailChildProcess.on('exit', () => { return rej(new Error('maildev exited unexpectedly, confirm port not in use')) }) @@ -38,7 +42,7 @@ class MockSmtpServer { } this.started = true this.emails = emailsCollection - return res() + return res(port) }) }) } diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index 3ef4b974633a0f7a4fbe2c2c95175d6c2a43a249..ed41bfa48161f6c5dad06a35b85f78d8fef14bb4 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts @@ -3,10 +3,11 @@ import { ChildProcess, exec, fork } from 'child_process' import { join } from 'path' import { root, wait } from '../miscs/miscs' -import { readdir, readFile } from 'fs-extra' +import { copy, readdir, readFile, remove } from 'fs-extra' import { existsSync } from 'fs' import { expect } from 'chai' import { VideoChannel } from '../../models/videos' +import { randomInt } from '../../core-utils/miscs/miscs' interface ServerInfo { app: ChildProcess, @@ -29,6 +30,8 @@ interface ServerInfo { email?: string } + customConfigFile?: string + accessToken?: string videoChannel?: VideoChannel @@ -49,6 +52,10 @@ interface ServerInfo { videos?: { id: number, uuid: string }[] } +function parallelTests () { + return process.env.MOCHA_PARALLEL === 'true' +} + function flushAndRunMultipleServers (totalServers: number, configOverride?: Object) { let apps = [] let i = 0 @@ -84,23 +91,23 @@ function randomServer () { const low = 10 const high = 10000 - return Math.floor(Math.random() * (high - low) + low) + return randomInt(low, high) } async function flushAndRunServer (serverNumber: number, configOverride?: Object, args = []) { - const parallel = process.env.MOCHA_PARALLEL === 'true' + const parallel = parallelTests() const internalServerNumber = parallel ? randomServer() : serverNumber const port = 9000 + internalServerNumber - await flushTests(serverNumber) + await flushTests(internalServerNumber) const server: ServerInfo = { app: null, port, internalServerNumber, parallel, - serverNumber: internalServerNumber, + serverNumber, url: `http://localhost:${port}`, host: `localhost:${port}`, client: { @@ -116,7 +123,7 @@ async function flushAndRunServer (serverNumber: number, configOverride?: Object, return runServer(server, configOverride, args) } -function runServer (server: ServerInfo, configOverrideArg?: any, args = []) { +async function runServer (server: ServerInfo, configOverrideArg?: any, args = []) { // These actions are async so we need to be sure that they have both been done const serverRunString = { 'Server listening': false @@ -131,15 +138,19 @@ function runServer (server: ServerInfo, configOverrideArg?: any, args = []) { user_password: 'User password: (.+)' } - // Share the environment - const env = Object.create(process.env) - env['NODE_ENV'] = 'test' - env['NODE_APP_INSTANCE'] = server.serverNumber.toString() + if (server.internalServerNumber !== server.serverNumber) { + const basePath = join(root(), 'config') + + const tmpConfigFile = join(basePath, `test-${server.internalServerNumber}.yaml`) + await copy(join(basePath, `test-${server.serverNumber}.yaml`), tmpConfigFile) + + server.customConfigFile = tmpConfigFile + } - let configOverride: any = {} + const configOverride: any = {} if (server.parallel) { - configOverride = { + Object.assign(configOverride, { listen: { port: server.port }, @@ -165,18 +176,22 @@ function runServer (server: ServerInfo, configOverrideArg?: any, args = []) { admin: { email: `admin${server.internalServerNumber}@example.com` } - } + }) } if (configOverrideArg !== undefined) { Object.assign(configOverride, configOverrideArg) } + // Share the environment + const env = Object.create(process.env) + env['NODE_ENV'] = 'test' + env['NODE_APP_INSTANCE'] = server.internalServerNumber.toString() env['NODE_CONFIG'] = JSON.stringify(configOverride) const options = { silent: true, - env: env, + env, detached: true } @@ -244,7 +259,10 @@ async function checkDirectoryIsEmpty (server: ServerInfo, directory: string) { function killallServers (servers: ServerInfo[]) { for (const server of servers) { + if (!server.app) continue + process.kill(-server.app.pid) + server.app = null } } @@ -256,6 +274,10 @@ function cleanupTests (servers: ServerInfo[]) { if (server.parallel) { p.push(flushTests(server.internalServerNumber)) } + + if (server.customConfigFile) { + p.push(remove(server.customConfigFile)) + } } return Promise.all(p) @@ -280,6 +302,7 @@ export { checkDirectoryIsEmpty, checkTmpIsEmpty, ServerInfo, + parallelTests, cleanupTests, flushAndRunMultipleServers, flushTests,