]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/cli/create-transcoding-job.ts
Merge from upstream
[github/Chocobozzz/PeerTube.git] / server / tests / cli / create-transcoding-job.ts
1 /* tslint:disable:no-unused-expression */
2
3 import 'mocha'
4 import * as chai from 'chai'
5 import { VideoDetails } from '../../../shared/models/videos'
6 import {
7 doubleFollow,
8 execCLI,
9 flushAndRunMultipleServers,
10 flushTests,
11 getEnvCli,
12 getVideo,
13 getVideosList,
14 killallServers,
15 ServerInfo,
16 setAccessTokensToServers,
17 uploadVideo, wait
18 } from '../../../shared/utils'
19 import { waitJobs } from '../../../shared/utils/server/jobs'
20
21 const expect = chai.expect
22
23 describe('Test create transcoding jobs', function () {
24 let servers: ServerInfo[] = []
25 let video1UUID: string
26 let video2UUID: string
27
28 before(async function () {
29 this.timeout(60000)
30
31 await flushTests()
32
33 // Run server 2 to have transcoding enabled
34 servers = await flushAndRunMultipleServers(2)
35 await setAccessTokensToServers(servers)
36
37 await doubleFollow(servers[0], servers[1])
38
39 // Upload two videos for our needs
40 const res1 = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video1' })
41 video1UUID = res1.body.video.uuid
42 const res2 = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video2' })
43 video2UUID = res2.body.video.uuid
44
45 await waitJobs(servers)
46 })
47
48 it('Should have two video files on each server', async function () {
49 this.timeout(30000)
50
51 for (const server of servers) {
52 const res = await getVideosList(server.url)
53 const videos = res.body.data
54 expect(videos).to.have.lengthOf(2)
55
56 for (const video of videos) {
57 const res2 = await getVideo(server.url, video.uuid)
58 const videoDetail: VideoDetails = res2.body
59 expect(videoDetail.files).to.have.lengthOf(1)
60 }
61 }
62 })
63
64 it('Should run a transcoding job on video 2', async function () {
65 this.timeout(60000)
66
67 const env = getEnvCli(servers[0])
68 await execCLI(`${env} npm run create-transcoding-job -- -v ${video2UUID}`)
69
70 await waitJobs(servers)
71
72 for (const server of servers) {
73 const res = await getVideosList(server.url)
74 const videos = res.body.data
75 expect(videos).to.have.lengthOf(2)
76
77 let infoHashes: { [ id: number ]: string }
78
79 for (const video of videos) {
80 const res2 = await getVideo(server.url, video.uuid)
81 const videoDetail: VideoDetails = res2.body
82
83 if (video.uuid === video2UUID) {
84 expect(videoDetail.files).to.have.lengthOf(4)
85
86 if (!infoHashes) {
87 infoHashes = {}
88
89 for (const file of videoDetail.files) {
90 infoHashes[file.resolution.id.toString()] = file.magnetUri
91 }
92 } else {
93 for (const resolution of Object.keys(infoHashes)) {
94 const file = videoDetail.files.find(f => f.resolution.id.toString() === resolution)
95 expect(file.magnetUri).to.equal(infoHashes[resolution])
96 }
97 }
98 } else {
99 expect(videoDetail.files).to.have.lengthOf(1)
100 }
101 }
102 }
103 })
104
105 it('Should run a transcoding job on video 1 with resolution', async function () {
106 this.timeout(60000)
107
108 const env = getEnvCli(servers[0])
109 await execCLI(`${env} npm run create-transcoding-job -- -v ${video1UUID} -r 480`)
110
111 await waitJobs(servers)
112
113 for (const server of servers) {
114 const res = await getVideosList(server.url)
115 const videos = res.body.data
116 expect(videos).to.have.lengthOf(2)
117
118 const res2 = await getVideo(server.url, video1UUID)
119 const videoDetail: VideoDetails = res2.body
120
121 expect(videoDetail.files).to.have.lengthOf(2)
122
123 expect(videoDetail.files[0].resolution.id).to.equal(720)
124
125 expect(videoDetail.files[1].resolution.id).to.equal(480)
126 }
127 })
128
129 after(async function () {
130 killallServers(servers)
131 })
132 })