diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index 8dbc1b060..65f89ff7f 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts @@ -449,14 +449,21 @@ const FEEDS = { // Special constants for a test instance if (isTestInstance() === true) { ACTOR_FOLLOW_SCORE.BASE = 20 + REMOTE_SCHEME.HTTP = 'http' REMOTE_SCHEME.WS = 'ws' + STATIC_MAX_AGE = '0' + ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE = 2 ACTIVITY_PUB.ACTOR_REFRESH_INTERVAL = 10 * 1000 // 10 seconds + CONSTRAINTS_FIELDS.ACTORS.AVATAR.FILE_SIZE.max = 100 * 1024 // 100KB + SCHEDULER_INTERVAL = 10000 VIDEO_VIEW_LIFETIME = 1000 // 1 second + + JOB_ATTEMPTS['email'] = 1 } updateWebserverConfig() diff --git a/server/lib/activitypub/process/process-update.ts b/server/lib/activitypub/process/process-update.ts index 77de8c155..1ebda46d3 100644 --- a/server/lib/activitypub/process/process-update.ts +++ b/server/lib/activitypub/process/process-update.ts @@ -1,5 +1,5 @@ import * as Bluebird from 'bluebird' -import { ActivityUpdate } from '../../../../shared/models/activitypub' +import { ActivityUpdate, VideoTorrentObject } from '../../../../shared/models/activitypub' import { ActivityPubActor } from '../../../../shared/models/activitypub/activitypub-actor' import { retryTransactionWrapper } from '../../../helpers/database-utils' import { logger } from '../../../helpers/logger' @@ -12,13 +12,13 @@ import { VideoChannelModel } from '../../../models/video/video-channel' import { VideoFileModel } from '../../../models/video/video-file' import { fetchAvatarIfExists, getOrCreateActorAndServerAndModel, updateActorAvatarInstance, updateActorInstance } from '../actor' import { - fetchRemoteVideo, generateThumbnailFromUrl, getOrCreateAccountAndVideoAndChannel, getOrCreateVideoChannel, videoActivityObjectToDBAttributes, videoFileActivityUrlToDBAttributes } from '../videos' +import { sanitizeAndCheckVideoTorrentObject } from '../../../helpers/custom-validators/activitypub/videos' async function processUpdateActivity (activity: ActivityUpdate) { const actor = await getOrCreateActorAndServerAndModel(activity.actor) @@ -30,7 +30,7 @@ async function processUpdateActivity (activity: ActivityUpdate) { return processUpdateActor(actor, activity) } - return + return undefined } // --------------------------------------------------------------------------- @@ -51,10 +51,12 @@ function processUpdateVideo (actor: ActorModel, activity: ActivityUpdate) { } async function updateRemoteVideo (actor: ActorModel, activity: ActivityUpdate) { - const videoUrl = activity.object.id + const videoObject = activity.object as VideoTorrentObject - const videoObject = await fetchRemoteVideo(videoUrl) - if (!videoObject) throw new Error('Cannot fetch remote video with url: ' + videoUrl) + if (sanitizeAndCheckVideoTorrentObject(videoObject) === false) { + logger.debug('Video sent by update is not valid.', { videoObject }) + return undefined + } const res = await getOrCreateAccountAndVideoAndChannel(videoObject.id) diff --git a/server/tests/activitypub.ts b/server/tests/activitypub.ts index 9e29b0fa8..53a04d363 100644 --- a/server/tests/activitypub.ts +++ b/server/tests/activitypub.ts @@ -31,10 +31,5 @@ describe('Test activitypub', function () { after(async function () { killallServers([ server ]) - - // Keep the logs if the test failed - if (this['ok']) { - await flushTests() - } }) }) diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts index f24961b85..4de0d6b10 100644 --- a/server/tests/api/server/config.ts +++ b/server/tests/api/server/config.ts @@ -234,11 +234,6 @@ describe('Test config', function () { }) after(async function () { - process.kill(-server.app.pid) - - // Keep the logs if the test failed - if (this['ok']) { - await flushTests() - } + killallServers([ server ]) }) }) diff --git a/server/tests/api/server/email.ts b/server/tests/api/server/email.ts index 068e820c8..4be013c84 100644 --- a/server/tests/api/server/email.ts +++ b/server/tests/api/server/email.ts @@ -5,6 +5,7 @@ import 'mocha' import { askResetPassword, createUser, reportVideoAbuse, resetPassword, runServer, uploadVideo, userLogin, wait } from '../../utils' import { flushTests, killallServers, ServerInfo, setAccessTokensToServers } from '../../utils/index' import { mockSmtpServer } from '../../utils/miscs/email' +import { waitJobs } from '../../utils/server/jobs' const expect = chai.expect @@ -32,8 +33,6 @@ describe('Test emails', function () { } } server = await runServer(1, overrideConfig) - - await wait(5000) await setAccessTokensToServers([ server ]) { @@ -57,7 +56,7 @@ describe('Test emails', function () { await askResetPassword(server.url, 'user_1@example.com') - await wait(3000) + await waitJobs(server) expect(emails).to.have.lengthOf(1) const email = emails[0] @@ -101,7 +100,7 @@ describe('Test emails', function () { const reason = 'my super bad reason' await reportVideoAbuse(server.url, server.accessToken, videoUUID, reason) - await wait(3000) + await waitJobs(server) expect(emails).to.have.lengthOf(2) const email = emails[1] @@ -115,10 +114,5 @@ describe('Test emails', function () { after(async function () { killallServers([ server ]) - - // Keep the logs if the test failed - if (this['ok']) { - await flushTests() - } }) }) diff --git a/server/tests/api/server/follows.ts b/server/tests/api/server/follows.ts index 9d619a7de..ce42df0a6 100644 --- a/server/tests/api/server/follows.ts +++ b/server/tests/api/server/follows.ts @@ -5,10 +5,13 @@ import 'mocha' import { Video, VideoPrivacy } from '../../../../shared/models/videos' import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model' import { completeVideoCheck } from '../../utils' - import { - flushAndRunMultipleServers, flushTests, getVideosList, killallServers, ServerInfo, setAccessTokensToServers, uploadVideo, - wait + flushAndRunMultipleServers, + getVideosList, + killallServers, + ServerInfo, + setAccessTokensToServers, + uploadVideo } from '../../utils/index' import { dateIsValid } from '../../utils/miscs/miscs' import { follow, getFollowersListPaginationAndSort, getFollowingListPaginationAndSort, unfollow } from '../../utils/server/follows' @@ -16,10 +19,13 @@ import { expectAccountFollows } from '../../utils/users/accounts' import { userLogin } from '../../utils/users/login' import { createUser } from '../../utils/users/users' import { - addVideoCommentReply, addVideoCommentThread, getVideoCommentThreads, + addVideoCommentReply, + addVideoCommentThread, + getVideoCommentThreads, getVideoThreadComments } from '../../utils/videos/video-comments' import { rateVideo } from '../../utils/videos/videos' +import { waitJobs } from '../../utils/server/jobs' const expect = chai.expect @@ -62,7 +68,7 @@ describe('Test follows', function () { await follow(servers[0].url, [ servers[1].url, servers[2].url ], servers[0].accessToken) - await wait(7000) + await waitJobs(servers) }) it('Should have 2 followings on server 1', async function () { @@ -135,7 +141,7 @@ describe('Test follows', function () { await unfollow(servers[0].url, servers[0].accessToken, servers[2]) - await wait(3000) + await waitJobs(servers) }) it('Should not follow server 3 on server 1 anymore', async function () { @@ -175,7 +181,7 @@ describe('Test follows', function () { await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'server2' }) await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3' }) - await wait(5000) + await waitJobs(servers) let res = await getVideosList(servers[0].url) expect(res.body.total).to.equal(1) @@ -240,12 +246,12 @@ describe('Test follows', function () { } } - await wait(5000) + await waitJobs(servers) // Server 1 follows server 3 await follow(servers[ 0 ].url, [ servers[ 2 ].url ], servers[ 0 ].accessToken) - await wait(7000) + await waitJobs(servers) }) it('Should have the correct follows counts 3', async function () { @@ -352,7 +358,7 @@ describe('Test follows', function () { await unfollow(servers[0].url, servers[0].accessToken, servers[2]) - await wait(3000) + await waitJobs(servers) let res = await getVideosList(servers[ 0 ].url) expect(res.body.total).to.equal(1) @@ -362,10 +368,5 @@ describe('Test follows', function () { after(async function () { killallServers(servers) - - // Keep the logs if the test failed - if (this['ok']) { - await flushTests() - } }) }) diff --git a/server/tests/api/server/handle-down.ts b/server/tests/api/server/handle-down.ts index 889825936..55705caca 100644 --- a/server/tests/api/server/handle-down.ts +++ b/server/tests/api/server/handle-down.ts @@ -12,7 +12,7 @@ import { wait } from '../../utils/index' import { follow, getFollowersListPaginationAndSort } from '../../utils/server/follows' -import { getJobsListPaginationAndSort } from '../../utils/server/jobs' +import { getJobsListPaginationAndSort, waitJobs } from '../../utils/server/jobs' import { addVideoCommentReply, addVideoCommentThread, getVideoCommentThreads, getVideoThreadComments @@ -94,11 +94,11 @@ describe('Test handle downs', function () { await follow(servers[1].url, [ servers[0].url ], servers[1].accessToken) - await wait(5000) + await waitJobs(servers) await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) - await wait(5000) + await waitJobs(servers) for (const server of servers) { const res = await getVideosList(server.url) @@ -118,7 +118,7 @@ describe('Test handle downs', function () { videos.push(resVideo.body.video) } - await wait(2000) + await waitJobs(servers[0]) await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, videoAttributes) @@ -136,7 +136,9 @@ describe('Test handle downs', function () { commentIdServer1 = resComment.body.comment.id } - await wait(10000) + await waitJobs(servers[0]) + // Wait scheduler + await wait(3000) const res = await getFollowersListPaginationAndSort(servers[0].url, 0, 1, 'createdAt') expect(res.body.data).to.be.an('array') @@ -159,7 +161,7 @@ describe('Test handle downs', function () { await follow(servers[1].url, [ servers[0].url ], servers[1].accessToken) - await wait(5000) + await waitJobs(servers) const res = await getFollowersListPaginationAndSort(servers[0].url, 0, 1, 'createdAt') expect(res.body.data).to.be.an('array') @@ -171,7 +173,7 @@ describe('Test handle downs', function () { await viewVideo(servers[0].url, videos[0].uuid) - await wait(5000) + await waitJobs(servers) const res = await getVideosList(servers[1].url) expect(res.body.data).to.be.an('array') @@ -189,7 +191,7 @@ describe('Test handle downs', function () { await addVideoCommentReply(servers[0].url, servers[0].accessToken, videos[1].uuid, commentIdServer1, 'comment 1-3') - await wait(5000) + await waitJobs(servers) const resVideo = await getVideo(servers[1].url, videos[0].uuid) expect(resVideo.body).not.to.be.undefined @@ -230,7 +232,7 @@ describe('Test handle downs', function () { await addVideoCommentReply(servers[1].url, servers[1].accessToken, videos[1].uuid, commentIdServer2, 'comment 1-4') - await wait(5000) + await waitJobs(servers) { const resComment = await getVideoThreadComments(servers[0].url, videos[1].uuid, threadIdServer1) @@ -259,10 +261,5 @@ describe('Test handle downs', function () { after(async function () { killallServers(servers) - - // Keep the logs if the test failed - if (this['ok']) { - await flushTests() - } }) }) diff --git a/server/tests/api/server/jobs.ts b/server/tests/api/server/jobs.ts index 671498769..81e389de6 100644 --- a/server/tests/api/server/jobs.ts +++ b/server/tests/api/server/jobs.ts @@ -4,7 +4,7 @@ import * as chai from 'chai' import 'mocha' import { flushTests, killallServers, ServerInfo, setAccessTokensToServers, wait } from '../../utils/index' import { doubleFollow } from '../../utils/server/follows' -import { getJobsList, getJobsListPaginationAndSort } from '../../utils/server/jobs' +import { getJobsList, getJobsListPaginationAndSort, waitJobs } from '../../utils/server/jobs' import { flushAndRunMultipleServers } from '../../utils/server/servers' import { uploadVideo } from '../../utils/videos/videos' import { dateIsValid } from '../../utils/miscs/miscs' @@ -31,7 +31,7 @@ describe('Test jobs', function () { await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video1' }) await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video2' }) - await wait(15000) + await waitJobs(servers) }) it('Should list jobs', async function () { @@ -55,10 +55,5 @@ describe('Test jobs', function () { after(async function () { killallServers(servers) - - // Keep the logs if the test failed - if (this['ok']) { - await flushTests() - } }) }) diff --git a/server/tests/api/server/reverse-proxy.ts b/server/tests/api/server/reverse-proxy.ts index 4c2655f64..908b4a68c 100644 --- a/server/tests/api/server/reverse-proxy.ts +++ b/server/tests/api/server/reverse-proxy.ts @@ -72,11 +72,6 @@ describe('Test application behind a reverse proxy', function () { }) after(async function () { - process.kill(-server.app.pid) - - // Keep the logs if the test failed - if (this['ok']) { - await flushTests() - } + killallServers([ server ]) }) }) diff --git a/server/tests/api/server/stats.ts b/server/tests/api/server/stats.ts index 71d54c0ab..e75089a14 100644 --- a/server/tests/api/server/stats.ts +++ b/server/tests/api/server/stats.ts @@ -17,6 +17,7 @@ import { import { flushTests, setAccessTokensToServers } from '../../utils/index' import { getStats } from '../../utils/server/stats' import { addVideoCommentThread } from '../../utils/videos/video-comments' +import { waitJobs } from '../../utils/server/jobs' const expect = chai.expect @@ -46,7 +47,7 @@ describe('Test stats', function () { await viewVideo(servers[0].url, videoUUID) await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken) - await wait(5000) + await waitJobs(servers) }) it('Should have the correct stats on instance 1', async function () { @@ -93,10 +94,5 @@ describe('Test stats', function () { after(async function () { killallServers(servers) - - // Keep the logs if the test failed - if (this['ok']) { - await flushTests() - } }) }) diff --git a/server/tests/api/users/users-multiple-servers.ts b/server/tests/api/users/users-multiple-servers.ts index 0e1e6c97d..81489021b 100644 --- a/server/tests/api/users/users-multiple-servers.ts +++ b/server/tests/api/users/users-multiple-servers.ts @@ -20,6 +20,7 @@ import { checkActorFilesWereRemoved, getAccount, getAccountsList } from '../../u import { setAccessTokensToServers } from '../../utils/users/login' import { User } from '../../../../shared/models/users' import { VideoChannel } from '../../../../shared/models/videos' +import { waitJobs } from '../../utils/server/jobs' const expect = chai.expect @@ -76,7 +77,7 @@ describe('Test users with multiple servers', function () { videoUUID = resVideo.body.video.uuid } - await wait(5000) + await waitJobs(servers) }) it('Should be able to update my display name', async function () { @@ -92,7 +93,7 @@ describe('Test users with multiple servers', function () { user = res.body expect(user.account.displayName).to.equal('my super display name') - await wait(5000) + await waitJobs(servers) }) it('Should be able to update my description', async function () { @@ -109,7 +110,7 @@ describe('Test users with multiple servers', function () { expect(user.account.displayName).to.equal('my super display name') expect(user.account.description).to.equal('my super description updated') - await wait(5000) + await waitJobs(servers) }) it('Should be able to update my avatar', async function () { @@ -128,7 +129,7 @@ describe('Test users with multiple servers', function () { await testImage(servers[0].url, 'avatar2-resized', user.account.avatar.path, '.png') - await wait(5000) + await waitJobs(servers) }) it('Should have updated my profile on other servers too', async function () { @@ -178,7 +179,7 @@ describe('Test users with multiple servers', function () { await removeUser(servers[0].url, userId, servers[0].accessToken) - await wait(5000) + await waitJobs(servers) for (const server of servers) { const resAccounts = await getAccountsList(server.url, '-createdAt') @@ -209,10 +210,5 @@ describe('Test users with multiple servers', function () { after(async function () { killallServers(servers) - - // Keep the logs if the test failed - if (this[ 'ok' ]) { - await flushTests() - } }) }) diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts index edc46a644..cb18898ce 100644 --- a/server/tests/api/videos/multiple-servers.ts +++ b/server/tests/api/videos/multiple-servers.ts @@ -15,7 +15,8 @@ import { dateIsValid, doubleFollow, flushAndRunMultipleServers, - flushTests, getLocalVideos, + flushTests, + getLocalVideos, getVideo, getVideoChannelsList, getVideosList, @@ -39,7 +40,7 @@ import { getVideoCommentThreads, getVideoThreadComments } from '../../utils/videos/video-comments' -import { getAccountsList } from '../../utils/users/accounts' +import { waitJobs } from '../../utils/server/jobs' const expect = chai.expect @@ -102,7 +103,7 @@ describe('Test multiple servers', function () { } await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) - await wait(10000) + await waitJobs(servers) // All servers should have this video let publishedAt: string = null @@ -177,7 +178,7 @@ describe('Test multiple servers', function () { await uploadVideo(servers[1].url, userAccessToken, videoAttributes) // Transcoding - await wait(30000) + await waitJobs(servers) // All servers should have this video for (const server of servers) { @@ -266,7 +267,7 @@ describe('Test multiple servers', function () { } await uploadVideo(servers[2].url, servers[2].accessToken, videoAttributes2) - await wait(10000) + await waitJobs(servers) // All servers should have this video for (const server of servers) { @@ -496,15 +497,15 @@ describe('Test multiple servers', function () { await viewVideo(servers[2].url, localVideosServer3[1]) await Promise.all(tasks) - await wait(1500) + await waitJobs(servers) await viewVideo(servers[2].url, localVideosServer3[0]) - await wait(1500) + await waitJobs(servers) await viewVideo(servers[2].url, localVideosServer3[0]) - await wait(5000) + await waitJobs(servers) for (const server of servers) { const res = await getVideosList(server.url) @@ -535,7 +536,7 @@ describe('Test multiple servers', function () { await Promise.all(tasks) - await wait(10000) + await waitJobs(servers) let baseVideos = null @@ -572,7 +573,7 @@ describe('Test multiple servers', function () { await wait(200) await rateVideo(servers[2].url, servers[2].accessToken, remoteVideosServer3[0], 'like') - await wait(10000) + await waitJobs(servers) let baseVideos = null for (const server of servers) { @@ -614,7 +615,7 @@ describe('Test multiple servers', function () { await updateVideo(servers[2].url, servers[2].accessToken, toRemove[0].id, attributes) - await wait(5000) + await waitJobs(servers) }) it('Should have the video 3 updated on each server', async function () { @@ -670,7 +671,7 @@ describe('Test multiple servers', function () { await removeVideo(servers[2].url, servers[2].accessToken, toRemove[0].id) await removeVideo(servers[2].url, servers[2].accessToken, toRemove[1].id) - await wait(5000) + await waitJobs(servers) }) it('Should not have files of videos 3 and 3-2 on each server', async function () { @@ -749,7 +750,7 @@ describe('Test multiple servers', function () { await addVideoCommentThread(servers[ 2 ].url, servers[ 2 ].accessToken, videoUUID, text) } - await wait(5000) + await waitJobs(servers) { const res = await getVideoCommentThreads(servers[1].url, videoUUID, 0, 5) @@ -759,7 +760,7 @@ describe('Test multiple servers', function () { await addVideoCommentReply(servers[ 1 ].url, servers[ 1 ].accessToken, videoUUID, threadId, text) } - await wait(5000) + await waitJobs(servers) { const res1 = await getVideoCommentThreads(servers[2].url, videoUUID, 0, 5) @@ -775,7 +776,7 @@ describe('Test multiple servers', function () { await addVideoCommentReply(servers[ 2 ].url, servers[ 2 ].accessToken, videoUUID, childCommentId, text2) } - await wait(5000) + await waitJobs(servers) }) it('Should have these threads', async function () { @@ -848,7 +849,7 @@ describe('Test multiple servers', function () { await deleteVideoComment(servers[2].url, servers[2].accessToken, videoUUID, childOfFirstChild.comment.id) - await wait(5000) + await waitJobs(servers) }) it('Should not have this comment anymore', async function () { @@ -877,7 +878,7 @@ describe('Test multiple servers', function () { const threadId = res1.body.data.find(c => c.text === 'my super first comment').id await deleteVideoComment(servers[0].url, servers[0].accessToken, videoUUID, threadId) - await wait(5000) + await waitJobs(servers) }) it('Should have the thread comments deleted on other servers too', async function () { @@ -910,7 +911,7 @@ describe('Test multiple servers', function () { await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, attributes) - await wait(5000) + await waitJobs(servers) for (const server of servers) { const res = await getVideo(server.url, videoUUID) @@ -941,7 +942,7 @@ describe('Test multiple servers', function () { await req.attach('videofile', filePath) .expect(200) - await wait(40000) + await waitJobs(servers) for (const server of servers) { const res = await getVideosList(server.url) diff --git a/server/tests/api/videos/services.ts b/server/tests/api/videos/services.ts index 51db000a2..2f1424292 100644 --- a/server/tests/api/videos/services.ts +++ b/server/tests/api/videos/services.ts @@ -54,7 +54,8 @@ describe('Test services', function () { const maxWidth = 50 const res = await getOEmbed(server.url, oembedUrl, format, maxHeight, maxWidth) - const expectedHtml = `' expect(res.body.html).to.equal(expectedHtml) @@ -69,10 +70,5 @@ describe('Test services', function () { after(async function () { killallServers([ server ]) - - // Keep the logs if the test failed - if (this['ok']) { - await flushTests() - } }) }) diff --git a/server/tests/api/videos/single-server.ts b/server/tests/api/videos/single-server.ts index 5e163e9df..d8af94e8f 100644 --- a/server/tests/api/videos/single-server.ts +++ b/server/tests/api/videos/single-server.ts @@ -5,10 +5,31 @@ import { keyBy } from 'lodash' import 'mocha' import { VideoPrivacy } from '../../../../shared/models/videos' import { - checkVideoFilesWereRemoved, completeVideoCheck, flushTests, getVideo, getVideoCategories, getVideoLanguages, getVideoLicences, - getVideoPrivacies, getVideosList, getVideosListPagination, getVideosListSort, killallServers, rateVideo, removeVideo, runServer, - searchVideo, searchVideoWithPagination, searchVideoWithSort, ServerInfo, setAccessTokensToServers, testImage, updateVideo, uploadVideo, - viewVideo, wait + checkVideoFilesWereRemoved, + completeVideoCheck, + flushTests, + getVideo, + getVideoCategories, + getVideoLanguages, + getVideoLicences, + getVideoPrivacies, + getVideosList, + getVideosListPagination, + getVideosListSort, + killallServers, + rateVideo, + removeVideo, + runServer, + searchVideo, + searchVideoWithPagination, + searchVideoWithSort, + ServerInfo, + setAccessTokensToServers, + testImage, + updateVideo, + uploadVideo, + viewVideo, + wait } from '../../utils' const expect = chai.expect diff --git a/server/tests/api/videos/video-abuse.ts b/server/tests/api/videos/video-abuse.ts index f1c4ef0ce..dde309b96 100644 --- a/server/tests/api/videos/video-abuse.ts +++ b/server/tests/api/videos/video-abuse.ts @@ -5,17 +5,16 @@ import 'mocha' import { VideoAbuse } from '../../../../shared/models/videos' import { flushAndRunMultipleServers, - flushTests, getVideoAbusesList, getVideosList, killallServers, reportVideoAbuse, ServerInfo, setAccessTokensToServers, - uploadVideo, - wait + uploadVideo } from '../../utils/index' import { doubleFollow } from '../../utils/server/follows' +import { waitJobs } from '../../utils/server/jobs' const expect = chai.expect @@ -48,7 +47,7 @@ describe('Test video abuses', function () { await uploadVideo(servers[1].url, servers[1].accessToken, video2Attributes) // Wait videos propagation, server 2 has transcoding enabled - await wait(15000) + await waitJobs(servers) const res = await getVideosList(servers[0].url) const videos = res.body.data @@ -68,13 +67,13 @@ describe('Test video abuses', function () { }) it('Should report abuse on a local video', async function () { - this.timeout(10000) + this.timeout(15000) const reason = 'my super bad reason' await reportVideoAbuse(servers[0].url, servers[0].accessToken, servers[0].video.id, reason) // We wait requests propagation, even if the server 1 is not supposed to make a request to server 2 - await wait(5000) + await waitJobs(servers) }) it('Should have 1 video abuses on server 1 and 0 on server 2', async function () { @@ -103,7 +102,7 @@ describe('Test video abuses', function () { await reportVideoAbuse(servers[0].url, servers[0].accessToken, servers[1].video.id, reason) // We wait requests propagation - await wait(5000) + await waitJobs(servers) }) it('Should have 2 video abuse on server 1 and 1 on server 2', async function () { @@ -137,10 +136,5 @@ describe('Test video abuses', function () { after(async function () { killallServers(servers) - - // Keep the logs if the test failed - if (this['ok']) { - await flushTests() - } }) }) diff --git a/server/tests/api/videos/video-blacklist-management.ts b/server/tests/api/videos/video-blacklist-management.ts index db79784c2..4d1a06436 100644 --- a/server/tests/api/videos/video-blacklist-management.ts +++ b/server/tests/api/videos/video-blacklist-management.ts @@ -6,7 +6,6 @@ import 'mocha' import { addVideoToBlacklist, flushAndRunMultipleServers, - flushTests, getBlacklistedVideosList, getSortedBlacklistedVideosList, getVideosList, @@ -14,10 +13,10 @@ import { removeVideoFromBlacklist, ServerInfo, setAccessTokensToServers, - uploadVideo, - wait + uploadVideo } from '../../utils/index' import { doubleFollow } from '../../utils/server/follows' +import { waitJobs } from '../../utils/server/jobs' const expect = chai.expect const orderBy = lodash.orderBy @@ -51,7 +50,7 @@ describe('Test video blacklist management', function () { await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'My 2nd video', description: 'A video on server 2' }) // Wait videos propagation, server 2 has transcoding enabled - await wait(15000) + await waitJobs(servers) // Blacklist the two videos on server 1 await blacklistVideosOnServer(servers[0]) @@ -154,9 +153,5 @@ describe('Test video blacklist management', function () { after(async function () { killallServers(servers) - - if (this['ok']) { - await flushTests() - } }) }) diff --git a/server/tests/api/videos/video-blacklist.ts b/server/tests/api/videos/video-blacklist.ts index d1cefa5d7..de4c68f1d 100644 --- a/server/tests/api/videos/video-blacklist.ts +++ b/server/tests/api/videos/video-blacklist.ts @@ -5,16 +5,15 @@ import 'mocha' import { addVideoToBlacklist, flushAndRunMultipleServers, - flushTests, getVideosList, killallServers, searchVideo, ServerInfo, setAccessTokensToServers, - uploadVideo, - wait + uploadVideo } from '../../utils/index' import { doubleFollow } from '../../utils/server/follows' +import { waitJobs } from '../../utils/server/jobs' const expect = chai.expect @@ -41,7 +40,7 @@ describe('Test video blacklists', function () { await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) // Wait videos propagation, server 2 has transcoding enabled - await wait(10000) + await waitJobs(servers) const res = await getVideosList(servers[0].url) const videos = res.body.data @@ -89,10 +88,5 @@ describe('Test video blacklists', function () { after(async function () { killallServers(servers) - - // Keep the logs if the test failed - if (this['ok']) { - await flushTests() - } }) }) diff --git a/server/tests/api/videos/video-channels.ts b/server/tests/api/videos/video-channels.ts index 7ae505fd7..ad543e2d6 100644 --- a/server/tests/api/videos/video-channels.ts +++ b/server/tests/api/videos/video-channels.ts @@ -3,7 +3,7 @@ import * as chai from 'chai' import 'mocha' import { User, Video } from '../../../../shared/index' -import { doubleFollow, flushAndRunMultipleServers, getVideoChannelVideos, updateVideo, uploadVideo, wait } from '../../utils' +import { doubleFollow, flushAndRunMultipleServers, getVideoChannelVideos, updateVideo, uploadVideo } from '../../utils' import { addVideoChannel, deleteVideoChannel, @@ -17,6 +17,7 @@ import { setAccessTokensToServers, updateVideoChannel } from '../../utils/index' +import { waitJobs } from '../../utils/server/jobs' const expect = chai.expect @@ -49,7 +50,7 @@ describe('Test video channels', function () { firstVideoChannelUUID = user.videoChannels[0].uuid } - await wait(5000) + await waitJobs(servers) }) it('Should have one video channel (created with root)', async () => { @@ -80,7 +81,7 @@ describe('Test video channels', function () { videoUUID = res.body.video.uuid } - await wait(3000) + await waitJobs(servers) }) it('Should have two video channels when getting my information', async () => { @@ -142,7 +143,7 @@ describe('Test video channels', function () { await updateVideoChannel(servers[0].url, servers[0].accessToken, secondVideoChannelId, videoChannelAttributes) - await wait(3000) + await waitJobs(servers) }) it('Should have video channel updated', async function () { @@ -184,7 +185,7 @@ describe('Test video channels', function () { await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { channelId: firstVideoChannelId }) - await wait(5000) + await waitJobs(servers) }) it('Should list the first video channel videos', async function () { @@ -219,10 +220,5 @@ describe('Test video channels', function () { after(async function () { killallServers(servers) - - // Keep the logs if the test failed - if (this['ok']) { - await flushTests() - } }) }) diff --git a/server/tests/api/videos/video-comments.ts b/server/tests/api/videos/video-comments.ts index f83d95088..d6e07c5b3 100644 --- a/server/tests/api/videos/video-comments.ts +++ b/server/tests/api/videos/video-comments.ts @@ -5,11 +5,20 @@ import 'mocha' import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model' import { testImage } from '../../utils' import { - dateIsValid, flushTests, killallServers, runServer, ServerInfo, setAccessTokensToServers, updateMyAvatar, + dateIsValid, + flushTests, + killallServers, + runServer, + ServerInfo, + setAccessTokensToServers, + updateMyAvatar, uploadVideo } from '../../utils/index' import { - addVideoCommentReply, addVideoCommentThread, deleteVideoComment, getVideoCommentThreads, + addVideoCommentReply, + addVideoCommentThread, + deleteVideoComment, + getVideoCommentThreads, getVideoThreadComments } from '../../utils/videos/video-comments' @@ -194,10 +203,5 @@ describe('Test video comments', function () { after(async function () { killallServers([ server ]) - - // Keep the logs if the test failed - if (this['ok']) { - await flushTests() - } }) }) diff --git a/server/tests/api/videos/video-description.ts b/server/tests/api/videos/video-description.ts index c2985194c..dd5cd78c0 100644 --- a/server/tests/api/videos/video-description.ts +++ b/server/tests/api/videos/video-description.ts @@ -4,7 +4,6 @@ import * as chai from 'chai' import 'mocha' import { flushAndRunMultipleServers, - flushTests, getVideo, getVideoDescription, getVideosList, @@ -12,10 +11,10 @@ import { ServerInfo, setAccessTokensToServers, updateVideo, - uploadVideo, - wait + uploadVideo } from '../../utils/index' import { doubleFollow } from '../../utils/server/follows' +import { waitJobs } from '../../utils/server/jobs' const expect = chai.expect @@ -46,7 +45,7 @@ describe('Test video description', function () { } await uploadVideo(servers[0].url, servers[0].accessToken, attributes) - await wait(5000) + await waitJobs(servers) const res = await getVideosList(servers[0].url) @@ -85,7 +84,7 @@ describe('Test video description', function () { } await updateVideo(servers[0].url, servers[0].accessToken, videoId, attributes) - await wait(5000) + await waitJobs(servers) }) it('Should have a small description on each server', async function () { @@ -102,10 +101,5 @@ describe('Test video description', function () { after(async function () { killallServers(servers) - - // Keep the logs if the test failed - if (this['ok']) { - await flushTests() - } }) }) diff --git a/server/tests/api/videos/video-nsfw.ts b/server/tests/api/videos/video-nsfw.ts index a8f152561..6af0ca8af 100644 --- a/server/tests/api/videos/video-nsfw.ts +++ b/server/tests/api/videos/video-nsfw.ts @@ -8,12 +8,15 @@ import { createUser } from '../../utils/users/users' import { getMyVideos } from '../../utils/videos/videos' import { getAccountVideos, - getConfig, getCustomConfig, - getMyUserInformation, getVideoChannelVideos, + getConfig, + getCustomConfig, + getMyUserInformation, + getVideoChannelVideos, getVideosListWithToken, runServer, searchVideo, - searchVideoWithToken, updateCustomConfig, + searchVideoWithToken, + updateCustomConfig, updateMyUser } from '../../utils' import { ServerConfig } from '../../../../shared/models' @@ -201,10 +204,5 @@ describe('Test video NSFW policy', function () { after(async function () { killallServers([ server ]) - - // Keep the logs if the test failed - if (this['ok']) { - await flushTests() - } }) }) diff --git a/server/tests/api/videos/video-privacy.ts b/server/tests/api/videos/video-privacy.ts index ea435d5af..9fefca7e3 100644 --- a/server/tests/api/videos/video-privacy.ts +++ b/server/tests/api/videos/video-privacy.ts @@ -5,18 +5,17 @@ import 'mocha' import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum' import { flushAndRunMultipleServers, - flushTests, getVideosList, killallServers, ServerInfo, setAccessTokensToServers, - uploadVideo, - wait + uploadVideo } from '../../utils/index' import { doubleFollow } from '../../utils/server/follows' import { userLogin } from '../../utils/users/login' import { createUser } from '../../utils/users/users' import { getMyVideos, getVideo, getVideoWithToken, updateVideo } from '../../utils/videos/videos' +import { waitJobs } from '../../utils/server/jobs' const expect = chai.expect @@ -48,7 +47,7 @@ describe('Test video privacy', function () { } await uploadVideo(servers[0].url, servers[0].accessToken, attributes) - await wait(5000) + await waitJobs(servers) }) it('Should not have this private video on server 2', async function () { @@ -99,7 +98,7 @@ describe('Test video privacy', function () { await uploadVideo(servers[1].url, servers[1].accessToken, attributes) // Server 2 has transcoding enabled - await wait(10000) + await waitJobs(servers) }) it('Should not have this unlisted video listed on server 1 and 2', async function () { @@ -139,7 +138,7 @@ describe('Test video privacy', function () { now = Date.now() await updateVideo(servers[0].url, servers[0].accessToken, privateVideoId, attribute) - await wait(5000) + await waitJobs(servers) }) it('Should have this new public video listed on server 1 and 2', async function () { @@ -155,10 +154,5 @@ describe('Test video privacy', function () { after(async function () { killallServers(servers) - - // Keep the logs if the test failed - if (this['ok']) { - await flushTests() - } }) }) diff --git a/server/tests/api/videos/video-transcoder.ts b/server/tests/api/videos/video-transcoder.ts index 1eace6491..2b203c26b 100644 --- a/server/tests/api/videos/video-transcoder.ts +++ b/server/tests/api/videos/video-transcoder.ts @@ -7,7 +7,6 @@ import { getVideoFileFPS } from '../../../helpers/ffmpeg-utils' import { doubleFollow, flushAndRunMultipleServers, - flushTests, getMyVideos, getVideo, getVideosList, @@ -16,10 +15,10 @@ import { ServerInfo, setAccessTokensToServers, uploadVideo, - wait, webtorrentAdd } from '../../utils' import { join } from 'path' +import { waitJobs } from '../../utils/server/jobs' const expect = chai.expect @@ -45,7 +44,7 @@ describe('Test video transcoding', function () { } await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) - await wait(10000) + await waitJobs(servers) const res = await getVideosList(servers[0].url) const video = res.body.data[0] @@ -73,7 +72,7 @@ describe('Test video transcoding', function () { } await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) - await wait(20000) + await waitJobs(servers) const res = await getVideosList(servers[1].url) @@ -102,7 +101,7 @@ describe('Test video transcoding', function () { } await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) - await wait(20000) + await waitJobs(servers) const res = await getVideosList(servers[1].url) @@ -125,7 +124,7 @@ describe('Test video transcoding', function () { await doubleFollow(servers[0], servers[1]) - await wait(15000) + await waitJobs(servers) { // Upload the video, but wait transcoding @@ -161,7 +160,7 @@ describe('Test video transcoding', function () { await getVideo(servers[0].url, videoId, 404) } - await wait(30000) + await waitJobs(servers) for (const server of servers) { const res = await getVideosList(server.url) @@ -179,10 +178,5 @@ describe('Test video transcoding', function () { after(async function () { killallServers(servers) - - // Keep the logs if the test failed - if (this['ok']) { - await flushTests() - } }) }) diff --git a/server/tests/cli/create-import-video-file-job.ts b/server/tests/cli/create-import-video-file-job.ts index 1472e60f6..13bcfd209 100644 --- a/server/tests/cli/create-import-video-file-job.ts +++ b/server/tests/cli/create-import-video-file-job.ts @@ -14,9 +14,9 @@ import { killallServers, ServerInfo, setAccessTokensToServers, - uploadVideo, - wait + uploadVideo } from '../utils' +import { waitJobs } from '../utils/server/jobs' const expect = chai.expect @@ -54,14 +54,14 @@ describe('Test create import video jobs', function () { video2UUID = res2.body.video.uuid // Transcoding - await wait(40000) + await waitJobs(servers) }) it('Should run a import job on video 1 with a lower resolution', async function () { const env = getEnvCli(servers[0]) await execCLI(`${env} npm run create-import-video-file-job -- -v ${video1UUID} -i server/tests/fixtures/video_short-480.webm`) - await wait(30000) + await waitJobs(servers) let magnetUri: string for (const server of servers) { @@ -85,7 +85,7 @@ describe('Test create import video jobs', function () { const env = getEnvCli(servers[1]) await execCLI(`${env} npm run create-import-video-file-job -- -v ${video2UUID} -i server/tests/fixtures/video_short.ogv`) - await wait(30000) + await waitJobs(servers) let magnetUri: string for (const server of servers) { @@ -111,7 +111,7 @@ describe('Test create import video jobs', function () { const env = getEnvCli(servers[0]) await execCLI(`${env} npm run create-import-video-file-job -- -v ${video1UUID} -i server/tests/fixtures/video_short2.webm`) - await wait(30000) + await waitJobs(servers) let magnetUri: string for (const server of servers) { @@ -133,10 +133,5 @@ describe('Test create import video jobs', function () { after(async function () { killallServers(servers) - - // Keep the logs if the test failed - if (this['ok']) { - await flushTests() - } }) }) diff --git a/server/tests/cli/create-transcoding-job.ts b/server/tests/cli/create-transcoding-job.ts index fe1c0c03d..e7c36f9c6 100644 --- a/server/tests/cli/create-transcoding-job.ts +++ b/server/tests/cli/create-transcoding-job.ts @@ -3,22 +3,22 @@ import 'mocha' import * as chai from 'chai' import { VideoDetails } from '../../../shared/models/videos' -const expect = chai.expect - import { + doubleFollow, execCLI, + flushAndRunMultipleServers, flushTests, getEnvCli, + getVideo, getVideosList, killallServers, - parseTorrentVideo, - runServer, ServerInfo, setAccessTokensToServers, - uploadVideo, - wait, - getVideo, flushAndRunMultipleServers, doubleFollow + uploadVideo, wait } from '../utils' +import { waitJobs } from '../utils/server/jobs' + +const expect = chai.expect describe('Test create transcoding jobs', function () { let servers: ServerInfo[] = [] @@ -40,7 +40,7 @@ describe('Test create transcoding jobs', function () { const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video2' }) video2UUID = res.body.video.uuid - await wait(3000) + await waitJobs(servers) }) it('Should have two video files on each server', async function () { @@ -65,7 +65,7 @@ describe('Test create transcoding jobs', function () { const env = getEnvCli(servers[0]) await execCLI(`${env} npm run create-transcoding-job -- -v ${video2UUID}`) - await wait(40000) + await waitJobs(servers) for (const server of servers) { const res = await getVideosList(server.url) @@ -102,10 +102,5 @@ describe('Test create transcoding jobs', function () { after(async function () { killallServers(servers) - - // Keep the logs if the test failed - if (this['ok']) { - await flushTests() - } }) }) diff --git a/server/tests/cli/reset-password.ts b/server/tests/cli/reset-password.ts index 98ea7d456..bf937d1c0 100644 --- a/server/tests/cli/reset-password.ts +++ b/server/tests/cli/reset-password.ts @@ -36,10 +36,5 @@ describe('Test reset password scripts', function () { after(async function () { killallServers([ server ]) - - // Keep the logs if the test failed - if (this['ok']) { - await flushTests() - } }) }) diff --git a/server/tests/cli/update-host.ts b/server/tests/cli/update-host.ts index ad56f7b1b..d0c6d2042 100644 --- a/server/tests/cli/update-host.ts +++ b/server/tests/cli/update-host.ts @@ -3,22 +3,22 @@ import 'mocha' import * as chai from 'chai' import { VideoDetails } from '../../../shared/models/videos' -const expect = chai.expect - import { execCLI, flushTests, getEnvCli, + getVideo, getVideosList, killallServers, parseTorrentVideo, runServer, ServerInfo, setAccessTokensToServers, - uploadVideo, - wait, - getVideo + uploadVideo } from '../utils' +import { waitJobs } from '../utils/server/jobs' + +const expect = chai.expect describe('Test update host scripts', function () { let server: ServerInfo @@ -41,7 +41,8 @@ describe('Test update host scripts', function () { const videoAttributes = {} await uploadVideo(server.url, server.accessToken, videoAttributes) await uploadVideo(server.url, server.accessToken, videoAttributes) - await wait(30000) + + await waitJobs(server) }) it('Should update torrent hosts', async function () { @@ -82,10 +83,5 @@ describe('Test update host scripts', function () { after(async function () { killallServers([ server ]) - - // Keep the logs if the test failed - if (this['ok']) { - await flushTests() - } }) }) diff --git a/server/tests/client.ts b/server/tests/client.ts index 2adb39c5e..687655452 100644 --- a/server/tests/client.ts +++ b/server/tests/client.ts @@ -11,7 +11,7 @@ import { runServer, serverLogin, uploadVideo, - getVideosList, updateCustomConfig, getCustomConfig + getVideosList, updateCustomConfig, getCustomConfig, killallServers } from './utils' describe('Test a client controllers', function () { @@ -102,11 +102,6 @@ describe('Test a client controllers', function () { }) after(async function () { - process.kill(-server.app.pid) - - // Keep the logs if the test failed - if (this['ok']) { - await flushTests() - } + killallServers([ server ]) }) }) diff --git a/server/tests/feeds/feeds.ts b/server/tests/feeds/feeds.ts index f65148f00..90450a0bb 100644 --- a/server/tests/feeds/feeds.ts +++ b/server/tests/feeds/feeds.ts @@ -11,12 +11,12 @@ import { killallServers, ServerInfo, setAccessTokensToServers, - uploadVideo, - wait + uploadVideo } from '../utils' import { join } from 'path' import * as libxmljs from 'libxmljs' import { addVideoCommentThread } from '../utils/videos/video-comments' +import { waitJobs } from '../utils/server/jobs' chai.use(require('chai-xml')) chai.use(require('chai-json-schema')) @@ -46,7 +46,7 @@ describe('Test syndication feeds', () => { await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoId, 'super comment 1') await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoId, 'super comment 2') - await wait(10000) + await waitJobs(servers) }) describe('All feed', function () { diff --git a/server/tests/utils/miscs/miscs.ts b/server/tests/utils/miscs/miscs.ts index 5e46004a7..7ac60a983 100644 --- a/server/tests/utils/miscs/miscs.ts +++ b/server/tests/utils/miscs/miscs.ts @@ -5,6 +5,7 @@ import { isAbsolute, join } from 'path' import * as request from 'supertest' import * as WebTorrent from 'webtorrent' import { readFileBufferPromise } from '../../../helpers/core-utils' +import { ServerInfo } from '..' const expect = chai.expect let webtorrent = new WebTorrent() diff --git a/server/tests/utils/server/follows.ts b/server/tests/utils/server/follows.ts index 82e89175c..d21fb5e58 100644 --- a/server/tests/utils/server/follows.ts +++ b/server/tests/utils/server/follows.ts @@ -1,6 +1,7 @@ import * as request from 'supertest' import { wait } from '../miscs/miscs' import { ServerInfo } from './servers' +import { waitJobs } from './jobs' function getFollowersListPaginationAndSort (url: string, start: number, count: number, sort: string) { const path = '/api/v1/server/followers' @@ -61,7 +62,7 @@ async function doubleFollow (server1: ServerInfo, server2: ServerInfo) { ]) // Wait request propagation - await wait(10000) + await waitJobs([ server1, server2 ]) return true } diff --git a/server/tests/utils/server/jobs.ts b/server/tests/utils/server/jobs.ts index 4053dd40b..375e76f93 100644 --- a/server/tests/utils/server/jobs.ts +++ b/server/tests/utils/server/jobs.ts @@ -1,5 +1,6 @@ import * as request from 'supertest' import { JobState } from '../../../../shared/models' +import { ServerInfo, wait } from '../index' function getJobsList (url: string, accessToken: string, state: JobState) { const path = '/api/v1/jobs/' + state @@ -26,9 +27,49 @@ function getJobsListPaginationAndSort (url: string, accessToken: string, state: .expect('Content-Type', /json/) } +async function waitJobs (serversArg: ServerInfo[] | ServerInfo) { + let servers: ServerInfo[] + + if (Array.isArray(serversArg) === false) servers = [ serversArg as ServerInfo ] + else servers = serversArg as ServerInfo[] + + const states: JobState[] = [ 'inactive', 'active', 'delayed' ] + const tasks: Promise[] = [] + let pendingRequests: boolean + + do { + pendingRequests = false + + // Check if each server has pending request + for (const server of servers) { + for (const state of states) { + const p = getJobsListPaginationAndSort(server.url, server.accessToken, state, 0, 10, '-createdAt') + .then(res => { + if (res.body.total > 0) pendingRequests = true + }) + tasks.push(p) + } + } + + await Promise.all(tasks) + + // Retry, in case of new jobs were created + if (pendingRequests === false) { + await wait(1000) + + await Promise.all(tasks) + } + + if (pendingRequests) { + await wait(1000) + } + } while (pendingRequests) +} + // --------------------------------------------------------------------------- export { getJobsList, + waitJobs, getJobsListPaginationAndSort }