aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-02-01 11:57:21 +0100
committerChocobozzz <me@florianbigard.com>2021-02-01 15:03:28 +0100
commit6949a1a1113cc6af3442dc3d5446b8fe6143f28e (patch)
tree70f8fecc38ff3f5dd848343caa338fc8993a2124 /server
parent56df7815b56f35d4e1b539087aac16f4ceabf7be (diff)
downloadPeerTube-6949a1a1113cc6af3442dc3d5446b8fe6143f28e.tar.gz
PeerTube-6949a1a1113cc6af3442dc3d5446b8fe6143f28e.tar.zst
PeerTube-6949a1a1113cc6af3442dc3d5446b8fe6143f28e.zip
Fix tests
Diffstat (limited to 'server')
-rw-r--r--server/models/redundancy/video-redundancy.ts3
-rw-r--r--server/tests/api/redundancy/redundancy-constraints.ts58
-rw-r--r--server/tests/api/redundancy/redundancy.ts27
3 files changed, 48 insertions, 40 deletions
diff --git a/server/models/redundancy/video-redundancy.ts b/server/models/redundancy/video-redundancy.ts
index d3b839cfe..98c6ff134 100644
--- a/server/models/redundancy/video-redundancy.ts
+++ b/server/models/redundancy/video-redundancy.ts
@@ -1,5 +1,5 @@
1import { sample } from 'lodash' 1import { sample } from 'lodash'
2import { col, FindOptions, fn, literal, Op, QueryTypes, Transaction, WhereOptions } from 'sequelize' 2import { FindOptions, literal, Op, QueryTypes, Transaction, WhereOptions } from 'sequelize'
3import { 3import {
4 AllowNull, 4 AllowNull,
5 BeforeDestroy, 5 BeforeDestroy,
@@ -36,7 +36,6 @@ import { VideoModel } from '../video/video'
36import { VideoChannelModel } from '../video/video-channel' 36import { VideoChannelModel } from '../video/video-channel'
37import { VideoFileModel } from '../video/video-file' 37import { VideoFileModel } from '../video/video-file'
38import { VideoStreamingPlaylistModel } from '../video/video-streaming-playlist' 38import { VideoStreamingPlaylistModel } from '../video/video-streaming-playlist'
39import { forEachSeries } from 'async'
40 39
41export enum ScopeNames { 40export enum ScopeNames {
42 WITH_VIDEO = 'WITH_VIDEO' 41 WITH_VIDEO = 'WITH_VIDEO'
diff --git a/server/tests/api/redundancy/redundancy-constraints.ts b/server/tests/api/redundancy/redundancy-constraints.ts
index 4fd8f065c..1cb1603bc 100644
--- a/server/tests/api/redundancy/redundancy-constraints.ts
+++ b/server/tests/api/redundancy/redundancy-constraints.ts
@@ -1,7 +1,9 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import * as chai from 'chai'
4import 'mocha' 3import 'mocha'
4import * as chai from 'chai'
5import { listVideoRedundancies, updateRedundancy } from '@shared/extra-utils/server/redundancy'
6import { VideoPrivacy } from '@shared/models'
5import { 7import {
6 cleanupTests, 8 cleanupTests,
7 flushAndRunServer, 9 flushAndRunServer,
@@ -10,11 +12,11 @@ import {
10 reRunServer, 12 reRunServer,
11 ServerInfo, 13 ServerInfo,
12 setAccessTokensToServers, 14 setAccessTokensToServers,
15 updateVideo,
13 uploadVideo, 16 uploadVideo,
14 waitUntilLog 17 waitUntilLog
15} from '../../../../shared/extra-utils' 18} from '../../../../shared/extra-utils'
16import { waitJobs } from '../../../../shared/extra-utils/server/jobs' 19import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
17import { listVideoRedundancies, updateRedundancy } from '@shared/extra-utils/server/redundancy'
18 20
19const expect = chai.expect 21const expect = chai.expect
20 22
@@ -23,6 +25,31 @@ describe('Test redundancy constraints', function () {
23 let localServer: ServerInfo 25 let localServer: ServerInfo
24 let servers: ServerInfo[] 26 let servers: ServerInfo[]
25 27
28 const remoteServerConfig = {
29 redundancy: {
30 videos: {
31 check_interval: '1 second',
32 strategies: [
33 {
34 strategy: 'recently-added',
35 min_lifetime: '1 hour',
36 size: '100MB',
37 min_views: 0
38 }
39 ]
40 }
41 }
42 }
43
44 async function uploadWrapper (videoName: string) {
45 // Wait for transcoding
46 const res = await uploadVideo(localServer.url, localServer.accessToken, { name: 'to transcode', privacy: VideoPrivacy.PRIVATE })
47 await waitJobs([ localServer ])
48
49 // Update video to schedule a federation
50 await updateVideo(localServer.url, localServer.accessToken, res.body.video.id, { name: videoName, privacy: VideoPrivacy.PUBLIC })
51 }
52
26 async function getTotalRedundanciesLocalServer () { 53 async function getTotalRedundanciesLocalServer () {
27 const res = await listVideoRedundancies({ 54 const res = await listVideoRedundancies({
28 url: localServer.url, 55 url: localServer.url,
@@ -47,22 +74,7 @@ describe('Test redundancy constraints', function () {
47 this.timeout(120000) 74 this.timeout(120000)
48 75
49 { 76 {
50 const config = { 77 remoteServer = await flushAndRunServer(1, remoteServerConfig)
51 redundancy: {
52 videos: {
53 check_interval: '1 second',
54 strategies: [
55 {
56 strategy: 'recently-added',
57 min_lifetime: '1 hour',
58 size: '100MB',
59 min_views: 0
60 }
61 ]
62 }
63 }
64 }
65 remoteServer = await flushAndRunServer(1, config)
66 } 78 }
67 79
68 { 80 {
@@ -124,9 +136,8 @@ describe('Test redundancy constraints', function () {
124 await killallServers([ localServer ]) 136 await killallServers([ localServer ])
125 await reRunServer(localServer, config) 137 await reRunServer(localServer, config)
126 138
127 await uploadVideo(localServer.url, localServer.accessToken, { name: 'video 2 server 2' }) 139 await uploadWrapper('video 2 server 2')
128 140
129 await waitJobs(servers)
130 await waitUntilLog(remoteServer, 'Duplicated ', 10) 141 await waitUntilLog(remoteServer, 'Duplicated ', 10)
131 await waitJobs(servers) 142 await waitJobs(servers)
132 143
@@ -154,9 +165,8 @@ describe('Test redundancy constraints', function () {
154 await killallServers([ localServer ]) 165 await killallServers([ localServer ])
155 await reRunServer(localServer, config) 166 await reRunServer(localServer, config)
156 167
157 await uploadVideo(localServer.url, localServer.accessToken, { name: 'video 3 server 2' }) 168 await uploadWrapper('video 3 server 2')
158 169
159 await waitJobs(servers)
160 await waitUntilLog(remoteServer, 'Duplicated ', 15) 170 await waitUntilLog(remoteServer, 'Duplicated ', 15)
161 await waitJobs(servers) 171 await waitJobs(servers)
162 172
@@ -177,9 +187,7 @@ describe('Test redundancy constraints', function () {
177 await follow(localServer.url, [ remoteServer.url ], localServer.accessToken) 187 await follow(localServer.url, [ remoteServer.url ], localServer.accessToken)
178 await waitJobs(servers) 188 await waitJobs(servers)
179 189
180 await uploadVideo(localServer.url, localServer.accessToken, { name: 'video 4 server 2' }) 190 await uploadWrapper('video 4 server 2')
181
182 await waitJobs(servers)
183 await waitUntilLog(remoteServer, 'Duplicated ', 20) 191 await waitUntilLog(remoteServer, 'Duplicated ', 20)
184 await waitJobs(servers) 192 await waitJobs(servers)
185 193
diff --git a/server/tests/api/redundancy/redundancy.ts b/server/tests/api/redundancy/redundancy.ts
index 8da0ba72a..811dc8c55 100644
--- a/server/tests/api/redundancy/redundancy.ts
+++ b/server/tests/api/redundancy/redundancy.ts
@@ -1,8 +1,11 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import * as chai from 'chai'
4import 'mocha' 3import 'mocha'
5import { VideoDetails } from '../../../../shared/models/videos' 4import * as chai from 'chai'
5import { readdir } from 'fs-extra'
6import * as magnetUtil from 'magnet-uri'
7import { join } from 'path'
8import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
6import { 9import {
7 checkSegmentHash, 10 checkSegmentHash,
8 checkVideoFilesWereRemoved, 11 checkVideoFilesWereRemoved,
@@ -21,29 +24,23 @@ import {
21 ServerInfo, 24 ServerInfo,
22 setAccessTokensToServers, 25 setAccessTokensToServers,
23 unfollow, 26 unfollow,
24 updateCustomConfig,
25 updateCustomSubConfig,
26 uploadVideo, 27 uploadVideo,
27 viewVideo, 28 viewVideo,
28 wait, 29 wait,
29 waitUntilLog 30 waitUntilLog
30} from '../../../../shared/extra-utils' 31} from '../../../../shared/extra-utils'
31import { waitJobs } from '../../../../shared/extra-utils/server/jobs' 32import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
32
33import * as magnetUtil from 'magnet-uri'
34import { 33import {
35 addVideoRedundancy, 34 addVideoRedundancy,
36 listVideoRedundancies, 35 listVideoRedundancies,
37 removeVideoRedundancy, 36 removeVideoRedundancy,
38 updateRedundancy 37 updateRedundancy
39} from '../../../../shared/extra-utils/server/redundancy' 38} from '../../../../shared/extra-utils/server/redundancy'
39import { getStats } from '../../../../shared/extra-utils/server/stats'
40import { ActorFollow } from '../../../../shared/models/actors' 40import { ActorFollow } from '../../../../shared/models/actors'
41import { readdir } from 'fs-extra'
42import { join } from 'path'
43import { VideoRedundancy, VideoRedundancyStrategy, VideoRedundancyStrategyWithManual } from '../../../../shared/models/redundancy' 41import { VideoRedundancy, VideoRedundancyStrategy, VideoRedundancyStrategyWithManual } from '../../../../shared/models/redundancy'
44import { getStats } from '../../../../shared/extra-utils/server/stats'
45import { ServerStats } from '../../../../shared/models/server/server-stats.model' 42import { ServerStats } from '../../../../shared/models/server/server-stats.model'
46import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' 43import { VideoDetails } from '../../../../shared/models/videos'
47 44
48const expect = chai.expect 45const expect = chai.expect
49 46
@@ -258,11 +255,11 @@ async function checkStatsGlobal (strategy: VideoRedundancyStrategyWithManual) {
258 return stat 255 return stat
259} 256}
260 257
261async function checkStatsWith1Redundancy (strategy: VideoRedundancyStrategyWithManual) { 258async function checkStatsWith1Redundancy (strategy: VideoRedundancyStrategyWithManual, onlyHls = false) {
262 const stat = await checkStatsGlobal(strategy) 259 const stat = await checkStatsGlobal(strategy)
263 260
264 expect(stat.totalUsed).to.be.at.least(1).and.below(409601) 261 expect(stat.totalUsed).to.be.at.least(1).and.below(409601)
265 expect(stat.totalVideoFiles).to.equal(4) 262 expect(stat.totalVideoFiles).to.equal(onlyHls ? 4 : 8)
266 expect(stat.totalVideos).to.equal(1) 263 expect(stat.totalVideos).to.equal(1)
267} 264}
268 265
@@ -519,7 +516,7 @@ describe('Test videos redundancy', function () {
519 await waitJobs(servers) 516 await waitJobs(servers)
520 517
521 await check1PlaylistRedundancies() 518 await check1PlaylistRedundancies()
522 await checkStatsWith1Redundancy(strategy) 519 await checkStatsWith1Redundancy(strategy, true)
523 }) 520 })
524 521
525 it('Should remove the video and the redundancy files', async function () { 522 it('Should remove the video and the redundancy files', async function () {
@@ -533,6 +530,10 @@ describe('Test videos redundancy', function () {
533 await checkVideoFilesWereRemoved(video1Server2UUID, server.internalServerNumber) 530 await checkVideoFilesWereRemoved(video1Server2UUID, server.internalServerNumber)
534 } 531 }
535 }) 532 })
533
534 after(async function () {
535 await cleanupTests(servers)
536 })
536 }) 537 })
537 538
538 describe('With manual strategy', function () { 539 describe('With manual strategy', function () {