]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/real-world/real-world.ts
BEARKING CHANGE: Update videos API response
[github/Chocobozzz/PeerTube.git] / server / tests / real-world / real-world.ts
index e225a126632463f61503f90b4ada3920fc601304..ae02ef64daa424f40b4b9d00676c1ba9adbf070a 100644 (file)
@@ -1,26 +1,23 @@
-import * as program from 'commander'
-
 // /!\ Before imports /!\
 process.env.NODE_ENV = 'test'
 
-import { REQUESTS_INTERVAL } from '../../initializers/constants'
-import { Video, VideoRateType, VideoFile } from '../../../shared'
+import * as program from 'commander'
+import { Video, VideoFile, VideoRateType } from '../../../shared'
+import { JobState } from '../../../shared/models'
 import {
-  ServerInfo as DefaultServerInfo,
   flushAndRunMultipleServers,
-  setAccessTokensToServers,
-  makeFriends,
-  wait,
+  flushTests, follow,
+  getVideo,
+  getVideosList, getVideosListPagination,
   killallServers,
-  flushTests,
-  uploadVideo,
-  getVideosList,
-  updateVideo,
   removeVideo,
-  getVideo,
-  getAllVideosListBy,
-  getRequestsStats
+  ServerInfo as DefaultServerInfo,
+  setAccessTokensToServers,
+  updateVideo,
+  uploadVideo, viewVideo,
+  wait
 } from '../utils'
+import { getJobsListPaginationAndSort } from '../utils/server/jobs'
 
 interface ServerInfo extends DefaultServerInfo {
   requestsNumber: number
@@ -33,10 +30,10 @@ program
   .option('-v, --view [weight]', 'Weight for viewing videos')
   .option('-l, --like [weight]', 'Weight for liking videos')
   .option('-s, --dislike [weight]', 'Weight for disliking videos')
-  .option('-p, --pods [n]', 'Number of pods to run (3 or 6)', /^3|6$/, 3)
+  .option('-p, --servers [n]', 'Number of servers to run (3 or 6)', /^3|6$/, 3)
   .option('-i, --interval-action [interval]', 'Interval in ms for an action')
   .option('-I, --interval-integrity [interval]', 'Interval in ms for an integrity check')
-  .option('-f, --flush', 'Flush datas on exit')
+  .option('-f, --flush', 'Flush data on exit')
   .option('-d, --difference', 'Display difference if integrity is not okay')
   .parse(process.argv)
 
@@ -51,7 +48,7 @@ const actionInterval = program['intervalAction'] !== undefined ? parseInt(progra
 const integrityInterval = program['intervalIntegrity'] !== undefined ? parseInt(program['intervalIntegrity'], 10) : 60000
 const displayDiffOnFail = program['difference'] || false
 
-const numberOfPods = 6
+const numberOfServers = 6
 
 console.log(
   'Create weight: %d, update weight: %d, remove weight: %d, view weight: %d, like weight: %d, dislike weight: %d.',
@@ -78,13 +75,17 @@ start()
 // ----------------------------------------------------------------------------
 
 async function start () {
-  const servers = await runServers(numberOfPods)
+  const servers = await runServers(numberOfServers)
 
-  process.on('exit', async () => await exitServers(servers, flushAtExit))
+  process.on('exit', async () => {
+    await exitServers(servers, flushAtExit)
+
+    return
+  })
   process.on('SIGINT', goodbye)
   process.on('SIGTERM', goodbye)
 
-  console.log('Servers runned')
+  console.log('Servers ran')
   initializeRequestsPerServer(servers)
 
   let checking = false
@@ -133,7 +134,7 @@ async function start () {
       initializeRequestsPerServer(servers)
       checking = false
       clearInterval(waitingInterval)
-    }, REQUESTS_INTERVAL)
+    }, 10000)
   }, integrityInterval)
 }
 
@@ -149,24 +150,20 @@ function getRandomNumServer (servers) {
   return getRandomInt(0, servers.length)
 }
 
-async function runServers (numberOfPods: number) {
-  let servers = null
-
-  // Run servers
-  servers = await flushAndRunMultipleServers(numberOfPods)
+async function runServers (numberOfServers: number) {
+  const servers: ServerInfo[] = (await flushAndRunMultipleServers(numberOfServers))
+    .map(s => Object.assign({ requestsNumber: 0 }, s))
 
   // Get the access tokens
   await setAccessTokensToServers(servers)
 
-  await makeFriends(servers[1].url, servers[1].accessToken)
-  await makeFriends(servers[0].url, servers[0].accessToken)
-  await wait(1000)
+  for (let i = 0; i < numberOfServers; i++) {
+    for (let j = 0; j < numberOfServers; j++) {
+      if (i === j) continue
 
-  await makeFriends(servers[3].url, servers[3].accessToken)
-  await makeFriends(servers[5].url, servers[5].accessToken)
-  await makeFriends(servers[4].url, servers[4].accessToken)
-
-  await wait(1000)
+      await follow(servers[i].url, [ servers[j].url ], servers[i].accessToken)
+    }
+  }
 
   return servers
 }
@@ -231,7 +228,7 @@ async function view (servers: ServerInfo[], numServer: number) {
   const toView = videos[getRandomInt(0, videos.length)].id
 
   console.log('Viewing video from server ' + numServer)
-  return getVideo(servers[numServer].url, toView)
+  return viewVideo(servers[numServer].url, toView)
 }
 
 function like (servers: ServerInfo[], numServer: number) {
@@ -258,9 +255,10 @@ async function checkIntegrity (servers: ServerInfo[]) {
   const videos: Video[][] = []
   const tasks: Promise<any>[] = []
 
-  // Fetch all videos and remove some fields that can differ between pods
+  // Fetch all videos and remove some fields that can differ between servers
   for (const server of servers) {
-    const p = getAllVideosListBy(server.url).then(res => videos.push(res.body.data))
+    const p = getVideosListPagination(server.url, 0, 1000000, '-createdAt')
+      .then(res => videos.push(res.body.data))
     tasks.push(p)
   }
 
@@ -329,7 +327,7 @@ function areDifferences (videos1: Video[], videos2: Video[]) {
             return `Video ${video1.uuid} has missing video file ${videoFile1.magnetUri}.`
           }
 
-          if (videoFile1.size !== videoFile2.size || videoFile1.resolutionLabel !== videoFile2.resolutionLabel) {
+          if (videoFile1.size !== videoFile2.size || videoFile1.resolution.label !== videoFile2.resolution.label) {
             return `Video ${video1.uuid} has different video file ${videoFile1.magnetUri}.`
           }
         })
@@ -349,24 +347,19 @@ function goodbye () {
 }
 
 async function isTherePendingRequests (servers: ServerInfo[]) {
+  const states: JobState[] = [ 'inactive', 'active', 'delayed' ]
   const tasks: Promise<any>[] = []
   let pendingRequests = false
 
   // Check if each server has pending request
   for (const server of servers) {
-    const p = getRequestsStats(server).then(res => {
-      const stats = res.body
-
-      if (
-        stats.requestScheduler.totalRequests !== 0 ||
-        stats.requestVideoEventScheduler.totalRequests !== 0 ||
-        stats.requestVideoQaduScheduler.totalRequests !== 0
-      ) {
-        pendingRequests = true
-      }
-    })
-
-    tasks.push(p)
+    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)