Improve tests when waiting pending jobs
authorChocobozzz <me@florianbigard.com>
Wed, 13 Jun 2018 08:06:50 +0000 (10:06 +0200)
committerChocobozzz <me@florianbigard.com>
Wed, 13 Jun 2018 08:22:53 +0000 (10:22 +0200)
32 files changed:
server/initializers/constants.ts
server/lib/activitypub/process/process-update.ts
server/tests/activitypub.ts
server/tests/api/server/config.ts
server/tests/api/server/email.ts
server/tests/api/server/follows.ts
server/tests/api/server/handle-down.ts
server/tests/api/server/jobs.ts
server/tests/api/server/reverse-proxy.ts
server/tests/api/server/stats.ts
server/tests/api/users/users-multiple-servers.ts
server/tests/api/videos/multiple-servers.ts
server/tests/api/videos/services.ts
server/tests/api/videos/single-server.ts
server/tests/api/videos/video-abuse.ts
server/tests/api/videos/video-blacklist-management.ts
server/tests/api/videos/video-blacklist.ts
server/tests/api/videos/video-channels.ts
server/tests/api/videos/video-comments.ts
server/tests/api/videos/video-description.ts
server/tests/api/videos/video-nsfw.ts
server/tests/api/videos/video-privacy.ts
server/tests/api/videos/video-transcoder.ts
server/tests/cli/create-import-video-file-job.ts
server/tests/cli/create-transcoding-job.ts
server/tests/cli/reset-password.ts
server/tests/cli/update-host.ts
server/tests/client.ts
server/tests/feeds/feeds.ts
server/tests/utils/miscs/miscs.ts
server/tests/utils/server/follows.ts
server/tests/utils/server/jobs.ts

index 8dbc1b060805f96887cd49c2ec767986794793cb..65f89ff7f76d1ad7a90f8e712b2296f1709d0733 100644 (file)
@@ -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()
index 77de8c1554352e3f40d92738113b834260d14918..1ebda46d33d784c076e6ba20d325f61c66987353 100644 (file)
@@ -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)
 
index 9e29b0fa88b1fcf9a67cb56804e039331b9b325b..53a04d3638d8ede6de29e13da4965386eda1af70 100644 (file)
@@ -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()
-    }
   })
 })
index f24961b858372a1b7de47981f6b99fed0255989d..4de0d6b1042dc3196ddfcef3f4764cfe0d0ccb3d 100644 (file)
@@ -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 ])
   })
 })
index 068e820c8e5c44913c8e3d0f827f80fad21f4083..4be013c84e9f3f170d7be2090c36c081618822af 100644 (file)
@@ -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()
-    }
   })
 })
index 9d619a7ded3f9f8fae3490f8e5b6b935221065ef..ce42df0a612317a25e8bbf5d6800fe285bb87342 100644 (file)
@@ -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()
-    }
   })
 })
index 889825936bec6f6fbfbe9edccc7a0ae908cd6704..55705caca71407eb230b6654ed1f61f1c9148a6f 100644 (file)
@@ -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()
-    }
   })
 })
index 6714987699fca1051bcc0e0cb865aae42d8738c9..81e389de66839c964e72f2b16a926df6bdf892c7 100644 (file)
@@ -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()
-    }
   })
 })
index 4c2655f64215726408c6e75cf257d33039bd8363..908b4a68cbd3a9cf0d71115ef72f74f22d97da80 100644 (file)
@@ -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 ])
   })
 })
index 71d54c0ab2c8410668dd792c3e62a1639a90131d..e75089a147aafbb3132a869c25aeb4034efd47c6 100644 (file)
@@ -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()
-    }
   })
 })
index 0e1e6c97db3975b5e52dee8b6f7723f40cd9be28..81489021bfbe44560d463bdefca036af5539855d 100644 (file)
@@ -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()
-    }
   })
 })
