aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/real-world
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/real-world')
-rw-r--r--server/tests/real-world/real-world.ts102
1 files changed, 75 insertions, 27 deletions
diff --git a/server/tests/real-world/real-world.ts b/server/tests/real-world/real-world.ts
index a200bd02d..e225a1266 100644
--- a/server/tests/real-world/real-world.ts
+++ b/server/tests/real-world/real-world.ts
@@ -1,11 +1,10 @@
1import * as program from 'commander' 1import * as program from 'commander'
2import { isEqual, differenceWith } from 'lodash'
3 2
4// /!\ Before imports /!\ 3// /!\ Before imports /!\
5process.env.NODE_ENV = 'test' 4process.env.NODE_ENV = 'test'
6 5
7import { REQUESTS_INTERVAL } from '../../initializers/constants' 6import { REQUESTS_INTERVAL } from '../../initializers/constants'
8import { Video, VideoRateType } from '../../../shared' 7import { Video, VideoRateType, VideoFile } from '../../../shared'
9import { 8import {
10 ServerInfo as DefaultServerInfo, 9 ServerInfo as DefaultServerInfo,
11 flushAndRunMultipleServers, 10 flushAndRunMultipleServers,
@@ -121,12 +120,14 @@ async function start () {
121 checking = true 120 checking = true
122 121
123 const waitingInterval = setInterval(async () => { 122 const waitingInterval = setInterval(async () => {
124 const awaitingRequests = await isThereAwaitingRequests(servers) 123 const pendingRequests = await isTherePendingRequests(servers)
125 if (awaitingRequests === true) { 124 if (pendingRequests === true) {
126 console.log('A server has awaiting requests, waiting...') 125 console.log('A server has pending requests, waiting...')
127 return 126 return
128 } 127 }
129 128
129 // Even if there are no pending request, wait some potential processes
130 await wait(2000)
130 await checkIntegrity(servers) 131 await checkIntegrity(servers)
131 132
132 initializeRequestsPerServer(servers) 133 initializeRequestsPerServer(servers)
@@ -212,7 +213,7 @@ async function update (servers: ServerInfo[], numServer: number) {
212 213
213async function remove (servers: ServerInfo[], numServer: number) { 214async function remove (servers: ServerInfo[], numServer: number) {
214 const res = await getVideosList(servers[numServer].url) 215 const res = await getVideosList(servers[numServer].url)
215 const videos = res.body.data 216 const videos = res.body.data.filter(video => video.isLocal === true)
216 if (videos.length === 0) return undefined 217 if (videos.length === 0) return undefined
217 218
218 const toRemove = videos[getRandomInt(0, videos.length)].id 219 const toRemove = videos[getRandomInt(0, videos.length)].id
@@ -259,19 +260,7 @@ async function checkIntegrity (servers: ServerInfo[]) {
259 260
260 // Fetch all videos and remove some fields that can differ between pods 261 // Fetch all videos and remove some fields that can differ between pods
261 for (const server of servers) { 262 for (const server of servers) {
262 const p = getAllVideosListBy(server.url).then(res => { 263 const p = getAllVideosListBy(server.url).then(res => videos.push(res.body.data))
263 const serverVideos = res.body.data
264 for (const serverVideo of serverVideos) {
265 delete serverVideo.id
266 delete serverVideo.isLocal
267 delete serverVideo.thumbnailPath
268 delete serverVideo.updatedAt
269 delete serverVideo.views
270 }
271
272 videos.push(serverVideos)
273 })
274
275 tasks.push(p) 264 tasks.push(p)
276 } 265 }
277 266
@@ -279,12 +268,12 @@ async function checkIntegrity (servers: ServerInfo[]) {
279 268
280 let i = 0 269 let i = 0
281 for (const video of videos) { 270 for (const video of videos) {
282 if (!isEqual(video, videos[0])) { 271 const differences = areDifferences(video, videos[0])
272 if (differences !== undefined) {
283 console.error('Integrity not ok with server %d!', i + 1) 273 console.error('Integrity not ok with server %d!', i + 1)
284 274
285 if (displayDiffOnFail) { 275 if (displayDiffOnFail) {
286 console.log(differenceWith(videos[0], video, isEqual)) 276 console.log(differences)
287 console.log(differenceWith(video, videos[0], isEqual))
288 } 277 }
289 278
290 process.exit(-1) 279 process.exit(-1)
@@ -296,15 +285,74 @@ async function checkIntegrity (servers: ServerInfo[]) {
296 console.log('Integrity ok.') 285 console.log('Integrity ok.')
297} 286}
298 287
288function areDifferences (videos1: Video[], videos2: Video[]) {
289 // Remove some keys we don't want to compare
290 videos1.concat(videos2).forEach(video => {
291 delete video.id
292 delete video.isLocal
293 delete video.thumbnailPath
294 delete video.updatedAt
295 delete video.views
296 })
297
298 if (videos1.length !== videos2.length) {
299 return `Videos length are different (${videos1.length}/${videos2.length}).`
300 }
301
302 for (const video1 of videos1) {
303 const video2 = videos2.find(video => video.uuid === video1.uuid)
304
305 if (!video2) return 'Video ' + video1.uuid + ' is missing.'
306
307 for (const videoKey of Object.keys(video1)) {
308 const attribute1 = video1[videoKey]
309 const attribute2 = video2[videoKey]
310
311 if (videoKey === 'tags') {
312 if (attribute1.length !== attribute2.length) {
313 return 'Tags are different.'
314 }
315
316 attribute1.forEach(tag1 => {
317 if (attribute2.indexOf(tag1) === -1) {
318 return 'Tag ' + tag1 + ' is missing.'
319 }
320 })
321 } else if (videoKey === 'files') {
322 if (attribute1.length !== attribute2.length) {
323 return 'Video files are different.'
324 }
325
326 attribute1.forEach((videoFile1: VideoFile) => {
327 const videoFile2: VideoFile = attribute2.find(videoFile => videoFile.magnetUri === videoFile1.magnetUri)
328 if (!videoFile2) {
329 return `Video ${video1.uuid} has missing video file ${videoFile1.magnetUri}.`
330 }
331
332 if (videoFile1.size !== videoFile2.size || videoFile1.resolutionLabel !== videoFile2.resolutionLabel) {
333 return `Video ${video1.uuid} has different video file ${videoFile1.magnetUri}.`
334 }
335 })
336 } else {
337 if (attribute1 !== attribute2) {
338 return `Video ${video1.uuid} has different value for attribute ${videoKey}.`
339 }
340 }
341 }
342 }
343
344 return undefined
345}
346
299function goodbye () { 347function goodbye () {
300 return process.exit(-1) 348 return process.exit(-1)
301} 349}
302 350
303async function isThereAwaitingRequests (servers: ServerInfo[]) { 351async function isTherePendingRequests (servers: ServerInfo[]) {
304 const tasks: Promise<any>[] = [] 352 const tasks: Promise<any>[] = []
305 let awaitingRequests = false 353 let pendingRequests = false
306 354
307 // Check if each server has awaiting request 355 // Check if each server has pending request
308 for (const server of servers) { 356 for (const server of servers) {
309 const p = getRequestsStats(server).then(res => { 357 const p = getRequestsStats(server).then(res => {
310 const stats = res.body 358 const stats = res.body
@@ -314,7 +362,7 @@ async function isThereAwaitingRequests (servers: ServerInfo[]) {
314 stats.requestVideoEventScheduler.totalRequests !== 0 || 362 stats.requestVideoEventScheduler.totalRequests !== 0 ||
315 stats.requestVideoQaduScheduler.totalRequests !== 0 363 stats.requestVideoQaduScheduler.totalRequests !== 0
316 ) { 364 ) {
317 awaitingRequests = true 365 pendingRequests = true
318 } 366 }
319 }) 367 })
320 368
@@ -323,5 +371,5 @@ async function isThereAwaitingRequests (servers: ServerInfo[]) {
323 371
324 await Promise.all(tasks) 372 await Promise.all(tasks)
325 373
326 return awaitingRequests 374 return pendingRequests
327} 375}