1 /* tslint:disable:no-unused-expression */
4 import * as chai from 'chai'
8 flushAndRunMultipleServers,
17 setAccessTokensToServers,
27 import { createUser } from '../utils/users'
29 const expect = chai.expect
31 describe('Test multiple pods', function () {
32 let servers: ServerInfo[] = []
35 let videoChannelId: number
37 before(async function () {
40 servers = await flushAndRunMultipleServers(3)
42 // Get the access tokens
43 await setAccessTokensToServers(servers)
45 const videoChannel = {
47 description: 'super channel'
49 await addVideoChannel(servers[0].url, servers[0].accessToken, videoChannel)
50 const channelRes = await getVideoChannelsList(servers[0].url, 0, 1)
51 videoChannelId = channelRes.body.data[0].id
53 // The second pod make friend with the third
54 await makeFriends(servers[1].url, servers[1].accessToken)
56 // Wait for the request between pods
59 // Pod 1 make friends too
60 await makeFriends(servers[0].url, servers[0].accessToken)
63 it('Should not have videos for all pods', async function () {
64 for (const server of servers) {
65 const res = await getVideosList(server.url)
66 const videos = res.body.data
67 expect(videos).to.be.an('array')
68 expect(videos.length).to.equal(0)
72 describe('Should upload the video and propagate on each pod', function () {
73 it('Should upload the video on pod 1 and propagate on each pod', async function () {
74 // Pod 1 has video transcoding activated
77 const videoAttributes = {
78 name: 'my super name for pod 1',
83 description: 'my super description for pod 1',
84 tags: [ 'tag1p1', 'tag2p1' ],
85 channelId: videoChannelId,
86 fixture: 'video_short1.webm'
88 await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
92 // All pods should have this video
93 for (const server of servers) {
96 const res = await getVideosList(server.url)
98 const videos = res.body.data
99 expect(videos).to.be.an('array')
100 expect(videos.length).to.equal(1)
101 const video = videos[0]
102 expect(video.name).to.equal('my super name for pod 1')
103 expect(video.category).to.equal(5)
104 expect(video.categoryLabel).to.equal('Sports')
105 expect(video.licence).to.equal(4)
106 expect(video.licenceLabel).to.equal('Attribution - Non Commercial')
107 expect(video.language).to.equal(9)
108 expect(video.languageLabel).to.equal('Japanese')
109 expect(video.nsfw).to.be.ok
110 expect(video.description).to.equal('my super description for pod 1')
111 expect(video.podHost).to.equal('localhost:9001')
112 expect(video.duration).to.equal(10)
113 expect(video.tags).to.deep.equal([ 'tag1p1', 'tag2p1' ])
114 expect(dateIsValid(video.createdAt)).to.be.true
115 expect(dateIsValid(video.updatedAt)).to.be.true
116 expect(video.author).to.equal('root')
118 const res2 = await getVideo(server.url, video.uuid)
119 const videoDetails = res2.body
121 expect(videoDetails.channel.name).to.equal('my channel')
122 expect(videoDetails.channel.description).to.equal('super channel')
123 expect(dateIsValid(videoDetails.channel.createdAt)).to.be.true
124 expect(dateIsValid(videoDetails.channel.updatedAt)).to.be.true
125 expect(videoDetails.files).to.have.lengthOf(1)
127 const file = videoDetails.files[0]
128 const magnetUri = file.magnetUri
129 expect(file.magnetUri).to.have.lengthOf.above(2)
130 expect(file.torrentUrl).to.equal(`http://${videoDetails.podHost}/static/torrents/${videoDetails.uuid}-${file.resolution}.torrent`)
131 expect(file.fileUrl).to.equal(`http://${videoDetails.podHost}/static/webseed/${videoDetails.uuid}-${file.resolution}.webm`)
132 expect(file.resolution).to.equal(720)
133 expect(file.resolutionLabel).to.equal('720p')
134 expect(file.size).to.equal(572456)
136 if (server.url !== 'http://localhost:9001') {
137 expect(video.isLocal).to.be.false
138 expect(videoDetails.channel.isLocal).to.be.false
140 expect(video.isLocal).to.be.true
141 expect(videoDetails.channel.isLocal).to.be.true
144 // All pods should have the same magnet Uri
145 if (baseMagnet === null) {
146 baseMagnet = magnetUri
148 expect(baseMagnet).to.equal(magnetUri)
151 const test = await testVideoImage(server.url, 'video_short1.webm', video.thumbnailPath)
152 expect(test).to.equal(true)
156 it('Should upload the video on pod 2 and propagate on each pod', async function () {
161 password: 'super_password'
163 await createUser(servers[1].url, servers[1].accessToken, user.username, user.password)
164 const userAccessToken = await getUserAccessToken(servers[1], user)
166 const videoAttributes = {
167 name: 'my super name for pod 2',
172 description: 'my super description for pod 2',
173 tags: [ 'tag1p2', 'tag2p2', 'tag3p2' ],
174 fixture: 'video_short2.webm'
176 await uploadVideo(servers[1].url, userAccessToken, videoAttributes)
178 // Transcoding, so wait more than 22000
181 // All pods should have this video
182 for (const server of servers) {
185 const res = await getVideosList(server.url)
187 const videos = res.body.data
188 expect(videos).to.be.an('array')
189 expect(videos.length).to.equal(2)
190 const video = videos[1]
191 expect(video.name).to.equal('my super name for pod 2')
192 expect(video.category).to.equal(4)
193 expect(video.categoryLabel).to.equal('Art')
194 expect(video.licence).to.equal(3)
195 expect(video.licenceLabel).to.equal('Attribution - No Derivatives')
196 expect(video.language).to.equal(11)
197 expect(video.languageLabel).to.equal('German')
198 expect(video.nsfw).to.be.true
199 expect(video.description).to.equal('my super description for pod 2')
200 expect(video.podHost).to.equal('localhost:9002')
201 expect(video.duration).to.equal(5)
202 expect(video.tags).to.deep.equal([ 'tag1p2', 'tag2p2', 'tag3p2' ])
203 expect(dateIsValid(video.createdAt)).to.be.true
204 expect(dateIsValid(video.updatedAt)).to.be.true
205 expect(video.author).to.equal('user1')
207 if (server.url !== 'http://localhost:9002') {
208 expect(video.isLocal).to.be.false
210 expect(video.isLocal).to.be.true
213 const res2 = await getVideo(server.url, video.uuid)
214 const videoDetails = res2.body
216 expect(videoDetails.channel.name).to.equal('Default user1 channel')
217 expect(dateIsValid(videoDetails.channel.createdAt)).to.be.true
218 expect(dateIsValid(videoDetails.channel.updatedAt)).to.be.true
220 expect(videoDetails.files).to.have.lengthOf(4)
222 // Check common attributes
223 for (const file of videoDetails.files) {
224 expect(file.magnetUri).to.have.lengthOf.above(2)
226 // All pods should have the same magnet Uri
227 if (baseMagnet[file.resolution] === undefined) {
228 baseMagnet[file.resolution] = file.magnet
230 expect(baseMagnet[file.resolution]).to.equal(file.magnet)
234 const file240p = videoDetails.files.find(f => f.resolution === 240)
235 expect(file240p).not.to.be.undefined
236 expect(file240p.resolutionLabel).to.equal('240p')
237 expect(file240p.size).to.be.above(180000).and.below(200000)
239 const file360p = videoDetails.files.find(f => f.resolution === 360)
240 expect(file360p).not.to.be.undefined
241 expect(file360p.resolutionLabel).to.equal('360p')
242 expect(file360p.size).to.be.above(270000).and.below(290000)
244 const file480p = videoDetails.files.find(f => f.resolution === 480)
245 expect(file480p).not.to.be.undefined
246 expect(file480p.resolutionLabel).to.equal('480p')
247 expect(file480p.size).to.be.above(380000).and.below(400000)
249 const file720p = videoDetails.files.find(f => f.resolution === 720)
250 expect(file720p).not.to.be.undefined
251 expect(file720p.resolutionLabel).to.equal('720p')
252 expect(file720p.size).to.be.above(700000).and.below(7200000)
254 const test = await testVideoImage(server.url, 'video_short2.webm', videoDetails.thumbnailPath)
255 expect(test).to.equal(true)
259 it('Should upload two videos on pod 3 and propagate on each pod', async function () {
262 const videoAttributes1 = {
263 name: 'my super name for pod 3',
268 description: 'my super description for pod 3',
270 fixture: 'video_short3.webm'
272 await uploadVideo(servers[2].url, servers[2].accessToken, videoAttributes1)
274 const videoAttributes2 = {
275 name: 'my super name for pod 3-2',
280 description: 'my super description for pod 3-2',
281 tags: [ 'tag2p3', 'tag3p3', 'tag4p3' ],
282 fixture: 'video_short.webm'
284 await uploadVideo(servers[2].url, servers[2].accessToken, videoAttributes2)
288 let baseMagnet = null
289 // All pods should have this video
290 for (const server of servers) {
291 const res = await getVideosList(server.url)
293 const videos = res.body.data
294 expect(videos).to.be.an('array')
295 expect(videos.length).to.equal(4)
297 // We not sure about the order of the two last uploads
300 if (videos[2].name === 'my super name for pod 3') {
308 expect(video1.name).to.equal('my super name for pod 3')
309 expect(video1.category).to.equal(6)
310 expect(video1.categoryLabel).to.equal('Travels')
311 expect(video1.licence).to.equal(5)
312 expect(video1.licenceLabel).to.equal('Attribution - Non Commercial - Share Alike')
313 expect(video1.language).to.equal(11)
314 expect(video1.languageLabel).to.equal('German')
315 expect(video1.nsfw).to.be.ok
316 expect(video1.description).to.equal('my super description for pod 3')
317 expect(video1.podHost).to.equal('localhost:9003')
318 expect(video1.duration).to.equal(5)
319 expect(video1.tags).to.deep.equal([ 'tag1p3' ])
320 expect(video1.author).to.equal('root')
321 expect(dateIsValid(video1.createdAt)).to.be.true
322 expect(dateIsValid(video1.updatedAt)).to.be.true
324 const res2 = await getVideo(server.url, video1.id)
325 const video1Details = res2.body
326 expect(video1Details.files).to.have.lengthOf(1)
328 const file1 = video1Details.files[0]
329 expect(file1.magnetUri).to.have.lengthOf.above(2)
330 expect(file1.resolution).to.equal(720)
331 expect(file1.resolutionLabel).to.equal('720p')
332 expect(file1.size).to.equal(292677)
334 expect(video2.name).to.equal('my super name for pod 3-2')
335 expect(video2.category).to.equal(7)
336 expect(video2.categoryLabel).to.equal('Gaming')
337 expect(video2.licence).to.equal(6)
338 expect(video2.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
339 expect(video2.language).to.equal(12)
340 expect(video2.languageLabel).to.equal('Korean')
341 expect(video2.nsfw).to.be.false
342 expect(video2.description).to.equal('my super description for pod 3-2')
343 expect(video2.podHost).to.equal('localhost:9003')
344 expect(video2.duration).to.equal(5)
345 expect(video2.tags).to.deep.equal([ 'tag2p3', 'tag3p3', 'tag4p3' ])
346 expect(video2.author).to.equal('root')
347 expect(dateIsValid(video2.createdAt)).to.be.true
348 expect(dateIsValid(video2.updatedAt)).to.be.true
350 const res3 = await getVideo(server.url, video2.id)
351 const video2Details = res3.body
353 expect(video2Details.files).to.have.lengthOf(1)
355 const file2 = video2Details.files[0]
356 const magnetUri2 = file2.magnetUri
357 expect(file2.magnetUri).to.have.lengthOf.above(2)
358 expect(file2.resolution).to.equal(720)
359 expect(file2.resolutionLabel).to.equal('720p')
360 expect(file2.size).to.equal(218910)
362 if (server.url !== 'http://localhost:9003') {
363 expect(video1.isLocal).to.be.false
364 expect(video2.isLocal).to.be.false
366 expect(video1.isLocal).to.be.true
367 expect(video2.isLocal).to.be.true
370 // All pods should have the same magnet Uri
371 if (baseMagnet === null) {
372 baseMagnet = magnetUri2
374 expect(baseMagnet).to.equal(magnetUri2)
377 const test1 = await testVideoImage(server.url, 'video_short3.webm', video1.thumbnailPath)
378 expect(test1).to.equal(true)
380 const test2 = await testVideoImage(server.url, 'video_short.webm', video2.thumbnailPath)
381 expect(test2).to.equal(true)
386 describe('Should seed the uploaded video', function () {
387 it('Should add the file 1 by asking pod 3', async function () {
388 // Yes, this could be long
391 const res = await getVideosList(servers[2].url)
393 const video = res.body.data[0]
394 toRemove.push(res.body.data[2])
395 toRemove.push(res.body.data[3])
397 const res2 = await getVideo(servers[2].url, video.id)
398 const videoDetails = res2.body
400 const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri)
401 expect(torrent.files).to.be.an('array')
402 expect(torrent.files.length).to.equal(1)
403 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
406 it('Should add the file 2 by asking pod 1', async function () {
407 // Yes, this could be long
410 const res = await getVideosList(servers[0].url)
412 const video = res.body.data[1]
413 const res2 = await getVideo(servers[0].url, video.id)
414 const videoDetails = res2.body
416 const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri)
417 expect(torrent.files).to.be.an('array')
418 expect(torrent.files.length).to.equal(1)
419 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
422 it('Should add the file 3 by asking pod 2', async function () {
423 // Yes, this could be long
426 const res = await getVideosList(servers[1].url)
428 const video = res.body.data[2]
429 const res2 = await getVideo(servers[1].url, video.id)
430 const videoDetails = res2.body
432 const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri)
433 expect(torrent.files).to.be.an('array')
434 expect(torrent.files.length).to.equal(1)
435 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
438 it('Should add the file 3-2 by asking pod 1', async function () {
439 // Yes, this could be long
442 const res = await getVideosList(servers[0].url)
444 const video = res.body.data[3]
445 const res2 = await getVideo(servers[0].url, video.id)
446 const videoDetails = res2.body
448 const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri)
449 expect(torrent.files).to.be.an('array')
450 expect(torrent.files.length).to.equal(1)
451 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
454 it('Should add the file 2 in 360p by asking pod 1', async function () {
455 // Yes, this could be long
458 const res = await getVideosList(servers[0].url)
460 const video = res.body.data.find(v => v.name === 'my super name for pod 2')
461 const res2 = await getVideo(servers[0].url, video.id)
462 const videoDetails = res2.body
464 const file = videoDetails.files.find(f => f.resolution === 360)
465 expect(file).not.to.be.undefined
467 const torrent = await webtorrentAdd(file.magnetUri)
468 expect(torrent.files).to.be.an('array')
469 expect(torrent.files.length).to.equal(1)
470 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
474 describe('Should update video views, likes and dislikes', function () {
475 let localVideosPod3 = []
476 let remoteVideosPod1 = []
477 let remoteVideosPod2 = []
478 let remoteVideosPod3 = []
480 before(async function () {
481 const res1 = await getVideosList(servers[0].url)
482 remoteVideosPod1 = res1.body.data.filter(video => video.isLocal === false).map(video => video.uuid)
484 const res2 = await getVideosList(servers[1].url)
485 remoteVideosPod2 = res2.body.data.filter(video => video.isLocal === false).map(video => video.uuid)
487 const res3 = await getVideosList(servers[2].url)
488 localVideosPod3 = res3.body.data.filter(video => video.isLocal === true).map(video => video.uuid)
489 remoteVideosPod3 = res3.body.data.filter(video => video.isLocal === false).map(video => video.uuid)
492 it('Should view multiple videos on owned servers', async function () {
495 const tasks: Promise<any>[] = []
496 tasks.push(getVideo(servers[2].url, localVideosPod3[0]))
497 tasks.push(getVideo(servers[2].url, localVideosPod3[0]))
498 tasks.push(getVideo(servers[2].url, localVideosPod3[0]))
499 tasks.push(getVideo(servers[2].url, localVideosPod3[1]))
501 await Promise.all(tasks)
505 for (const server of servers) {
506 const res = await getVideosList(server.url)
508 const videos = res.body.data
509 const video0 = videos.find(v => v.uuid === localVideosPod3[0])
510 const video1 = videos.find(v => v.uuid === localVideosPod3[1])
512 expect(video0.views).to.equal(4)
513 expect(video1.views).to.equal(2)
517 it('Should view multiple videos on each servers', async function () {
520 const tasks: Promise<any>[] = []
521 tasks.push(getVideo(servers[0].url, remoteVideosPod1[0]))
522 tasks.push(getVideo(servers[1].url, remoteVideosPod2[0]))
523 tasks.push(getVideo(servers[1].url, remoteVideosPod2[0]))
524 tasks.push(getVideo(servers[2].url, remoteVideosPod3[0]))
525 tasks.push(getVideo(servers[2].url, remoteVideosPod3[1]))
526 tasks.push(getVideo(servers[2].url, remoteVideosPod3[1]))
527 tasks.push(getVideo(servers[2].url, remoteVideosPod3[1]))
528 tasks.push(getVideo(servers[2].url, localVideosPod3[1]))
529 tasks.push(getVideo(servers[2].url, localVideosPod3[1]))
530 tasks.push(getVideo(servers[2].url, localVideosPod3[1]))
532 await Promise.all(tasks)
536 let baseVideos = null
538 for (const server of servers) {
539 const res = await getVideosList(server.url)
541 const videos = res.body.data
543 // Initialize base videos for future comparisons
544 if (baseVideos === null) {
549 for (const baseVideo of baseVideos) {
550 const sameVideo = videos.find(video => video.name === baseVideo.name)
551 expect(baseVideo.views).to.equal(sameVideo.views)
556 it('Should like and dislikes videos on different services', async function () {
559 const tasks: Promise<any>[] = []
560 tasks.push(rateVideo(servers[0].url, servers[0].accessToken, remoteVideosPod1[0], 'like'))
561 tasks.push(rateVideo(servers[0].url, servers[0].accessToken, remoteVideosPod1[0], 'dislike'))
562 tasks.push(rateVideo(servers[0].url, servers[0].accessToken, remoteVideosPod1[0], 'like'))
563 tasks.push(rateVideo(servers[2].url, servers[2].accessToken, localVideosPod3[1], 'like'))
564 tasks.push(rateVideo(servers[2].url, servers[2].accessToken, localVideosPod3[1], 'dislike'))
565 tasks.push(rateVideo(servers[2].url, servers[2].accessToken, remoteVideosPod3[1], 'dislike'))
566 tasks.push(rateVideo(servers[2].url, servers[2].accessToken, remoteVideosPod3[0], 'like'))
568 await Promise.all(tasks)
572 let baseVideos = null
573 for (const server of servers) {
574 const res = await getVideosList(server.url)
576 const videos = res.body.data
578 // Initialize base videos for future comparisons
579 if (baseVideos === null) {
584 baseVideos.forEach(baseVideo => {
585 const sameVideo = videos.find(video => video.name === baseVideo.name)
586 expect(baseVideo.likes).to.equal(sameVideo.likes)
587 expect(baseVideo.dislikes).to.equal(sameVideo.dislikes)
593 describe('Should manipulate these videos', function () {
594 it('Should update the video 3 by asking pod 3', async function () {
598 name: 'my super video updated',
603 description: 'my super description updated',
604 tags: [ 'tag_up_1', 'tag_up_2' ]
607 await updateVideo(servers[2].url, servers[2].accessToken, toRemove[0].id, attributes)
612 it('Should have the video 3 updated on each pod', async function () {
615 for (const server of servers) {
616 const res = await getVideosList(server.url)
618 const videos = res.body.data
619 const videoUpdated = videos.find(video => video.name === 'my super video updated')
621 expect(!!videoUpdated).to.be.true
622 expect(videoUpdated.category).to.equal(10)
623 expect(videoUpdated.categoryLabel).to.equal('Entertainment')
624 expect(videoUpdated.licence).to.equal(7)
625 expect(videoUpdated.licenceLabel).to.equal('Public Domain Dedication')
626 expect(videoUpdated.language).to.equal(13)
627 expect(videoUpdated.languageLabel).to.equal('French')
628 expect(videoUpdated.nsfw).to.be.ok
629 expect(videoUpdated.description).to.equal('my super description updated')
630 expect(videoUpdated.tags).to.deep.equal([ 'tag_up_1', 'tag_up_2' ])
631 expect(dateIsValid(videoUpdated.updatedAt, 20000)).to.be.true
633 const res2 = await getVideo(server.url, videoUpdated.uuid)
634 const videoUpdatedDetails = res2.body
636 const file = videoUpdatedDetails .files[0]
637 expect(file.magnetUri).to.have.lengthOf.above(2)
638 expect(file.resolution).to.equal(720)
639 expect(file.resolutionLabel).to.equal('720p')
640 expect(file.size).to.equal(292677)
642 const test = await testVideoImage(server.url, 'video_short3.webm', videoUpdated.thumbnailPath)
643 expect(test).to.equal(true)
645 // Avoid "duplicate torrent" errors
646 const refreshWebTorrent = true
647 const torrent = await webtorrentAdd(videoUpdatedDetails .files[0].magnetUri, refreshWebTorrent)
648 expect(torrent.files).to.be.an('array')
649 expect(torrent.files.length).to.equal(1)
650 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
654 it('Should remove the videos 3 and 3-2 by asking pod 3', async function () {
657 await removeVideo(servers[2].url, servers[2].accessToken, toRemove[0].id)
658 await removeVideo(servers[2].url, servers[2].accessToken, toRemove[1].id)
663 it('Should have videos 1 and 3 on each pod', async function () {
664 for (const server of servers) {
665 const res = await getVideosList(server.url)
667 const videos = res.body.data
668 expect(videos).to.be.an('array')
669 expect(videos.length).to.equal(2)
670 expect(videos[0].name).not.to.equal(videos[1].name)
671 expect(videos[0].name).not.to.equal(toRemove[0].name)
672 expect(videos[1].name).not.to.equal(toRemove[0].name)
673 expect(videos[0].name).not.to.equal(toRemove[1].name)
674 expect(videos[1].name).not.to.equal(toRemove[1].name)
676 videoUUID = videos.find(video => video.name === 'my super name for pod 1').uuid
680 it('Should get the same video by UUID on each pod', async function () {
682 for (const server of servers) {
683 const res = await getVideo(server.url, videoUUID)
685 const video = res.body
687 if (baseVideo === null) {
692 expect(baseVideo.name).to.equal(video.name)
693 expect(baseVideo.uuid).to.equal(video.uuid)
694 expect(baseVideo.category).to.equal(video.category)
695 expect(baseVideo.language).to.equal(video.language)
696 expect(baseVideo.licence).to.equal(video.licence)
697 expect(baseVideo.category).to.equal(video.category)
698 expect(baseVideo.nsfw).to.equal(video.nsfw)
699 expect(baseVideo.author).to.equal(video.author)
700 expect(baseVideo.tags).to.deep.equal(video.tags)
704 it('Should get the preview from each pod', async function () {
705 for (const server of servers) {
706 const res = await getVideo(server.url, videoUUID)
707 const video = res.body
709 const test = await testVideoImage(server.url, 'video_short1-preview.webm', video.previewPath)
710 expect(test).to.equal(true)
715 after(async function () {
716 killallServers(servers)
718 // Keep the logs if the test failed