]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Fix tests
authorChocobozzz <me@florianbigard.com>
Mon, 1 Feb 2021 10:57:21 +0000 (11:57 +0100)
committerChocobozzz <me@florianbigard.com>
Mon, 1 Feb 2021 14:03:28 +0000 (15:03 +0100)
server/models/redundancy/video-redundancy.ts
server/tests/api/redundancy/redundancy-constraints.ts
server/tests/api/redundancy/redundancy.ts

index d3b839cfe932542dcc8a37d810c1acf6429307b1..98c6ff1349a22ae645fe666366fc1c9e15ec31bb 100644 (file)
@@ -1,5 +1,5 @@
 import { sample } from 'lodash'
-import { col, FindOptions, fn, literal, Op, QueryTypes, Transaction, WhereOptions } from 'sequelize'
+import { FindOptions, literal, Op, QueryTypes, Transaction, WhereOptions } from 'sequelize'
 import {
   AllowNull,
   BeforeDestroy,
@@ -36,7 +36,6 @@ import { VideoModel } from '../video/video'
 import { VideoChannelModel } from '../video/video-channel'
 import { VideoFileModel } from '../video/video-file'
 import { VideoStreamingPlaylistModel } from '../video/video-streaming-playlist'
-import { forEachSeries } from 'async'
 
 export enum ScopeNames {
   WITH_VIDEO = 'WITH_VIDEO'
index 4fd8f065c0fb2a68228cfe091f9f54835c7d60e2..1cb1603bc0a3989bb958bc9731bfb0ccd1f16204 100644 (file)
@@ -1,7 +1,9 @@
 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
 
-import * as chai from 'chai'
 import 'mocha'
+import * as chai from 'chai'
+import { listVideoRedundancies, updateRedundancy } from '@shared/extra-utils/server/redundancy'
+import { VideoPrivacy } from '@shared/models'
 import {
   cleanupTests,
   flushAndRunServer,
@@ -10,11 +12,11 @@ import {
   reRunServer,
   ServerInfo,
   setAccessTokensToServers,
+  updateVideo,
   uploadVideo,
   waitUntilLog
 } from '../../../../shared/extra-utils'
 import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
-import { listVideoRedundancies, updateRedundancy } from '@shared/extra-utils/server/redundancy'
 
 const expect = chai.expect
 
@@ -23,6 +25,31 @@ describe('Test redundancy constraints', function () {
   let localServer: ServerInfo
   let servers: ServerInfo[]
 
+  const remoteServerConfig = {
+    redundancy: {
+      videos: {
+        check_interval: '1 second',
+        strategies: [
+          {
+            strategy: 'recently-added',
+            min_lifetime: '1 hour',
+            size: '100MB',
+            min_views: 0
+          }
+        ]
+      }
+    }
+  }
+
+  async function uploadWrapper (videoName: string) {
+    // Wait for transcoding
+    const res = await uploadVideo(localServer.url, localServer.accessToken, { name: 'to transcode', privacy: VideoPrivacy.PRIVATE })
+    await waitJobs([ localServer ])
+
+    // Update video to schedule a federation
+    await updateVideo(localServer.url, localServer.accessToken, res.body.video.id, { name: videoName, privacy: VideoPrivacy.PUBLIC })
+  }
+
   async function getTotalRedundanciesLocalServer () {
     const res = await listVideoRedundancies({
       url: localServer.url,
@@ -47,22 +74,7 @@ describe('Test redundancy constraints', function () {
     this.timeout(120000)
 
     {
-      const config = {
-        redundancy: {
-          videos: {
-            check_interval: '1 second',
-            strategies: [
-              {
-                strategy: 'recently-added',
-                min_lifetime: '1 hour',
-                size: '100MB',
-                min_views: 0
-              }
-            ]
-          }
-        }
-      }
-      remoteServer = await flushAndRunServer(1, config)
+      remoteServer = await flushAndRunServer(1, remoteServerConfig)
     }
 
     {
@@ -124,9 +136,8 @@ describe('Test redundancy constraints', function () {
     await killallServers([ localServer ])
     await reRunServer(localServer, config)
 
-    await uploadVideo(localServer.url, localServer.accessToken, { name: 'video 2 server 2' })
+    await uploadWrapper('video 2 server 2')
 
-    await waitJobs(servers)
     await waitUntilLog(remoteServer, 'Duplicated ', 10)
     await waitJobs(servers)
 
@@ -154,9 +165,8 @@ describe('Test redundancy constraints', function () {
     await killallServers([ localServer ])
     await reRunServer(localServer, config)
 
-    await uploadVideo(localServer.url, localServer.accessToken, { name: 'video 3 server 2' })
+    await uploadWrapper('video 3 server 2')
 
-    await waitJobs(servers)
     await waitUntilLog(remoteServer, 'Duplicated ', 15)
     await waitJobs(servers)
 
@@ -177,9 +187,7 @@ describe('Test redundancy constraints', function () {
     await follow(localServer.url, [ remoteServer.url ], localServer.accessToken)
     await waitJobs(servers)
 
-    await uploadVideo(localServer.url, localServer.accessToken, { name: 'video 4 server 2' })
-
-    await waitJobs(servers)
+    await uploadWrapper('video 4 server 2')
     await waitUntilLog(remoteServer, 'Duplicated ', 20)
     await waitJobs(servers)
 
index 8da0ba72a459827d8e475e5e38405a3fe0e29a5a..811dc8c55a87cf9ba34ff15626be99a6ef79f77e 100644 (file)
@@ -1,8 +1,11 @@
 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
 
-import * as chai from 'chai'
 import 'mocha'
-import { VideoDetails } from '../../../../shared/models/videos'
+import * as chai from 'chai'
+import { readdir } from 'fs-extra'
+import * as magnetUtil from 'magnet-uri'
+import { join } from 'path'
+import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
 import {
   checkSegmentHash,
   checkVideoFilesWereRemoved,
@@ -21,29 +24,23 @@ import {
   ServerInfo,
   setAccessTokensToServers,
   unfollow,
-  updateCustomConfig,
-  updateCustomSubConfig,
   uploadVideo,
   viewVideo,
   wait,
   waitUntilLog
 } from '../../../../shared/extra-utils'
 import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
-
-import * as magnetUtil from 'magnet-uri'
 import {
   addVideoRedundancy,
   listVideoRedundancies,
   removeVideoRedundancy,
   updateRedundancy
 } from '../../../../shared/extra-utils/server/redundancy'
+import { getStats } from '../../../../shared/extra-utils/server/stats'
 import { ActorFollow } from '../../../../shared/models/actors'
-import { readdir } from 'fs-extra'
-import { join } from 'path'
 import { VideoRedundancy, VideoRedundancyStrategy, VideoRedundancyStrategyWithManual } from '../../../../shared/models/redundancy'
-import { getStats } from '../../../../shared/extra-utils/server/stats'
 import { ServerStats } from '../../../../shared/models/server/server-stats.model'
-import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
+import { VideoDetails } from '../../../../shared/models/videos'
 
 const expect = chai.expect
 
@@ -258,11 +255,11 @@ async function checkStatsGlobal (strategy: VideoRedundancyStrategyWithManual) {
   return stat
 }
 
-async function checkStatsWith1Redundancy (strategy: VideoRedundancyStrategyWithManual) {
+async function checkStatsWith1Redundancy (strategy: VideoRedundancyStrategyWithManual, onlyHls = false) {
   const stat = await checkStatsGlobal(strategy)
 
   expect(stat.totalUsed).to.be.at.least(1).and.below(409601)
-  expect(stat.totalVideoFiles).to.equal(4)
+  expect(stat.totalVideoFiles).to.equal(onlyHls ? 4 : 8)
   expect(stat.totalVideos).to.equal(1)
 }
 
@@ -519,7 +516,7 @@ describe('Test videos redundancy', function () {
       await waitJobs(servers)
 
       await check1PlaylistRedundancies()
-      await checkStatsWith1Redundancy(strategy)
+      await checkStatsWith1Redundancy(strategy, true)
     })
 
     it('Should remove the video and the redundancy files', async function () {
@@ -533,6 +530,10 @@ describe('Test videos redundancy', function () {
         await checkVideoFilesWereRemoved(video1Server2UUID, server.internalServerNumber)
       }
     })
+
+    after(async function () {
+      await cleanupTests(servers)
+    })
   })
 
   describe('With manual strategy', function () {