1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import * as chai from 'chai'
10 setAccessTokensToServers,
12 } from '@shared/server-commands'
13 import { VideoPrivacy, VideoRedundanciesTarget } from '@shared/models'
15 const expect = chai.expect
17 describe('Test manage videos redundancy', function () {
18 const targets: VideoRedundanciesTarget[] = [ 'my-videos', 'remote-videos' ]
20 let servers: PeerTubeServer[]
21 let video1Server2UUID: string
22 let video2Server2UUID: string
23 let redundanciesToRemove: number[] = []
25 let commands: RedundancyCommand[]
27 before(async function () {
38 check_interval: '1 second',
41 strategy: 'recently-added',
42 min_lifetime: '1 hour',
50 servers = await createMultipleServers(3, config)
52 // Get the access tokens
53 await setAccessTokensToServers(servers)
55 commands = servers.map(s => s.redundancy)
58 const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video 1 server 2' } })
59 video1Server2UUID = uuid
63 const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video 2 server 2' } })
64 video2Server2UUID = uuid
67 await waitJobs(servers)
69 // Server 1 and server 2 follow each other
70 await doubleFollow(servers[0], servers[1])
71 await doubleFollow(servers[0], servers[2])
72 await commands[0].updateRedundancy({ host: servers[1].host, redundancyAllowed: true })
74 await waitJobs(servers)
77 it('Should not have redundancies on server 3', async function () {
78 for (const target of targets) {
79 const body = await commands[2].listVideos({ target })
81 expect(body.total).to.equal(0)
82 expect(body.data).to.have.lengthOf(0)
86 it('Should correctly list followings by redundancy', async function () {
87 const body = await servers[0].follows.getFollowings({ sort: '-redundancyAllowed' })
89 expect(body.total).to.equal(2)
90 expect(body.data).to.have.lengthOf(2)
92 expect(body.data[0].following.host).to.equal(servers[1].host)
93 expect(body.data[1].following.host).to.equal(servers[2].host)
96 it('Should not have "remote-videos" redundancies on server 2', async function () {
99 await waitJobs(servers)
100 await servers[0].servers.waitUntilLog('Duplicated ', 10)
101 await waitJobs(servers)
103 const body = await commands[1].listVideos({ target: 'remote-videos' })
105 expect(body.total).to.equal(0)
106 expect(body.data).to.have.lengthOf(0)
109 it('Should have "my-videos" redundancies on server 2', async function () {
112 const body = await commands[1].listVideos({ target: 'my-videos' })
113 expect(body.total).to.equal(2)
115 const videos = body.data
116 expect(videos).to.have.lengthOf(2)
118 const videos1 = videos.find(v => v.uuid === video1Server2UUID)
119 const videos2 = videos.find(v => v.uuid === video2Server2UUID)
121 expect(videos1.name).to.equal('video 1 server 2')
122 expect(videos2.name).to.equal('video 2 server 2')
124 expect(videos1.redundancies.files).to.have.lengthOf(4)
125 expect(videos1.redundancies.streamingPlaylists).to.have.lengthOf(1)
127 const redundancies = videos1.redundancies.files.concat(videos1.redundancies.streamingPlaylists)
129 for (const r of redundancies) {
130 expect(r.strategy).to.be.null
131 expect(r.fileUrl).to.exist
132 expect(r.createdAt).to.exist
133 expect(r.updatedAt).to.exist
134 expect(r.expiresOn).to.exist
138 it('Should not have "my-videos" redundancies on server 1', async function () {
139 const body = await commands[0].listVideos({ target: 'my-videos' })
141 expect(body.total).to.equal(0)
142 expect(body.data).to.have.lengthOf(0)
145 it('Should have "remote-videos" redundancies on server 1', async function () {
148 const body = await commands[0].listVideos({ target: 'remote-videos' })
149 expect(body.total).to.equal(2)
151 const videos = body.data
152 expect(videos).to.have.lengthOf(2)
154 const videos1 = videos.find(v => v.uuid === video1Server2UUID)
155 const videos2 = videos.find(v => v.uuid === video2Server2UUID)
157 expect(videos1.name).to.equal('video 1 server 2')
158 expect(videos2.name).to.equal('video 2 server 2')
160 expect(videos1.redundancies.files).to.have.lengthOf(4)
161 expect(videos1.redundancies.streamingPlaylists).to.have.lengthOf(1)
163 const redundancies = videos1.redundancies.files.concat(videos1.redundancies.streamingPlaylists)
165 for (const r of redundancies) {
166 expect(r.strategy).to.equal('recently-added')
167 expect(r.fileUrl).to.exist
168 expect(r.createdAt).to.exist
169 expect(r.updatedAt).to.exist
170 expect(r.expiresOn).to.exist
174 it('Should correctly paginate and sort results', async function () {
176 const body = await commands[0].listVideos({
177 target: 'remote-videos',
183 const videos = body.data
184 expect(videos[0].name).to.equal('video 1 server 2')
185 expect(videos[1].name).to.equal('video 2 server 2')
189 const body = await commands[0].listVideos({
190 target: 'remote-videos',
196 const videos = body.data
197 expect(videos[0].name).to.equal('video 2 server 2')
198 expect(videos[1].name).to.equal('video 1 server 2')
202 const body = await commands[0].listVideos({
203 target: 'remote-videos',
209 expect(body.data[0].name).to.equal('video 1 server 2')
213 it('Should manually add a redundancy and list it', async function () {
216 const uuid = (await servers[1].videos.quickUpload({ name: 'video 3 server 2', privacy: VideoPrivacy.UNLISTED })).uuid
217 await waitJobs(servers)
218 const videoId = await servers[0].videos.getId({ uuid })
220 await commands[0].addVideo({ videoId })
222 await waitJobs(servers)
223 await servers[0].servers.waitUntilLog('Duplicated ', 15)
224 await waitJobs(servers)
227 const body = await commands[0].listVideos({
228 target: 'remote-videos',
234 const video = body.data[0]
236 expect(video.name).to.equal('video 3 server 2')
237 expect(video.redundancies.files).to.have.lengthOf(4)
238 expect(video.redundancies.streamingPlaylists).to.have.lengthOf(1)
240 const redundancies = video.redundancies.files.concat(video.redundancies.streamingPlaylists)
242 for (const r of redundancies) {
243 redundanciesToRemove.push(r.id)
245 expect(r.strategy).to.equal('manual')
246 expect(r.fileUrl).to.exist
247 expect(r.createdAt).to.exist
248 expect(r.updatedAt).to.exist
249 expect(r.expiresOn).to.be.null
253 const body = await commands[1].listVideos({
260 const video = body.data[0]
261 expect(video.name).to.equal('video 3 server 2')
262 expect(video.redundancies.files).to.have.lengthOf(4)
263 expect(video.redundancies.streamingPlaylists).to.have.lengthOf(1)
265 const redundancies = video.redundancies.files.concat(video.redundancies.streamingPlaylists)
267 for (const r of redundancies) {
268 expect(r.strategy).to.be.null
269 expect(r.fileUrl).to.exist
270 expect(r.createdAt).to.exist
271 expect(r.updatedAt).to.exist
272 expect(r.expiresOn).to.be.null
276 it('Should manually remove a redundancy and remove it from the list', async function () {
279 for (const redundancyId of redundanciesToRemove) {
280 await commands[0].removeVideo({ redundancyId })
284 const body = await commands[0].listVideos({
285 target: 'remote-videos',
291 const videos = body.data
293 expect(videos).to.have.lengthOf(2)
295 const video = videos[0]
296 expect(video.name).to.equal('video 2 server 2')
297 expect(video.redundancies.files).to.have.lengthOf(4)
298 expect(video.redundancies.streamingPlaylists).to.have.lengthOf(1)
300 const redundancies = video.redundancies.files.concat(video.redundancies.streamingPlaylists)
302 redundanciesToRemove = redundancies.map(r => r.id)
306 it('Should remove another (auto) redundancy', async function () {
307 for (const redundancyId of redundanciesToRemove) {
308 await commands[0].removeVideo({ redundancyId })
311 const body = await commands[0].listVideos({
312 target: 'remote-videos',
318 const videos = body.data
319 expect(videos).to.have.lengthOf(1)
320 expect(videos[0].name).to.equal('video 1 server 2')
323 after(async function () {
324 await cleanupTests(servers)