index edc46a64452f2257b69d088d3eedce9ad1bed40e..cb18898cef0a2bebb90da20d47b360804d61c4b6 100644 (file)
@@ -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)
index 51db000a26a8be1498d413f8ce515300c723f7af..2f14242920dd96cb500b0809b9e195446964b670 100644 (file)
@@ -54,7 +54,8 @@ describe('Test services', function () {
     const maxWidth = 50
 
     const res = await getOEmbed(server.url, oembedUrl, format, maxHeight, maxWidth)
-    const expectedHtml = `<iframe width="50" height="50" src="http://localhost:9001/videos/embed/${server.video.uuid}" ` +
+    const expectedHtml = '<iframe width="50" height="50" sandbox="allow-same-origin allow-scripts" ' +
+                         `src="http://localhost:9001/videos/embed/${server.video.uuid}" ` +
                          'frameborder="0" allowfullscreen></iframe>'
 
     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()
-    }
   })
 })
index 5e163e9df005aa02a02f6d9219af27bf7de5da97..d8af94e8f9302fe98bf6442b9af2edad511c3073 100644 (file)
@@ -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
index f1c4ef0ceb45d2bba609154cd96959559a1d345d..dde309b96a5a5746d80748836d4305ac22336000 100644 (file)
@@ -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()
-    }
   })
 })
index db79784c2774e4b28dd78e7ac01c2b2d2520f115..4d1a064366a20964b0af9caa4a445b0ce9935a35 100644 (file)
@@ -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()
-    }
   })
 })
index d1cefa5d701a0a08d59f9f1557c3ffeeb6f6418d..de4c68f1dd10a4c218d3dc171272854a06b0db81 100644 (file)
@@ -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()
-    }
   })
 })
index 7ae505fd78b046da9218822918e9afa71be3673f..ad543e2d6c31df9c908fd69732fc31b890559e94 100644 (file)
@@ -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()
-    }
   })
 })
index f83d9508811dd55f20937abdf15bdc5eb49979f3..d6e07c5b3945dbba0d31dc603a709202fef87e40 100644 (file)
@@ -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()
-    }
   })
 })
index c2985194c5c026b9ddde917bf81fe25fe3b768d0..dd5cd78c0556def192d31b327e501f82c006246c 100644 (file)
@@ -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()
-    }
   })
 })
index a8f1525610144f4a773879b5c21161fe44038069..6af0ca8af72472ee8318c93ea1d040b599371fa0 100644 (file)
@@ -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()
-    }
   })
 })
index ea435d5afedee39a5b573bb556541b7a100717e5..9fefca7e3d919e90e280a3592a0aa164dc477643 100644 (file)
@@ -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()
-    }
   })
 })
index 1eace6491c0729281c4de105b9cc5df13102c7ea..2b203c26baf2c567338e470e5126bd2e5be5a82b 100644 (file)
@@ -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()
-    }
   })
 })
index 1472e60f6fb5630910f54ea827b500c825ae1b7a..13bcfd209836f636e831fe487c0d74ddcafec67f 100644 (file)
@@ -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()
-    }
   })
 })
index fe1c0c03d7753a4a769293b83ed02bac14234ee6..e7c36f9c6243702c4775f05de750daafbdb62c9d 100644 (file)
@@ -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()
-    }
   })
 })
index 98ea7d4561365af8caf2edb1a9a29cc9378d5d0b..bf937d1c0c022ed054a911cbe83dc97a30f6a310 100644 (file)
@@ -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()
-    }
   })
 })
index ad56f7b1b4e8cf7dcfba0437cb95181485d14085..d0c6d2042839ecd2ca3e2edb6e0f049a968b1e70 100644 (file)
@@ -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()
-    }
   })
 })
index 2adb39c5eed8d1c47ad9c995209f5acff7941c69..68765545221927c2eec9c7e07630438a4730ea7d 100644 (file)
@@ -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 ])
   })
 })
index f65148f00bc5ffdbfe80386a1d4fd61a9b9d36d9..90450a0bbad0504527c8718ef7aa9884f238f65c 100644 (file)
@@ -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 () {
index 5e46004a7f48f8a24cac8bfc3961a7268f983483..7ac60a983b5faf68358ced7c13bd47a48f260b22 100644 (file)
@@ -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()
index 82e89175cf13f12692463ee6785650784a842404..d21fb5e5895bbabfdc18cc5dd9445f4773caf519 100644 (file)
@@ -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
 }
index 4053dd40b203a49dba373a41e3d430a324cc6761..375e76f93411ca8214a66f122887ab0eabfa5ddb 100644 (file)
@@ -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<any>[] = []
+  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
 }