aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-06-13 10:06:50 +0200
committerChocobozzz <me@florianbigard.com>2018-06-13 10:22:53 +0200
commit3cd0734fd9b0ff21aaef02317a874e8f1c06e027 (patch)
tree9e8622d269919addd35b462141ab5f22236aa6f4
parent2186386cca113506791583cb07d6ccacba7af4e0 (diff)
downloadPeerTube-3cd0734fd9b0ff21aaef02317a874e8f1c06e027.tar.gz
PeerTube-3cd0734fd9b0ff21aaef02317a874e8f1c06e027.tar.zst
PeerTube-3cd0734fd9b0ff21aaef02317a874e8f1c06e027.zip
Improve tests when waiting pending jobs
-rw-r--r--server/initializers/constants.ts7
-rw-r--r--server/lib/activitypub/process/process-update.ts14
-rw-r--r--server/tests/activitypub.ts5
-rw-r--r--server/tests/api/server/config.ts7
-rw-r--r--server/tests/api/server/email.ts12
-rw-r--r--server/tests/api/server/follows.ts31
-rw-r--r--server/tests/api/server/handle-down.ts25
-rw-r--r--server/tests/api/server/jobs.ts9
-rw-r--r--server/tests/api/server/reverse-proxy.ts7
-rw-r--r--server/tests/api/server/stats.ts8
-rw-r--r--server/tests/api/users/users-multiple-servers.ts16
-rw-r--r--server/tests/api/videos/multiple-servers.ts39
-rw-r--r--server/tests/api/videos/services.ts8
-rw-r--r--server/tests/api/videos/single-server.ts29
-rw-r--r--server/tests/api/videos/video-abuse.ts18
-rw-r--r--server/tests/api/videos/video-blacklist-management.ts11
-rw-r--r--server/tests/api/videos/video-blacklist.ts12
-rw-r--r--server/tests/api/videos/video-channels.ts16
-rw-r--r--server/tests/api/videos/video-comments.ts18
-rw-r--r--server/tests/api/videos/video-description.ts14
-rw-r--r--server/tests/api/videos/video-nsfw.ts14
-rw-r--r--server/tests/api/videos/video-privacy.ts16
-rw-r--r--server/tests/api/videos/video-transcoder.ts18
-rw-r--r--server/tests/cli/create-import-video-file-job.ts17
-rw-r--r--server/tests/cli/create-transcoding-job.ts23
-rw-r--r--server/tests/cli/reset-password.ts5
-rw-r--r--server/tests/cli/update-host.ts18
-rw-r--r--server/tests/client.ts9
-rw-r--r--server/tests/feeds/feeds.ts6
-rw-r--r--server/tests/utils/miscs/miscs.ts1
-rw-r--r--server/tests/utils/server/follows.ts3
-rw-r--r--server/tests/utils/server/jobs.ts41
32 files changed, 225 insertions, 252 deletions
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 = {
449// Special constants for a test instance 449// Special constants for a test instance
450if (isTestInstance() === true) { 450if (isTestInstance() === true) {
451 ACTOR_FOLLOW_SCORE.BASE = 20 451 ACTOR_FOLLOW_SCORE.BASE = 20
452
452 REMOTE_SCHEME.HTTP = 'http' 453 REMOTE_SCHEME.HTTP = 'http'
453 REMOTE_SCHEME.WS = 'ws' 454 REMOTE_SCHEME.WS = 'ws'
455
454 STATIC_MAX_AGE = '0' 456 STATIC_MAX_AGE = '0'
457
455 ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE = 2 458 ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE = 2
456 ACTIVITY_PUB.ACTOR_REFRESH_INTERVAL = 10 * 1000 // 10 seconds 459 ACTIVITY_PUB.ACTOR_REFRESH_INTERVAL = 10 * 1000 // 10 seconds
460
457 CONSTRAINTS_FIELDS.ACTORS.AVATAR.FILE_SIZE.max = 100 * 1024 // 100KB 461 CONSTRAINTS_FIELDS.ACTORS.AVATAR.FILE_SIZE.max = 100 * 1024 // 100KB
462
458 SCHEDULER_INTERVAL = 10000 463 SCHEDULER_INTERVAL = 10000
459 VIDEO_VIEW_LIFETIME = 1000 // 1 second 464 VIDEO_VIEW_LIFETIME = 1000 // 1 second
465
466 JOB_ATTEMPTS['email'] = 1
460} 467}
461 468
462updateWebserverConfig() 469updateWebserverConfig()
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 @@
1import * as Bluebird from 'bluebird' 1import * as Bluebird from 'bluebird'
2import { ActivityUpdate } from '../../../../shared/models/activitypub' 2import { ActivityUpdate, VideoTorrentObject } from '../../../../shared/models/activitypub'
3import { ActivityPubActor } from '../../../../shared/models/activitypub/activitypub-actor' 3import { ActivityPubActor } from '../../../../shared/models/activitypub/activitypub-actor'
4import { retryTransactionWrapper } from '../../../helpers/database-utils' 4import { retryTransactionWrapper } from '../../../helpers/database-utils'
5import { logger } from '../../../helpers/logger' 5import { logger } from '../../../helpers/logger'
@@ -12,13 +12,13 @@ import { VideoChannelModel } from '../../../models/video/video-channel'
12import { VideoFileModel } from '../../../models/video/video-file' 12import { VideoFileModel } from '../../../models/video/video-file'
13import { fetchAvatarIfExists, getOrCreateActorAndServerAndModel, updateActorAvatarInstance, updateActorInstance } from '../actor' 13import { fetchAvatarIfExists, getOrCreateActorAndServerAndModel, updateActorAvatarInstance, updateActorInstance } from '../actor'
14import { 14import {
15 fetchRemoteVideo,
16 generateThumbnailFromUrl, 15 generateThumbnailFromUrl,
17 getOrCreateAccountAndVideoAndChannel, 16 getOrCreateAccountAndVideoAndChannel,
18 getOrCreateVideoChannel, 17 getOrCreateVideoChannel,
19 videoActivityObjectToDBAttributes, 18 videoActivityObjectToDBAttributes,
20 videoFileActivityUrlToDBAttributes 19 videoFileActivityUrlToDBAttributes
21} from '../videos' 20} from '../videos'
21import { sanitizeAndCheckVideoTorrentObject } from '../../../helpers/custom-validators/activitypub/videos'
22 22
23async function processUpdateActivity (activity: ActivityUpdate) { 23async function processUpdateActivity (activity: ActivityUpdate) {
24 const actor = await getOrCreateActorAndServerAndModel(activity.actor) 24 const actor = await getOrCreateActorAndServerAndModel(activity.actor)
@@ -30,7 +30,7 @@ async function processUpdateActivity (activity: ActivityUpdate) {
30 return processUpdateActor(actor, activity) 30 return processUpdateActor(actor, activity)
31 } 31 }
32 32
33 return 33 return undefined
34} 34}
35 35
36// --------------------------------------------------------------------------- 36// ---------------------------------------------------------------------------
@@ -51,10 +51,12 @@ function processUpdateVideo (actor: ActorModel, activity: ActivityUpdate) {
51} 51}
52 52
53async function updateRemoteVideo (actor: ActorModel, activity: ActivityUpdate) { 53async function updateRemoteVideo (actor: ActorModel, activity: ActivityUpdate) {
54 const videoUrl = activity.object.id 54 const videoObject = activity.object as VideoTorrentObject
55 55
56 const videoObject = await fetchRemoteVideo(videoUrl) 56 if (sanitizeAndCheckVideoTorrentObject(videoObject) === false) {
57 if (!videoObject) throw new Error('Cannot fetch remote video with url: ' + videoUrl) 57 logger.debug('Video sent by update is not valid.', { videoObject })
58 return undefined
59 }
58 60
59 const res = await getOrCreateAccountAndVideoAndChannel(videoObject.id) 61 const res = await getOrCreateAccountAndVideoAndChannel(videoObject.id)
60 62
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 () {
31 31
32 after(async function () { 32 after(async function () {
33 killallServers([ server ]) 33 killallServers([ server ])
34
35 // Keep the logs if the test failed
36 if (this['ok']) {
37 await flushTests()
38 }
39 }) 34 })
40}) 35})
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 () {
234 }) 234 })
235 235
236 after(async function () { 236 after(async function () {
237 process.kill(-server.app.pid) 237 killallServers([ server ])
238
239 // Keep the logs if the test failed
240 if (this['ok']) {
241 await flushTests()
242 }
243 }) 238 })
244}) 239})
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'
5import { askResetPassword, createUser, reportVideoAbuse, resetPassword, runServer, uploadVideo, userLogin, wait } from '../../utils' 5import { askResetPassword, createUser, reportVideoAbuse, resetPassword, runServer, uploadVideo, userLogin, wait } from '../../utils'
6import { flushTests, killallServers, ServerInfo, setAccessTokensToServers } from '../../utils/index' 6import { flushTests, killallServers, ServerInfo, setAccessTokensToServers } from '../../utils/index'
7import { mockSmtpServer } from '../../utils/miscs/email' 7import { mockSmtpServer } from '../../utils/miscs/email'
8import { waitJobs } from '../../utils/server/jobs'
8 9
9const expect = chai.expect 10const expect = chai.expect
10 11
@@ -32,8 +33,6 @@ describe('Test emails', function () {
32 } 33 }
33 } 34 }
34 server = await runServer(1, overrideConfig) 35 server = await runServer(1, overrideConfig)
35
36 await wait(5000)
37 await setAccessTokensToServers([ server ]) 36 await setAccessTokensToServers([ server ])
38 37
39 { 38 {
@@ -57,7 +56,7 @@ describe('Test emails', function () {
57 56
58 await askResetPassword(server.url, 'user_1@example.com') 57 await askResetPassword(server.url, 'user_1@example.com')
59 58
60 await wait(3000) 59 await waitJobs(server)
61 expect(emails).to.have.lengthOf(1) 60 expect(emails).to.have.lengthOf(1)
62 61
63 const email = emails[0] 62 const email = emails[0]
@@ -101,7 +100,7 @@ describe('Test emails', function () {
101 const reason = 'my super bad reason' 100 const reason = 'my super bad reason'
102 await reportVideoAbuse(server.url, server.accessToken, videoUUID, reason) 101 await reportVideoAbuse(server.url, server.accessToken, videoUUID, reason)
103 102
104 await wait(3000) 103 await waitJobs(server)
105 expect(emails).to.have.lengthOf(2) 104 expect(emails).to.have.lengthOf(2)
106 105
107 const email = emails[1] 106 const email = emails[1]
@@ -115,10 +114,5 @@ describe('Test emails', function () {
115 114
116 after(async function () { 115 after(async function () {
117 killallServers([ server ]) 116 killallServers([ server ])
118
119 // Keep the logs if the test failed
120 if (this['ok']) {
121 await flushTests()
122 }
123 }) 117 })
124}) 118})
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'
5import { Video, VideoPrivacy } from '../../../../shared/models/videos' 5import { Video, VideoPrivacy } from '../../../../shared/models/videos'
6import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model' 6import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model'
7import { completeVideoCheck } from '../../utils' 7import { completeVideoCheck } from '../../utils'
8
9import { 8import {
10 flushAndRunMultipleServers, flushTests, getVideosList, killallServers, ServerInfo, setAccessTokensToServers, uploadVideo, 9 flushAndRunMultipleServers,
11 wait 10 getVideosList,
11 killallServers,
12 ServerInfo,
13 setAccessTokensToServers,
14 uploadVideo
12} from '../../utils/index' 15} from '../../utils/index'
13import { dateIsValid } from '../../utils/miscs/miscs' 16import { dateIsValid } from '../../utils/miscs/miscs'
14import { follow, getFollowersListPaginationAndSort, getFollowingListPaginationAndSort, unfollow } from '../../utils/server/follows' 17import { follow, getFollowersListPaginationAndSort, getFollowingListPaginationAndSort, unfollow } from '../../utils/server/follows'
@@ -16,10 +19,13 @@ import { expectAccountFollows } from '../../utils/users/accounts'
16import { userLogin } from '../../utils/users/login' 19import { userLogin } from '../../utils/users/login'
17import { createUser } from '../../utils/users/users' 20import { createUser } from '../../utils/users/users'
18import { 21import {
19 addVideoCommentReply, addVideoCommentThread, getVideoCommentThreads, 22 addVideoCommentReply,
23 addVideoCommentThread,
24 getVideoCommentThreads,
20 getVideoThreadComments 25 getVideoThreadComments
21} from '../../utils/videos/video-comments' 26} from '../../utils/videos/video-comments'
22import { rateVideo } from '../../utils/videos/videos' 27import { rateVideo } from '../../utils/videos/videos'
28import { waitJobs } from '../../utils/server/jobs'
23 29
24const expect = chai.expect 30const expect = chai.expect
25 31
@@ -62,7 +68,7 @@ describe('Test follows', function () {
62 68
63 await follow(servers[0].url, [ servers[1].url, servers[2].url ], servers[0].accessToken) 69 await follow(servers[0].url, [ servers[1].url, servers[2].url ], servers[0].accessToken)
64 70
65 await wait(7000) 71 await waitJobs(servers)
66 }) 72 })
67 73
68 it('Should have 2 followings on server 1', async function () { 74 it('Should have 2 followings on server 1', async function () {
@@ -135,7 +141,7 @@ describe('Test follows', function () {
135 141
136 await unfollow(servers[0].url, servers[0].accessToken, servers[2]) 142 await unfollow(servers[0].url, servers[0].accessToken, servers[2])
137 143
138 await wait(3000) 144 await waitJobs(servers)
139 }) 145 })
140 146
141 it('Should not follow server 3 on server 1 anymore', async function () { 147 it('Should not follow server 3 on server 1 anymore', async function () {
@@ -175,7 +181,7 @@ describe('Test follows', function () {
175 await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'server2' }) 181 await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'server2' })
176 await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3' }) 182 await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3' })
177 183
178 await wait(5000) 184 await waitJobs(servers)
179 185
180 let res = await getVideosList(servers[0].url) 186 let res = await getVideosList(servers[0].url)
181 expect(res.body.total).to.equal(1) 187 expect(res.body.total).to.equal(1)
@@ -240,12 +246,12 @@ describe('Test follows', function () {
240 } 246 }
241 } 247 }
242 248
243 await wait(5000) 249 await waitJobs(servers)
244 250
245 // Server 1 follows server 3 251 // Server 1 follows server 3
246 await follow(servers[ 0 ].url, [ servers[ 2 ].url ], servers[ 0 ].accessToken) 252 await follow(servers[ 0 ].url, [ servers[ 2 ].url ], servers[ 0 ].accessToken)
247 253
248 await wait(7000) 254 await waitJobs(servers)
249 }) 255 })
250 256
251 it('Should have the correct follows counts 3', async function () { 257 it('Should have the correct follows counts 3', async function () {
@@ -352,7 +358,7 @@ describe('Test follows', function () {
352 358
353 await unfollow(servers[0].url, servers[0].accessToken, servers[2]) 359 await unfollow(servers[0].url, servers[0].accessToken, servers[2])
354 360
355 await wait(3000) 361 await waitJobs(servers)
356 362
357 let res = await getVideosList(servers[ 0 ].url) 363 let res = await getVideosList(servers[ 0 ].url)
358 expect(res.body.total).to.equal(1) 364 expect(res.body.total).to.equal(1)
@@ -362,10 +368,5 @@ describe('Test follows', function () {
362 368
363 after(async function () { 369 after(async function () {
364 killallServers(servers) 370 killallServers(servers)
365
366 // Keep the logs if the test failed
367 if (this['ok']) {
368 await flushTests()
369 }
370 }) 371 })
371}) 372})
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 {
12 wait 12 wait
13} from '../../utils/index' 13} from '../../utils/index'
14import { follow, getFollowersListPaginationAndSort } from '../../utils/server/follows' 14import { follow, getFollowersListPaginationAndSort } from '../../utils/server/follows'
15import { getJobsListPaginationAndSort } from '../../utils/server/jobs' 15import { getJobsListPaginationAndSort, waitJobs } from '../../utils/server/jobs'
16import { 16import {
17 addVideoCommentReply, addVideoCommentThread, getVideoCommentThreads, 17 addVideoCommentReply, addVideoCommentThread, getVideoCommentThreads,
18 getVideoThreadComments 18 getVideoThreadComments
@@ -94,11 +94,11 @@ describe('Test handle downs', function () {
94 94
95 await follow(servers[1].url, [ servers[0].url ], servers[1].accessToken) 95 await follow(servers[1].url, [ servers[0].url ], servers[1].accessToken)
96 96
97 await wait(5000) 97 await waitJobs(servers)
98 98
99 await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) 99 await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
100 100
101 await wait(5000) 101 await waitJobs(servers)
102 102
103 for (const server of servers) { 103 for (const server of servers) {
104 const res = await getVideosList(server.url) 104 const res = await getVideosList(server.url)
@@ -118,7 +118,7 @@ describe('Test handle downs', function () {
118 videos.push(resVideo.body.video) 118 videos.push(resVideo.body.video)
119 } 119 }
120 120
121 await wait(2000) 121 await waitJobs(servers[0])
122 122
123 await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, videoAttributes) 123 await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, videoAttributes)
124 124
@@ -136,7 +136,9 @@ describe('Test handle downs', function () {
136 commentIdServer1 = resComment.body.comment.id 136 commentIdServer1 = resComment.body.comment.id
137 } 137 }
138 138
139 await wait(10000) 139 await waitJobs(servers[0])
140 // Wait scheduler
141 await wait(3000)
140 142
141 const res = await getFollowersListPaginationAndSort(servers[0].url, 0, 1, 'createdAt') 143 const res = await getFollowersListPaginationAndSort(servers[0].url, 0, 1, 'createdAt')
142 expect(res.body.data).to.be.an('array') 144 expect(res.body.data).to.be.an('array')
@@ -159,7 +161,7 @@ describe('Test handle downs', function () {
159 161
160 await follow(servers[1].url, [ servers[0].url ], servers[1].accessToken) 162 await follow(servers[1].url, [ servers[0].url ], servers[1].accessToken)
161 163
162 await wait(5000) 164 await waitJobs(servers)
163 165
164 const res = await getFollowersListPaginationAndSort(servers[0].url, 0, 1, 'createdAt') 166 const res = await getFollowersListPaginationAndSort(servers[0].url, 0, 1, 'createdAt')
165 expect(res.body.data).to.be.an('array') 167 expect(res.body.data).to.be.an('array')
@@ -171,7 +173,7 @@ describe('Test handle downs', function () {
171 173
172 await viewVideo(servers[0].url, videos[0].uuid) 174 await viewVideo(servers[0].url, videos[0].uuid)
173 175
174 await wait(5000) 176 await waitJobs(servers)
175 177
176 const res = await getVideosList(servers[1].url) 178 const res = await getVideosList(servers[1].url)
177 expect(res.body.data).to.be.an('array') 179 expect(res.body.data).to.be.an('array')
@@ -189,7 +191,7 @@ describe('Test handle downs', function () {
189 191
190 await addVideoCommentReply(servers[0].url, servers[0].accessToken, videos[1].uuid, commentIdServer1, 'comment 1-3') 192 await addVideoCommentReply(servers[0].url, servers[0].accessToken, videos[1].uuid, commentIdServer1, 'comment 1-3')
191 193
192 await wait(5000) 194 await waitJobs(servers)
193 195
194 const resVideo = await getVideo(servers[1].url, videos[0].uuid) 196 const resVideo = await getVideo(servers[1].url, videos[0].uuid)
195 expect(resVideo.body).not.to.be.undefined 197 expect(resVideo.body).not.to.be.undefined
@@ -230,7 +232,7 @@ describe('Test handle downs', function () {
230 232
231 await addVideoCommentReply(servers[1].url, servers[1].accessToken, videos[1].uuid, commentIdServer2, 'comment 1-4') 233 await addVideoCommentReply(servers[1].url, servers[1].accessToken, videos[1].uuid, commentIdServer2, 'comment 1-4')
232 234
233 await wait(5000) 235 await waitJobs(servers)
234 236
235 { 237 {
236 const resComment = await getVideoThreadComments(servers[0].url, videos[1].uuid, threadIdServer1) 238 const resComment = await getVideoThreadComments(servers[0].url, videos[1].uuid, threadIdServer1)
@@ -259,10 +261,5 @@ describe('Test handle downs', function () {
259 261
260 after(async function () { 262 after(async function () {
261 killallServers(servers) 263 killallServers(servers)
262
263 // Keep the logs if the test failed
264 if (this['ok']) {
265 await flushTests()
266 }
267 }) 264 })
268}) 265})
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'
4import 'mocha' 4import 'mocha'
5import { flushTests, killallServers, ServerInfo, setAccessTokensToServers, wait } from '../../utils/index' 5import { flushTests, killallServers, ServerInfo, setAccessTokensToServers, wait } from '../../utils/index'
6import { doubleFollow } from '../../utils/server/follows' 6import { doubleFollow } from '../../utils/server/follows'
7import { getJobsList, getJobsListPaginationAndSort } from '../../utils/server/jobs' 7import { getJobsList, getJobsListPaginationAndSort, waitJobs } from '../../utils/server/jobs'
8import { flushAndRunMultipleServers } from '../../utils/server/servers' 8import { flushAndRunMultipleServers } from '../../utils/server/servers'
9import { uploadVideo } from '../../utils/videos/videos' 9import { uploadVideo } from '../../utils/videos/videos'
10import { dateIsValid } from '../../utils/miscs/miscs' 10import { dateIsValid } from '../../utils/miscs/miscs'
@@ -31,7 +31,7 @@ describe('Test jobs', function () {
31 await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video1' }) 31 await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video1' })
32 await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video2' }) 32 await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video2' })
33 33
34 await wait(15000) 34 await waitJobs(servers)
35 }) 35 })
36 36
37 it('Should list jobs', async function () { 37 it('Should list jobs', async function () {
@@ -55,10 +55,5 @@ describe('Test jobs', function () {
55 55
56 after(async function () { 56 after(async function () {
57 killallServers(servers) 57 killallServers(servers)
58
59 // Keep the logs if the test failed
60 if (this['ok']) {
61 await flushTests()
62 }
63 }) 58 })
64}) 59})
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 () {
72 }) 72 })
73 73
74 after(async function () { 74 after(async function () {
75 process.kill(-server.app.pid) 75 killallServers([ server ])
76
77 // Keep the logs if the test failed
78 if (this['ok']) {
79 await flushTests()
80 }
81 }) 76 })
82}) 77})
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 {
17import { flushTests, setAccessTokensToServers } from '../../utils/index' 17import { flushTests, setAccessTokensToServers } from '../../utils/index'
18import { getStats } from '../../utils/server/stats' 18import { getStats } from '../../utils/server/stats'
19import { addVideoCommentThread } from '../../utils/videos/video-comments' 19import { addVideoCommentThread } from '../../utils/videos/video-comments'
20import { waitJobs } from '../../utils/server/jobs'
20 21
21const expect = chai.expect 22const expect = chai.expect
22 23
@@ -46,7 +47,7 @@ describe('Test stats', function () {
46 await viewVideo(servers[0].url, videoUUID) 47 await viewVideo(servers[0].url, videoUUID)
47 48
48 await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken) 49 await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken)
49 await wait(5000) 50 await waitJobs(servers)
50 }) 51 })
51 52
52 it('Should have the correct stats on instance 1', async function () { 53 it('Should have the correct stats on instance 1', async function () {
@@ -93,10 +94,5 @@ describe('Test stats', function () {
93 94
94 after(async function () { 95 after(async function () {
95 killallServers(servers) 96 killallServers(servers)
96
97 // Keep the logs if the test failed
98 if (this['ok']) {
99 await flushTests()
100 }
101 }) 97 })
102}) 98})
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
20import { setAccessTokensToServers } from '../../utils/users/login' 20import { setAccessTokensToServers } from '../../utils/users/login'
21import { User } from '../../../../shared/models/users' 21import { User } from '../../../../shared/models/users'
22import { VideoChannel } from '../../../../shared/models/videos' 22import { VideoChannel } from '../../../../shared/models/videos'
23import { waitJobs } from '../../utils/server/jobs'
23 24
24const expect = chai.expect 25const expect = chai.expect
25 26
@@ -76,7 +77,7 @@ describe('Test users with multiple servers', function () {
76 videoUUID = resVideo.body.video.uuid 77 videoUUID = resVideo.body.video.uuid
77 } 78 }
78 79
79 await wait(5000) 80 await waitJobs(servers)
80 }) 81 })
81 82
82 it('Should be able to update my display name', async function () { 83 it('Should be able to update my display name', async function () {
@@ -92,7 +93,7 @@ describe('Test users with multiple servers', function () {
92 user = res.body 93 user = res.body
93 expect(user.account.displayName).to.equal('my super display name') 94 expect(user.account.displayName).to.equal('my super display name')
94 95
95 await wait(5000) 96 await waitJobs(servers)
96 }) 97 })
97 98
98 it('Should be able to update my description', async function () { 99 it('Should be able to update my description', async function () {
@@ -109,7 +110,7 @@ describe('Test users with multiple servers', function () {
109 expect(user.account.displayName).to.equal('my super display name') 110 expect(user.account.displayName).to.equal('my super display name')
110 expect(user.account.description).to.equal('my super description updated') 111 expect(user.account.description).to.equal('my super description updated')
111 112
112 await wait(5000) 113 await waitJobs(servers)
113 }) 114 })
114 115
115 it('Should be able to update my avatar', async function () { 116 it('Should be able to update my avatar', async function () {
@@ -128,7 +129,7 @@ describe('Test users with multiple servers', function () {
128 129
129 await testImage(servers[0].url, 'avatar2-resized', user.account.avatar.path, '.png') 130 await testImage(servers[0].url, 'avatar2-resized', user.account.avatar.path, '.png')
130 131
131 await wait(5000) 132 await waitJobs(servers)
132 }) 133 })
133 134
134 it('Should have updated my profile on other servers too', async function () { 135 it('Should have updated my profile on other servers too', async function () {
@@ -178,7 +179,7 @@ describe('Test users with multiple servers', function () {
178 179
179 await removeUser(servers[0].url, userId, servers[0].accessToken) 180 await removeUser(servers[0].url, userId, servers[0].accessToken)
180 181
181 await wait(5000) 182 await waitJobs(servers)
182 183
183 for (const server of servers) { 184 for (const server of servers) {
184 const resAccounts = await getAccountsList(server.url, '-createdAt') 185 const resAccounts = await getAccountsList(server.url, '-createdAt')
@@ -209,10 +210,5 @@ describe('Test users with multiple servers', function () {
209 210
210 after(async function () { 211 after(async function () {
211 killallServers(servers) 212 killallServers(servers)
212
213 // Keep the logs if the test failed
214 if (this[ 'ok' ]) {
215 await flushTests()
216 }
217 }) 213 })
218}) 214})
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 {
15 dateIsValid, 15 dateIsValid,
16 doubleFollow, 16 doubleFollow,
17 flushAndRunMultipleServers, 17 flushAndRunMultipleServers,
18 flushTests, getLocalVideos, 18 flushTests,
19 getLocalVideos,
19 getVideo, 20 getVideo,
20 getVideoChannelsList, 21 getVideoChannelsList,
21 getVideosList, 22 getVideosList,
@@ -39,7 +40,7 @@ import {
39 getVideoCommentThreads, 40 getVideoCommentThreads,
40 getVideoThreadComments 41 getVideoThreadComments
41} from '../../utils/videos/video-comments' 42} from '../../utils/videos/video-comments'
42import { getAccountsList } from '../../utils/users/accounts' 43import { waitJobs } from '../../utils/server/jobs'
43 44
44const expect = chai.expect 45const expect = chai.expect
45 46
@@ -102,7 +103,7 @@ describe('Test multiple servers', function () {
102 } 103 }
103 await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) 104 await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
104 105
105 await wait(10000) 106 await waitJobs(servers)
106 107
107 // All servers should have this video 108 // All servers should have this video
108 let publishedAt: string = null 109 let publishedAt: string = null
@@ -177,7 +178,7 @@ describe('Test multiple servers', function () {
177 await uploadVideo(servers[1].url, userAccessToken, videoAttributes) 178 await uploadVideo(servers[1].url, userAccessToken, videoAttributes)
178 179
179 // Transcoding 180 // Transcoding
180 await wait(30000) 181 await waitJobs(servers)
181 182
182 // All servers should have this video 183 // All servers should have this video
183 for (const server of servers) { 184 for (const server of servers) {
@@ -266,7 +267,7 @@ describe('Test multiple servers', function () {
266 } 267 }
267 await uploadVideo(servers[2].url, servers[2].accessToken, videoAttributes2) 268 await uploadVideo(servers[2].url, servers[2].accessToken, videoAttributes2)
268 269
269 await wait(10000) 270 await waitJobs(servers)
270 271
271 // All servers should have this video 272 // All servers should have this video
272 for (const server of servers) { 273 for (const server of servers) {
@@ -496,15 +497,15 @@ describe('Test multiple servers', function () {
496 await viewVideo(servers[2].url, localVideosServer3[1]) 497 await viewVideo(servers[2].url, localVideosServer3[1])
497 498
498 await Promise.all(tasks) 499 await Promise.all(tasks)
499 await wait(1500) 500 await waitJobs(servers)
500 501
501 await viewVideo(servers[2].url, localVideosServer3[0]) 502 await viewVideo(servers[2].url, localVideosServer3[0])
502 503
503 await wait(1500) 504 await waitJobs(servers)
504 505
505 await viewVideo(servers[2].url, localVideosServer3[0]) 506 await viewVideo(servers[2].url, localVideosServer3[0])
506 507
507 await wait(5000) 508 await waitJobs(servers)
508 509
509 for (const server of servers) { 510 for (const server of servers) {
510 const res = await getVideosList(server.url) 511 const res = await getVideosList(server.url)
@@ -535,7 +536,7 @@ describe('Test multiple servers', function () {
535 536
536 await Promise.all(tasks) 537 await Promise.all(tasks)
537 538
538 await wait(10000) 539 await waitJobs(servers)
539 540
540 let baseVideos = null 541 let baseVideos = null
541 542
@@ -572,7 +573,7 @@ describe('Test multiple servers', function () {
572 await wait(200) 573 await wait(200)
573 await rateVideo(servers[2].url, servers[2].accessToken, remoteVideosServer3[0], 'like') 574 await rateVideo(servers[2].url, servers[2].accessToken, remoteVideosServer3[0], 'like')
574 575
575 await wait(10000) 576 await waitJobs(servers)
576 577
577 let baseVideos = null 578 let baseVideos = null
578 for (const server of servers) { 579 for (const server of servers) {
@@ -614,7 +615,7 @@ describe('Test multiple servers', function () {
614 615
615 await updateVideo(servers[2].url, servers[2].accessToken, toRemove[0].id, attributes) 616 await updateVideo(servers[2].url, servers[2].accessToken, toRemove[0].id, attributes)
616 617
617 await wait(5000) 618 await waitJobs(servers)
618 }) 619 })
619 620
620 it('Should have the video 3 updated on each server', async function () { 621 it('Should have the video 3 updated on each server', async function () {
@@ -670,7 +671,7 @@ describe('Test multiple servers', function () {
670 await removeVideo(servers[2].url, servers[2].accessToken, toRemove[0].id) 671 await removeVideo(servers[2].url, servers[2].accessToken, toRemove[0].id)
671 await removeVideo(servers[2].url, servers[2].accessToken, toRemove[1].id) 672 await removeVideo(servers[2].url, servers[2].accessToken, toRemove[1].id)
672 673
673 await wait(5000) 674 await waitJobs(servers)
674 }) 675 })
675 676
676 it('Should not have files of videos 3 and 3-2 on each server', async function () { 677 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 () {
749 await addVideoCommentThread(servers[ 2 ].url, servers[ 2 ].accessToken, videoUUID, text) 750 await addVideoCommentThread(servers[ 2 ].url, servers[ 2 ].accessToken, videoUUID, text)
750 } 751 }
751 752
752 await wait(5000) 753 await waitJobs(servers)
753 754
754 { 755 {
755 const res = await getVideoCommentThreads(servers[1].url, videoUUID, 0, 5) 756 const res = await getVideoCommentThreads(servers[1].url, videoUUID, 0, 5)
@@ -759,7 +760,7 @@ describe('Test multiple servers', function () {
759 await addVideoCommentReply(servers[ 1 ].url, servers[ 1 ].accessToken, videoUUID, threadId, text) 760 await addVideoCommentReply(servers[ 1 ].url, servers[ 1 ].accessToken, videoUUID, threadId, text)
760 } 761 }
761 762
762 await wait(5000) 763 await waitJobs(servers)
763 764
764 { 765 {
765 const res1 = await getVideoCommentThreads(servers[2].url, videoUUID, 0, 5) 766 const res1 = await getVideoCommentThreads(servers[2].url, videoUUID, 0, 5)
@@ -775,7 +776,7 @@ describe('Test multiple servers', function () {
775 await addVideoCommentReply(servers[ 2 ].url, servers[ 2 ].accessToken, videoUUID, childCommentId, text2) 776 await addVideoCommentReply(servers[ 2 ].url, servers[ 2 ].accessToken, videoUUID, childCommentId, text2)
776 } 777 }
777 778
778 await wait(5000) 779 await waitJobs(servers)
779 }) 780 })
780 781
781 it('Should have these threads', async function () { 782 it('Should have these threads', async function () {
@@ -848,7 +849,7 @@ describe('Test multiple servers', function () {
848 849
849 await deleteVideoComment(servers[2].url, servers[2].accessToken, videoUUID, childOfFirstChild.comment.id) 850 await deleteVideoComment(servers[2].url, servers[2].accessToken, videoUUID, childOfFirstChild.comment.id)
850 851
851 await wait(5000) 852 await waitJobs(servers)
852 }) 853 })
853 854
854 it('Should not have this comment anymore', async function () { 855 it('Should not have this comment anymore', async function () {
@@ -877,7 +878,7 @@ describe('Test multiple servers', function () {
877 const threadId = res1.body.data.find(c => c.text === 'my super first comment').id 878 const threadId = res1.body.data.find(c => c.text === 'my super first comment').id
878 await deleteVideoComment(servers[0].url, servers[0].accessToken, videoUUID, threadId) 879 await deleteVideoComment(servers[0].url, servers[0].accessToken, videoUUID, threadId)
879 880
880 await wait(5000) 881 await waitJobs(servers)
881 }) 882 })
882 883
883 it('Should have the thread comments deleted on other servers too', async function () { 884 it('Should have the thread comments deleted on other servers too', async function () {
@@ -910,7 +911,7 @@ describe('Test multiple servers', function () {
910 911
911 await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, attributes) 912 await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, attributes)
912 913
913 await wait(5000) 914 await waitJobs(servers)
914 915
915 for (const server of servers) { 916 for (const server of servers) {
916 const res = await getVideo(server.url, videoUUID) 917 const res = await getVideo(server.url, videoUUID)
@@ -941,7 +942,7 @@ describe('Test multiple servers', function () {
941 await req.attach('videofile', filePath) 942 await req.attach('videofile', filePath)
942 .expect(200) 943 .expect(200)
943 944
944 await wait(40000) 945 await waitJobs(servers)
945 946
946 for (const server of servers) { 947 for (const server of servers) {
947 const res = await getVideosList(server.url) 948 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 () {
54 const maxWidth = 50 54 const maxWidth = 50
55 55
56 const res = await getOEmbed(server.url, oembedUrl, format, maxHeight, maxWidth) 56 const res = await getOEmbed(server.url, oembedUrl, format, maxHeight, maxWidth)
57 const expectedHtml = `<iframe width="50" height="50" src="http://localhost:9001/videos/embed/${server.video.uuid}" ` + 57 const expectedHtml = '<iframe width="50" height="50" sandbox="allow-same-origin allow-scripts" ' +
58 `src="http://localhost:9001/videos/embed/${server.video.uuid}" ` +
58 'frameborder="0" allowfullscreen></iframe>' 59 'frameborder="0" allowfullscreen></iframe>'
59 60
60 expect(res.body.html).to.equal(expectedHtml) 61 expect(res.body.html).to.equal(expectedHtml)
@@ -69,10 +70,5 @@ describe('Test services', function () {
69 70
70 after(async function () { 71 after(async function () {
71 killallServers([ server ]) 72 killallServers([ server ])
72
73 // Keep the logs if the test failed
74 if (this['ok']) {
75 await flushTests()
76 }
77 }) 73 })
78}) 74})
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'
5import 'mocha' 5import 'mocha'
6import { VideoPrivacy } from '../../../../shared/models/videos' 6import { VideoPrivacy } from '../../../../shared/models/videos'
7import { 7import {
8 checkVideoFilesWereRemoved, completeVideoCheck, flushTests, getVideo, getVideoCategories, getVideoLanguages, getVideoLicences, 8 checkVideoFilesWereRemoved,
9 getVideoPrivacies, getVideosList, getVideosListPagination, getVideosListSort, killallServers, rateVideo, removeVideo, runServer, 9 completeVideoCheck,
10 searchVideo, searchVideoWithPagination, searchVideoWithSort, ServerInfo, setAccessTokensToServers, testImage, updateVideo, uploadVideo, 10 flushTests,
11 viewVideo, wait 11 getVideo,
12 getVideoCategories,
13 getVideoLanguages,
14 getVideoLicences,
15 getVideoPrivacies,
16 getVideosList,
17 getVideosListPagination,
18 getVideosListSort,
19 killallServers,
20 rateVideo,
21 removeVideo,
22 runServer,
23 searchVideo,
24 searchVideoWithPagination,
25 searchVideoWithSort,
26 ServerInfo,
27 setAccessTokensToServers,
28 testImage,
29 updateVideo,
30 uploadVideo,
31 viewVideo,
32 wait
12} from '../../utils' 33} from '../../utils'
13 34
14const expect = chai.expect 35const 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'
5import { VideoAbuse } from '../../../../shared/models/videos' 5import { VideoAbuse } from '../../../../shared/models/videos'
6import { 6import {
7 flushAndRunMultipleServers, 7 flushAndRunMultipleServers,
8 flushTests,
9 getVideoAbusesList, 8 getVideoAbusesList,
10 getVideosList, 9 getVideosList,
11 killallServers, 10 killallServers,
12 reportVideoAbuse, 11 reportVideoAbuse,
13 ServerInfo, 12 ServerInfo,
14 setAccessTokensToServers, 13 setAccessTokensToServers,
15 uploadVideo, 14 uploadVideo
16 wait
17} from '../../utils/index' 15} from '../../utils/index'
18import { doubleFollow } from '../../utils/server/follows' 16import { doubleFollow } from '../../utils/server/follows'
17import { waitJobs } from '../../utils/server/jobs'
19 18
20const expect = chai.expect 19const expect = chai.expect
21 20
@@ -48,7 +47,7 @@ describe('Test video abuses', function () {
48 await uploadVideo(servers[1].url, servers[1].accessToken, video2Attributes) 47 await uploadVideo(servers[1].url, servers[1].accessToken, video2Attributes)
49 48
50 // Wait videos propagation, server 2 has transcoding enabled 49 // Wait videos propagation, server 2 has transcoding enabled
51 await wait(15000) 50 await waitJobs(servers)
52 51
53 const res = await getVideosList(servers[0].url) 52 const res = await getVideosList(servers[0].url)
54 const videos = res.body.data 53 const videos = res.body.data
@@ -68,13 +67,13 @@ describe('Test video abuses', function () {
68 }) 67 })
69 68
70 it('Should report abuse on a local video', async function () { 69 it('Should report abuse on a local video', async function () {
71 this.timeout(10000) 70 this.timeout(15000)
72 71
73 const reason = 'my super bad reason' 72 const reason = 'my super bad reason'
74 await reportVideoAbuse(servers[0].url, servers[0].accessToken, servers[0].video.id, reason) 73 await reportVideoAbuse(servers[0].url, servers[0].accessToken, servers[0].video.id, reason)
75 74
76 // We wait requests propagation, even if the server 1 is not supposed to make a request to server 2 75 // We wait requests propagation, even if the server 1 is not supposed to make a request to server 2
77 await wait(5000) 76 await waitJobs(servers)
78 }) 77 })
79 78
80 it('Should have 1 video abuses on server 1 and 0 on server 2', async function () { 79 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 () {
103 await reportVideoAbuse(servers[0].url, servers[0].accessToken, servers[1].video.id, reason) 102 await reportVideoAbuse(servers[0].url, servers[0].accessToken, servers[1].video.id, reason)
104 103
105 // We wait requests propagation 104 // We wait requests propagation
106 await wait(5000) 105 await waitJobs(servers)
107 }) 106 })
108 107
109 it('Should have 2 video abuse on server 1 and 1 on server 2', async function () { 108 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 () {
137 136
138 after(async function () { 137 after(async function () {
139 killallServers(servers) 138 killallServers(servers)
140
141 // Keep the logs if the test failed
142 if (this['ok']) {
143 await flushTests()
144 }
145 }) 139 })
146}) 140})
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'
6import { 6import {
7 addVideoToBlacklist, 7 addVideoToBlacklist,
8 flushAndRunMultipleServers, 8 flushAndRunMultipleServers,
9 flushTests,
10 getBlacklistedVideosList, 9 getBlacklistedVideosList,
11 getSortedBlacklistedVideosList, 10 getSortedBlacklistedVideosList,
12 getVideosList, 11 getVideosList,
@@ -14,10 +13,10 @@ import {
14 removeVideoFromBlacklist, 13 removeVideoFromBlacklist,
15 ServerInfo, 14 ServerInfo,
16 setAccessTokensToServers, 15 setAccessTokensToServers,
17 uploadVideo, 16 uploadVideo
18 wait
19} from '../../utils/index' 17} from '../../utils/index'
20import { doubleFollow } from '../../utils/server/follows' 18import { doubleFollow } from '../../utils/server/follows'
19import { waitJobs } from '../../utils/server/jobs'
21 20
22const expect = chai.expect 21const expect = chai.expect
23const orderBy = lodash.orderBy 22const orderBy = lodash.orderBy
@@ -51,7 +50,7 @@ describe('Test video blacklist management', function () {
51 await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'My 2nd video', description: 'A video on server 2' }) 50 await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'My 2nd video', description: 'A video on server 2' })
52 51
53 // Wait videos propagation, server 2 has transcoding enabled 52 // Wait videos propagation, server 2 has transcoding enabled
54 await wait(15000) 53 await waitJobs(servers)
55 54
56 // Blacklist the two videos on server 1 55 // Blacklist the two videos on server 1
57 await blacklistVideosOnServer(servers[0]) 56 await blacklistVideosOnServer(servers[0])
@@ -154,9 +153,5 @@ describe('Test video blacklist management', function () {
154 153
155 after(async function () { 154 after(async function () {
156 killallServers(servers) 155 killallServers(servers)
157
158 if (this['ok']) {
159 await flushTests()
160 }
161 }) 156 })
162}) 157})
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'
5import { 5import {
6 addVideoToBlacklist, 6 addVideoToBlacklist,
7 flushAndRunMultipleServers, 7 flushAndRunMultipleServers,
8 flushTests,
9 getVideosList, 8 getVideosList,
10 killallServers, 9 killallServers,
11 searchVideo, 10 searchVideo,
12 ServerInfo, 11 ServerInfo,
13 setAccessTokensToServers, 12 setAccessTokensToServers,
14 uploadVideo, 13 uploadVideo
15 wait
16} from '../../utils/index' 14} from '../../utils/index'
17import { doubleFollow } from '../../utils/server/follows' 15import { doubleFollow } from '../../utils/server/follows'
16import { waitJobs } from '../../utils/server/jobs'
18 17
19const expect = chai.expect 18const expect = chai.expect
20 19
@@ -41,7 +40,7 @@ describe('Test video blacklists', function () {
41 await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) 40 await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes)
42 41
43 // Wait videos propagation, server 2 has transcoding enabled 42 // Wait videos propagation, server 2 has transcoding enabled
44 await wait(10000) 43 await waitJobs(servers)
45 44
46 const res = await getVideosList(servers[0].url) 45 const res = await getVideosList(servers[0].url)
47 const videos = res.body.data 46 const videos = res.body.data
@@ -89,10 +88,5 @@ describe('Test video blacklists', function () {
89 88
90 after(async function () { 89 after(async function () {
91 killallServers(servers) 90 killallServers(servers)
92
93 // Keep the logs if the test failed
94 if (this['ok']) {
95 await flushTests()
96 }
97 }) 91 })
98}) 92})
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 @@
3import * as chai from 'chai' 3import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { User, Video } from '../../../../shared/index' 5import { User, Video } from '../../../../shared/index'
6import { doubleFollow, flushAndRunMultipleServers, getVideoChannelVideos, updateVideo, uploadVideo, wait } from '../../utils' 6import { doubleFollow, flushAndRunMultipleServers, getVideoChannelVideos, updateVideo, uploadVideo } from '../../utils'
7import { 7import {
8 addVideoChannel, 8 addVideoChannel,
9 deleteVideoChannel, 9 deleteVideoChannel,
@@ -17,6 +17,7 @@ import {
17 setAccessTokensToServers, 17 setAccessTokensToServers,
18 updateVideoChannel 18 updateVideoChannel
19} from '../../utils/index' 19} from '../../utils/index'
20import { waitJobs } from '../../utils/server/jobs'
20 21
21const expect = chai.expect 22const expect = chai.expect
22 23
@@ -49,7 +50,7 @@ describe('Test video channels', function () {
49 firstVideoChannelUUID = user.videoChannels[0].uuid 50 firstVideoChannelUUID = user.videoChannels[0].uuid
50 } 51 }
51 52
52 await wait(5000) 53 await waitJobs(servers)
53 }) 54 })
54 55
55 it('Should have one video channel (created with root)', async () => { 56 it('Should have one video channel (created with root)', async () => {
@@ -80,7 +81,7 @@ describe('Test video channels', function () {
80 videoUUID = res.body.video.uuid 81 videoUUID = res.body.video.uuid
81 } 82 }
82 83
83 await wait(3000) 84 await waitJobs(servers)
84 }) 85 })
85 86
86 it('Should have two video channels when getting my information', async () => { 87 it('Should have two video channels when getting my information', async () => {
@@ -142,7 +143,7 @@ describe('Test video channels', function () {
142 143
143 await updateVideoChannel(servers[0].url, servers[0].accessToken, secondVideoChannelId, videoChannelAttributes) 144 await updateVideoChannel(servers[0].url, servers[0].accessToken, secondVideoChannelId, videoChannelAttributes)
144 145
145 await wait(3000) 146 await waitJobs(servers)
146 }) 147 })
147 148
148 it('Should have video channel updated', async function () { 149 it('Should have video channel updated', async function () {
@@ -184,7 +185,7 @@ describe('Test video channels', function () {
184 185
185 await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { channelId: firstVideoChannelId }) 186 await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { channelId: firstVideoChannelId })
186 187
187 await wait(5000) 188 await waitJobs(servers)
188 }) 189 })
189 190
190 it('Should list the first video channel videos', async function () { 191 it('Should list the first video channel videos', async function () {
@@ -219,10 +220,5 @@ describe('Test video channels', function () {
219 220
220 after(async function () { 221 after(async function () {
221 killallServers(servers) 222 killallServers(servers)
222
223 // Keep the logs if the test failed
224 if (this['ok']) {
225 await flushTests()
226 }
227 }) 223 })
228}) 224})
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'
5import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model' 5import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model'
6import { testImage } from '../../utils' 6import { testImage } from '../../utils'
7import { 7import {
8 dateIsValid, flushTests, killallServers, runServer, ServerInfo, setAccessTokensToServers, updateMyAvatar, 8 dateIsValid,
9 flushTests,
10 killallServers,
11 runServer,
12 ServerInfo,
13 setAccessTokensToServers,
14 updateMyAvatar,
9 uploadVideo 15 uploadVideo
10} from '../../utils/index' 16} from '../../utils/index'
11import { 17import {
12 addVideoCommentReply, addVideoCommentThread, deleteVideoComment, getVideoCommentThreads, 18 addVideoCommentReply,
19 addVideoCommentThread,
20 deleteVideoComment,
21 getVideoCommentThreads,
13 getVideoThreadComments 22 getVideoThreadComments
14} from '../../utils/videos/video-comments' 23} from '../../utils/videos/video-comments'
15 24
@@ -194,10 +203,5 @@ describe('Test video comments', function () {
194 203
195 after(async function () { 204 after(async function () {
196 killallServers([ server ]) 205 killallServers([ server ])
197
198 // Keep the logs if the test failed
199 if (this['ok']) {
200 await flushTests()
201 }
202 }) 206 })
203}) 207})
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'
4import 'mocha' 4import 'mocha'
5import { 5import {
6 flushAndRunMultipleServers, 6 flushAndRunMultipleServers,
7 flushTests,
8 getVideo, 7 getVideo,
9 getVideoDescription, 8 getVideoDescription,
10 getVideosList, 9 getVideosList,
@@ -12,10 +11,10 @@ import {
12 ServerInfo, 11 ServerInfo,
13 setAccessTokensToServers, 12 setAccessTokensToServers,
14 updateVideo, 13 updateVideo,
15 uploadVideo, 14 uploadVideo
16 wait
17} from '../../utils/index' 15} from '../../utils/index'
18import { doubleFollow } from '../../utils/server/follows' 16import { doubleFollow } from '../../utils/server/follows'
17import { waitJobs } from '../../utils/server/jobs'
19 18
20const expect = chai.expect 19const expect = chai.expect
21 20
@@ -46,7 +45,7 @@ describe('Test video description', function () {
46 } 45 }
47 await uploadVideo(servers[0].url, servers[0].accessToken, attributes) 46 await uploadVideo(servers[0].url, servers[0].accessToken, attributes)
48 47
49 await wait(5000) 48 await waitJobs(servers)
50 49
51 const res = await getVideosList(servers[0].url) 50 const res = await getVideosList(servers[0].url)
52 51
@@ -85,7 +84,7 @@ describe('Test video description', function () {
85 } 84 }
86 await updateVideo(servers[0].url, servers[0].accessToken, videoId, attributes) 85 await updateVideo(servers[0].url, servers[0].accessToken, videoId, attributes)
87 86
88 await wait(5000) 87 await waitJobs(servers)
89 }) 88 })
90 89
91 it('Should have a small description on each server', async function () { 90 it('Should have a small description on each server', async function () {
@@ -102,10 +101,5 @@ describe('Test video description', function () {
102 101
103 after(async function () { 102 after(async function () {
104 killallServers(servers) 103 killallServers(servers)
105
106 // Keep the logs if the test failed
107 if (this['ok']) {
108 await flushTests()
109 }
110 }) 104 })
111}) 105})
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'
8import { getMyVideos } from '../../utils/videos/videos' 8import { getMyVideos } from '../../utils/videos/videos'
9import { 9import {
10 getAccountVideos, 10 getAccountVideos,
11 getConfig, getCustomConfig, 11 getConfig,
12 getMyUserInformation, getVideoChannelVideos, 12 getCustomConfig,
13 getMyUserInformation,
14 getVideoChannelVideos,
13 getVideosListWithToken, 15 getVideosListWithToken,
14 runServer, 16 runServer,
15 searchVideo, 17 searchVideo,
16 searchVideoWithToken, updateCustomConfig, 18 searchVideoWithToken,
19 updateCustomConfig,
17 updateMyUser 20 updateMyUser
18} from '../../utils' 21} from '../../utils'
19import { ServerConfig } from '../../../../shared/models' 22import { ServerConfig } from '../../../../shared/models'
@@ -201,10 +204,5 @@ describe('Test video NSFW policy', function () {
201 204
202 after(async function () { 205 after(async function () {
203 killallServers([ server ]) 206 killallServers([ server ])
204
205 // Keep the logs if the test failed
206 if (this['ok']) {
207 await flushTests()
208 }
209 }) 207 })
210}) 208})
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'
5import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum' 5import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum'
6import { 6import {
7 flushAndRunMultipleServers, 7 flushAndRunMultipleServers,
8 flushTests,
9 getVideosList, 8 getVideosList,
10 killallServers, 9 killallServers,
11 ServerInfo, 10 ServerInfo,
12 setAccessTokensToServers, 11 setAccessTokensToServers,
13 uploadVideo, 12 uploadVideo
14 wait
15} from '../../utils/index' 13} from '../../utils/index'
16import { doubleFollow } from '../../utils/server/follows' 14import { doubleFollow } from '../../utils/server/follows'
17import { userLogin } from '../../utils/users/login' 15import { userLogin } from '../../utils/users/login'
18import { createUser } from '../../utils/users/users' 16import { createUser } from '../../utils/users/users'
19import { getMyVideos, getVideo, getVideoWithToken, updateVideo } from '../../utils/videos/videos' 17import { getMyVideos, getVideo, getVideoWithToken, updateVideo } from '../../utils/videos/videos'
18import { waitJobs } from '../../utils/server/jobs'
20 19
21const expect = chai.expect 20const expect = chai.expect
22 21
@@ -48,7 +47,7 @@ describe('Test video privacy', function () {
48 } 47 }
49 await uploadVideo(servers[0].url, servers[0].accessToken, attributes) 48 await uploadVideo(servers[0].url, servers[0].accessToken, attributes)
50 49
51 await wait(5000) 50 await waitJobs(servers)
52 }) 51 })
53 52
54 it('Should not have this private video on server 2', async function () { 53 it('Should not have this private video on server 2', async function () {
@@ -99,7 +98,7 @@ describe('Test video privacy', function () {
99 await uploadVideo(servers[1].url, servers[1].accessToken, attributes) 98 await uploadVideo(servers[1].url, servers[1].accessToken, attributes)
100 99
101 // Server 2 has transcoding enabled 100 // Server 2 has transcoding enabled
102 await wait(10000) 101 await waitJobs(servers)
103 }) 102 })
104 103
105 it('Should not have this unlisted video listed on server 1 and 2', async function () { 104 it('Should not have this unlisted video listed on server 1 and 2', async function () {
@@ -139,7 +138,7 @@ describe('Test video privacy', function () {
139 now = Date.now() 138 now = Date.now()
140 await updateVideo(servers[0].url, servers[0].accessToken, privateVideoId, attribute) 139 await updateVideo(servers[0].url, servers[0].accessToken, privateVideoId, attribute)
141 140
142 await wait(5000) 141 await waitJobs(servers)
143 }) 142 })
144 143
145 it('Should have this new public video listed on server 1 and 2', async function () { 144 it('Should have this new public video listed on server 1 and 2', async function () {
@@ -155,10 +154,5 @@ describe('Test video privacy', function () {
155 154
156 after(async function () { 155 after(async function () {
157 killallServers(servers) 156 killallServers(servers)
158
159 // Keep the logs if the test failed
160 if (this['ok']) {
161 await flushTests()
162 }
163 }) 157 })
164}) 158})
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'
7import { 7import {
8 doubleFollow, 8 doubleFollow,
9 flushAndRunMultipleServers, 9 flushAndRunMultipleServers,
10 flushTests,
11 getMyVideos, 10 getMyVideos,
12 getVideo, 11 getVideo,
13 getVideosList, 12 getVideosList,
@@ -16,10 +15,10 @@ import {
16 ServerInfo, 15 ServerInfo,
17 setAccessTokensToServers, 16 setAccessTokensToServers,
18 uploadVideo, 17 uploadVideo,
19 wait,
20 webtorrentAdd 18 webtorrentAdd
21} from '../../utils' 19} from '../../utils'
22import { join } from 'path' 20import { join } from 'path'
21import { waitJobs } from '../../utils/server/jobs'
23 22
24const expect = chai.expect 23const expect = chai.expect
25 24
@@ -45,7 +44,7 @@ describe('Test video transcoding', function () {
45 } 44 }
46 await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) 45 await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
47 46
48 await wait(10000) 47 await waitJobs(servers)
49 48
50 const res = await getVideosList(servers[0].url) 49 const res = await getVideosList(servers[0].url)
51 const video = res.body.data[0] 50 const video = res.body.data[0]
@@ -73,7 +72,7 @@ describe('Test video transcoding', function () {
73 } 72 }
74 await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) 73 await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes)
75 74
76 await wait(20000) 75 await waitJobs(servers)
77 76
78 const res = await getVideosList(servers[1].url) 77 const res = await getVideosList(servers[1].url)
79 78
@@ -102,7 +101,7 @@ describe('Test video transcoding', function () {
102 } 101 }
103 await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) 102 await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes)
104 103
105 await wait(20000) 104 await waitJobs(servers)
106 105
107 const res = await getVideosList(servers[1].url) 106 const res = await getVideosList(servers[1].url)
108 107
@@ -125,7 +124,7 @@ describe('Test video transcoding', function () {
125 124
126 await doubleFollow(servers[0], servers[1]) 125 await doubleFollow(servers[0], servers[1])
127 126
128 await wait(15000) 127 await waitJobs(servers)
129 128
130 { 129 {
131 // Upload the video, but wait transcoding 130 // Upload the video, but wait transcoding
@@ -161,7 +160,7 @@ describe('Test video transcoding', function () {
161 await getVideo(servers[0].url, videoId, 404) 160 await getVideo(servers[0].url, videoId, 404)
162 } 161 }
163 162
164 await wait(30000) 163 await waitJobs(servers)
165 164
166 for (const server of servers) { 165 for (const server of servers) {
167 const res = await getVideosList(server.url) 166 const res = await getVideosList(server.url)
@@ -179,10 +178,5 @@ describe('Test video transcoding', function () {
179 178
180 after(async function () { 179 after(async function () {
181 killallServers(servers) 180 killallServers(servers)
182
183 // Keep the logs if the test failed
184 if (this['ok']) {
185 await flushTests()
186 }
187 }) 181 })
188}) 182})
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 {
14 killallServers, 14 killallServers,
15 ServerInfo, 15 ServerInfo,
16 setAccessTokensToServers, 16 setAccessTokensToServers,
17 uploadVideo, 17 uploadVideo
18 wait
19} from '../utils' 18} from '../utils'
19import { waitJobs } from '../utils/server/jobs'
20 20
21const expect = chai.expect 21const expect = chai.expect
22 22
@@ -54,14 +54,14 @@ describe('Test create import video jobs', function () {
54 video2UUID = res2.body.video.uuid 54 video2UUID = res2.body.video.uuid
55 55
56 // Transcoding 56 // Transcoding
57 await wait(40000) 57 await waitJobs(servers)
58 }) 58 })
59 59
60 it('Should run a import job on video 1 with a lower resolution', async function () { 60 it('Should run a import job on video 1 with a lower resolution', async function () {
61 const env = getEnvCli(servers[0]) 61 const env = getEnvCli(servers[0])
62 await execCLI(`${env} npm run create-import-video-file-job -- -v ${video1UUID} -i server/tests/fixtures/video_short-480.webm`) 62 await execCLI(`${env} npm run create-import-video-file-job -- -v ${video1UUID} -i server/tests/fixtures/video_short-480.webm`)
63 63
64 await wait(30000) 64 await waitJobs(servers)
65 65
66 let magnetUri: string 66 let magnetUri: string
67 for (const server of servers) { 67 for (const server of servers) {
@@ -85,7 +85,7 @@ describe('Test create import video jobs', function () {
85 const env = getEnvCli(servers[1]) 85 const env = getEnvCli(servers[1])
86 await execCLI(`${env} npm run create-import-video-file-job -- -v ${video2UUID} -i server/tests/fixtures/video_short.ogv`) 86 await execCLI(`${env} npm run create-import-video-file-job -- -v ${video2UUID} -i server/tests/fixtures/video_short.ogv`)
87 87
88 await wait(30000) 88 await waitJobs(servers)
89 89
90 let magnetUri: string 90 let magnetUri: string
91 for (const server of servers) { 91 for (const server of servers) {
@@ -111,7 +111,7 @@ describe('Test create import video jobs', function () {
111 const env = getEnvCli(servers[0]) 111 const env = getEnvCli(servers[0])
112 await execCLI(`${env} npm run create-import-video-file-job -- -v ${video1UUID} -i server/tests/fixtures/video_short2.webm`) 112 await execCLI(`${env} npm run create-import-video-file-job -- -v ${video1UUID} -i server/tests/fixtures/video_short2.webm`)
113 113
114 await wait(30000) 114 await waitJobs(servers)
115 115
116 let magnetUri: string 116 let magnetUri: string
117 for (const server of servers) { 117 for (const server of servers) {
@@ -133,10 +133,5 @@ describe('Test create import video jobs', function () {
133 133
134 after(async function () { 134 after(async function () {
135 killallServers(servers) 135 killallServers(servers)
136
137 // Keep the logs if the test failed
138 if (this['ok']) {
139 await flushTests()
140 }
141 }) 136 })
142}) 137})
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 @@
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { VideoDetails } from '../../../shared/models/videos' 5import { VideoDetails } from '../../../shared/models/videos'
6const expect = chai.expect
7
8import { 6import {
7 doubleFollow,
9 execCLI, 8 execCLI,
9 flushAndRunMultipleServers,
10 flushTests, 10 flushTests,
11 getEnvCli, 11 getEnvCli,
12 getVideo,
12 getVideosList, 13 getVideosList,
13 killallServers, 14 killallServers,
14 parseTorrentVideo,
15 runServer,
16 ServerInfo, 15 ServerInfo,
17 setAccessTokensToServers, 16 setAccessTokensToServers,
18 uploadVideo, 17 uploadVideo, wait
19 wait,
20 getVideo, flushAndRunMultipleServers, doubleFollow
21} from '../utils' 18} from '../utils'
19import { waitJobs } from '../utils/server/jobs'
20
21const expect = chai.expect
22 22
23describe('Test create transcoding jobs', function () { 23describe('Test create transcoding jobs', function () {
24 let servers: ServerInfo[] = [] 24 let servers: ServerInfo[] = []
@@ -40,7 +40,7 @@ describe('Test create transcoding jobs', function () {
40 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video2' }) 40 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video2' })
41 video2UUID = res.body.video.uuid 41 video2UUID = res.body.video.uuid
42 42
43 await wait(3000) 43 await waitJobs(servers)
44 }) 44 })
45 45
46 it('Should have two video files on each server', async function () { 46 it('Should have two video files on each server', async function () {
@@ -65,7 +65,7 @@ describe('Test create transcoding jobs', function () {
65 const env = getEnvCli(servers[0]) 65 const env = getEnvCli(servers[0])
66 await execCLI(`${env} npm run create-transcoding-job -- -v ${video2UUID}`) 66 await execCLI(`${env} npm run create-transcoding-job -- -v ${video2UUID}`)
67 67
68 await wait(40000) 68 await waitJobs(servers)
69 69
70 for (const server of servers) { 70 for (const server of servers) {
71 const res = await getVideosList(server.url) 71 const res = await getVideosList(server.url)
@@ -102,10 +102,5 @@ describe('Test create transcoding jobs', function () {
102 102
103 after(async function () { 103 after(async function () {
104 killallServers(servers) 104 killallServers(servers)
105
106 // Keep the logs if the test failed
107 if (this['ok']) {
108 await flushTests()
109 }
110 }) 105 })
111}) 106})
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 () {
36 36
37 after(async function () { 37 after(async function () {
38 killallServers([ server ]) 38 killallServers([ server ])
39
40 // Keep the logs if the test failed
41 if (this['ok']) {
42 await flushTests()
43 }
44 }) 39 })
45}) 40})
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 @@
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { VideoDetails } from '../../../shared/models/videos' 5import { VideoDetails } from '../../../shared/models/videos'
6const expect = chai.expect
7
8import { 6import {
9 execCLI, 7 execCLI,
10 flushTests, 8 flushTests,
11 getEnvCli, 9 getEnvCli,
10 getVideo,
12 getVideosList, 11 getVideosList,
13 killallServers, 12 killallServers,
14 parseTorrentVideo, 13 parseTorrentVideo,
15 runServer, 14 runServer,
16 ServerInfo, 15 ServerInfo,
17 setAccessTokensToServers, 16 setAccessTokensToServers,
18 uploadVideo, 17 uploadVideo
19 wait,
20 getVideo
21} from '../utils' 18} from '../utils'
19import { waitJobs } from '../utils/server/jobs'
20
21const expect = chai.expect
22 22
23describe('Test update host scripts', function () { 23describe('Test update host scripts', function () {
24 let server: ServerInfo 24 let server: ServerInfo
@@ -41,7 +41,8 @@ describe('Test update host scripts', function () {
41 const videoAttributes = {} 41 const videoAttributes = {}
42 await uploadVideo(server.url, server.accessToken, videoAttributes) 42 await uploadVideo(server.url, server.accessToken, videoAttributes)
43 await uploadVideo(server.url, server.accessToken, videoAttributes) 43 await uploadVideo(server.url, server.accessToken, videoAttributes)
44 await wait(30000) 44
45 await waitJobs(server)
45 }) 46 })
46 47
47 it('Should update torrent hosts', async function () { 48 it('Should update torrent hosts', async function () {
@@ -82,10 +83,5 @@ describe('Test update host scripts', function () {
82 83
83 after(async function () { 84 after(async function () {
84 killallServers([ server ]) 85 killallServers([ server ])
85
86 // Keep the logs if the test failed
87 if (this['ok']) {
88 await flushTests()
89 }
90 }) 86 })
91}) 87})
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 {
11 runServer, 11 runServer,
12 serverLogin, 12 serverLogin,
13 uploadVideo, 13 uploadVideo,
14 getVideosList, updateCustomConfig, getCustomConfig 14 getVideosList, updateCustomConfig, getCustomConfig, killallServers
15} from './utils' 15} from './utils'
16 16
17describe('Test a client controllers', function () { 17describe('Test a client controllers', function () {
@@ -102,11 +102,6 @@ describe('Test a client controllers', function () {
102 }) 102 })
103 103
104 after(async function () { 104 after(async function () {
105 process.kill(-server.app.pid) 105 killallServers([ server ])
106
107 // Keep the logs if the test failed
108 if (this['ok']) {
109 await flushTests()
110 }
111 }) 106 })
112}) 107})
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 {
11 killallServers, 11 killallServers,
12 ServerInfo, 12 ServerInfo,
13 setAccessTokensToServers, 13 setAccessTokensToServers,
14 uploadVideo, 14 uploadVideo
15 wait
16} from '../utils' 15} from '../utils'
17import { join } from 'path' 16import { join } from 'path'
18import * as libxmljs from 'libxmljs' 17import * as libxmljs from 'libxmljs'
19import { addVideoCommentThread } from '../utils/videos/video-comments' 18import { addVideoCommentThread } from '../utils/videos/video-comments'
19import { waitJobs } from '../utils/server/jobs'
20 20
21chai.use(require('chai-xml')) 21chai.use(require('chai-xml'))
22chai.use(require('chai-json-schema')) 22chai.use(require('chai-json-schema'))
@@ -46,7 +46,7 @@ describe('Test syndication feeds', () => {
46 await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoId, 'super comment 1') 46 await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoId, 'super comment 1')
47 await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoId, 'super comment 2') 47 await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoId, 'super comment 2')
48 48
49 await wait(10000) 49 await waitJobs(servers)
50 }) 50 })
51 51
52 describe('All feed', function () { 52 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'
5import * as request from 'supertest' 5import * as request from 'supertest'
6import * as WebTorrent from 'webtorrent' 6import * as WebTorrent from 'webtorrent'
7import { readFileBufferPromise } from '../../../helpers/core-utils' 7import { readFileBufferPromise } from '../../../helpers/core-utils'
8import { ServerInfo } from '..'
8 9
9const expect = chai.expect 10const expect = chai.expect
10let webtorrent = new WebTorrent() 11let 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 @@
1import * as request from 'supertest' 1import * as request from 'supertest'
2import { wait } from '../miscs/miscs' 2import { wait } from '../miscs/miscs'
3import { ServerInfo } from './servers' 3import { ServerInfo } from './servers'
4import { waitJobs } from './jobs'
4 5
5function getFollowersListPaginationAndSort (url: string, start: number, count: number, sort: string) { 6function getFollowersListPaginationAndSort (url: string, start: number, count: number, sort: string) {
6 const path = '/api/v1/server/followers' 7 const path = '/api/v1/server/followers'
@@ -61,7 +62,7 @@ async function doubleFollow (server1: ServerInfo, server2: ServerInfo) {
61 ]) 62 ])
62 63
63 // Wait request propagation 64 // Wait request propagation
64 await wait(10000) 65 await waitJobs([ server1, server2 ])
65 66
66 return true 67 return true
67} 68}
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 @@
1import * as request from 'supertest' 1import * as request from 'supertest'
2import { JobState } from '../../../../shared/models' 2import { JobState } from '../../../../shared/models'
3import { ServerInfo, wait } from '../index'
3 4
4function getJobsList (url: string, accessToken: string, state: JobState) { 5function getJobsList (url: string, accessToken: string, state: JobState) {
5 const path = '/api/v1/jobs/' + state 6 const path = '/api/v1/jobs/' + state
@@ -26,9 +27,49 @@ function getJobsListPaginationAndSort (url: string, accessToken: string, state:
26 .expect('Content-Type', /json/) 27 .expect('Content-Type', /json/)
27} 28}
28 29
30async function waitJobs (serversArg: ServerInfo[] | ServerInfo) {
31 let servers: ServerInfo[]
32
33 if (Array.isArray(serversArg) === false) servers = [ serversArg as ServerInfo ]
34 else servers = serversArg as ServerInfo[]
35
36 const states: JobState[] = [ 'inactive', 'active', 'delayed' ]
37 const tasks: Promise<any>[] = []
38 let pendingRequests: boolean
39
40 do {
41 pendingRequests = false
42
43 // Check if each server has pending request
44 for (const server of servers) {
45 for (const state of states) {
46 const p = getJobsListPaginationAndSort(server.url, server.accessToken, state, 0, 10, '-createdAt')
47 .then(res => {
48 if (res.body.total > 0) pendingRequests = true
49 })
50 tasks.push(p)
51 }
52 }
53
54 await Promise.all(tasks)
55
56 // Retry, in case of new jobs were created
57 if (pendingRequests === false) {
58 await wait(1000)
59
60 await Promise.all(tasks)
61 }
62
63 if (pendingRequests) {
64 await wait(1000)
65 }
66 } while (pendingRequests)
67}
68
29// --------------------------------------------------------------------------- 69// ---------------------------------------------------------------------------
30 70
31export { 71export {
32 getJobsList, 72 getJobsList,
73 waitJobs,
33 getJobsListPaginationAndSort 74 getJobsListPaginationAndSort
34} 75}