1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
11 setAccessTokensToServers,
13 } from '@shared/extra-utils'
14 import { VideoPrivacy, VideoRedundanciesTarget } from '@shared/models'
16 const expect = chai.expect
18 describe('Test manage videos redundancy', function () {
19 const targets: VideoRedundanciesTarget[] = [ 'my-videos', 'remote-videos' ]
21 let servers: PeerTubeServer[]
22 let video1Server2UUID: string
23 let video2Server2UUID: string
24 let redundanciesToRemove: number[] = []
26 let commands: RedundancyCommand[]
28 before(async function () {
39 check_interval: '1 second',
42 strategy: 'recently-added',
43 min_lifetime: '1 hour',
51 servers = await createMultipleServers(3, config)
53 // Get the access tokens
54 await setAccessTokensToServers(servers)
56 commands = servers.map(s => s.redundancy)
59 const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video 1 server 2' } })
60 video1Server2UUID = uuid
64 const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video 2 server 2' } })
65 video2Server2UUID = uuid
68 await waitJobs(servers)
70 // Server 1 and server 2 follow each other
71 await doubleFollow(servers[0], servers[1])
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 not have "remote-videos" redundancies on server 2', async function () {
89 await waitJobs(servers)
90 await servers[0].servers.waitUntilLog('Duplicated ', 10)
91 await waitJobs(servers)
93 const body = await commands[1].listVideos({ target: 'remote-videos' })
95 expect(body.total).to.equal(0)
96 expect(body.data).to.have.lengthOf(0)
99 it('Should have "my-videos" redundancies on server 2', async function () {
102 const body = await commands[1].listVideos({ target: 'my-videos' })
103 expect(body.total).to.equal(2)
105 const videos = body.data
106 expect(videos).to.have.lengthOf(2)
108 const videos1 = videos.find(v => v.uuid === video1Server2UUID)
109 const videos2 = videos.find(v => v.uuid === video2Server2UUID)
111 expect(videos1.name).to.equal('video 1 server 2')
112 expect(videos2.name).to.equal('video 2 server 2')
114 expect(videos1.redundancies.files).to.have.lengthOf(4)
115 expect(videos1.redundancies.streamingPlaylists).to.have.lengthOf(1)
117 const redundancies = videos1.redundancies.files.concat(videos1.redundancies.streamingPlaylists)
119 for (const r of redundancies) {
120 expect(r.strategy).to.be.null
121 expect(r.fileUrl).to.exist
122 expect(r.createdAt).to.exist
123 expect(r.updatedAt).to.exist
124 expect(r.expiresOn).to.exist
128 it('Should not have "my-videos" redundancies on server 1', async function () {
129 const body = await commands[0].listVideos({ target: 'my-videos' })
131 expect(body.total).to.equal(0)
132 expect(body.data).to.have.lengthOf(0)
135 it('Should have "remote-videos" redundancies on server 1', async function () {
138 const body = await commands[0].listVideos({ target: 'remote-videos' })
139 expect(body.total).to.equal(2)
141 const videos = body.data
142 expect(videos).to.have.lengthOf(2)
144 const videos1 = videos.find(v => v.uuid === video1Server2UUID)
145 const videos2 = videos.find(v => v.uuid === video2Server2UUID)
147 expect(videos1.name).to.equal('video 1 server 2')
148 expect(videos2.name).to.equal('video 2 server 2')
150 expect(videos1.redundancies.files).to.have.lengthOf(4)
151 expect(videos1.redundancies.streamingPlaylists).to.have.lengthOf(1)
153 const redundancies = videos1.redundancies.files.concat(videos1.redundancies.streamingPlaylists)
155 for (const r of redundancies) {
156 expect(r.strategy).to.equal('recently-added')
157 expect(r.fileUrl).to.exist
158 expect(r.createdAt).to.exist
159 expect(r.updatedAt).to.exist
160 expect(r.expiresOn).to.exist
164 it('Should correctly paginate and sort results', async function () {
166 const body = await commands[0].listVideos({
167 target: 'remote-videos',
173 const videos = body.data
174 expect(videos[0].name).to.equal('video 1 server 2')
175 expect(videos[1].name).to.equal('video 2 server 2')
179 const body = await commands[0].listVideos({
180 target: 'remote-videos',
186 const videos = body.data
187 expect(videos[0].name).to.equal('video 2 server 2')
188 expect(videos[1].name).to.equal('video 1 server 2')
192 const body = await commands[0].listVideos({
193 target: 'remote-videos',
199 expect(body.data[0].name).to.equal('video 1 server 2')
203 it('Should manually add a redundancy and list it', async function () {
206 const uuid = (await servers[1].videos.quickUpload({ name: 'video 3 server 2', privacy: VideoPrivacy.UNLISTED })).uuid
207 await waitJobs(servers)
208 const videoId = await servers[0].videos.getId({ uuid })
210 await commands[0].addVideo({ videoId })
212 await waitJobs(servers)
213 await servers[0].servers.waitUntilLog('Duplicated ', 15)
214 await waitJobs(servers)
217 const body = await commands[0].listVideos({
218 target: 'remote-videos',
224 const video = body.data[0]
226 expect(video.name).to.equal('video 3 server 2')
227 expect(video.redundancies.files).to.have.lengthOf(4)
228 expect(video.redundancies.streamingPlaylists).to.have.lengthOf(1)
230 const redundancies = video.redundancies.files.concat(video.redundancies.streamingPlaylists)
232 for (const r of redundancies) {
233 redundanciesToRemove.push(r.id)
235 expect(r.strategy).to.equal('manual')
236 expect(r.fileUrl).to.exist
237 expect(r.createdAt).to.exist
238 expect(r.updatedAt).to.exist
239 expect(r.expiresOn).to.be.null
243 const body = await commands[1].listVideos({
250 const video = body.data[0]
251 expect(video.name).to.equal('video 3 server 2')
252 expect(video.redundancies.files).to.have.lengthOf(4)
253 expect(video.redundancies.streamingPlaylists).to.have.lengthOf(1)
255 const redundancies = video.redundancies.files.concat(video.redundancies.streamingPlaylists)
257 for (const r of redundancies) {
258 expect(r.strategy).to.be.null
259 expect(r.fileUrl).to.exist
260 expect(r.createdAt).to.exist
261 expect(r.updatedAt).to.exist
262 expect(r.expiresOn).to.be.null
266 it('Should manually remove a redundancy and remove it from the list', async function () {
269 for (const redundancyId of redundanciesToRemove) {
270 await commands[0].removeVideo({ redundancyId })
274 const body = await commands[0].listVideos({
275 target: 'remote-videos',
281 const videos = body.data
283 expect(videos).to.have.lengthOf(2)
285 const video = videos[0]
286 expect(video.name).to.equal('video 2 server 2')
287 expect(video.redundancies.files).to.have.lengthOf(4)
288 expect(video.redundancies.streamingPlaylists).to.have.lengthOf(1)
290 const redundancies = video.redundancies.files.concat(video.redundancies.streamingPlaylists)
292 redundanciesToRemove = redundancies.map(r => r.id)
296 it('Should remove another (auto) redundancy', async function () {
297 for (const redundancyId of redundanciesToRemove) {
298 await commands[0].removeVideo({ redundancyId })
301 const body = await commands[0].listVideos({
302 target: 'remote-videos',
308 const videos = body.data
309 expect(videos).to.have.lengthOf(1)
310 expect(videos[0].name).to.equal('video 1 server 2')
313 after(async function () {
314 await cleanupTests(servers)