diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-10-02 12:20:26 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-10-03 15:31:26 +0200 |
commit | 40298b02546e8225dd21bf6048fe7f224aefc32a (patch) | |
tree | 0a0b981dbeb2af47810adff6553a0df995a03734 /server/tests | |
parent | f0adb2701c1cf404ff63095f71e542bfe6d025ae (diff) | |
download | PeerTube-40298b02546e8225dd21bf6048fe7f224aefc32a.tar.gz PeerTube-40298b02546e8225dd21bf6048fe7f224aefc32a.tar.zst PeerTube-40298b02546e8225dd21bf6048fe7f224aefc32a.zip |
Implement video transcoding on server side
Diffstat (limited to 'server/tests')
-rw-r--r-- | server/tests/api/multiple-pods.ts | 65 | ||||
-rw-r--r-- | server/tests/api/video-transcoder.ts | 4 | ||||
-rw-r--r-- | server/tests/cli/update-host.ts | 30 | ||||
-rw-r--r-- | server/tests/utils/videos.ts | 5 |
4 files changed, 70 insertions, 34 deletions
diff --git a/server/tests/api/multiple-pods.ts b/server/tests/api/multiple-pods.ts index 7117ab290..9860935e5 100644 --- a/server/tests/api/multiple-pods.ts +++ b/server/tests/api/multiple-pods.ts | |||
@@ -129,7 +129,7 @@ describe('Test multiple pods', function () { | |||
129 | }) | 129 | }) |
130 | 130 | ||
131 | it('Should upload the video on pod 2 and propagate on each pod', async function () { | 131 | it('Should upload the video on pod 2 and propagate on each pod', async function () { |
132 | this.timeout(60000) | 132 | this.timeout(120000) |
133 | 133 | ||
134 | const videoAttributes = { | 134 | const videoAttributes = { |
135 | name: 'my super name for pod 2', | 135 | name: 'my super name for pod 2', |
@@ -143,12 +143,12 @@ describe('Test multiple pods', function () { | |||
143 | } | 143 | } |
144 | await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) | 144 | await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) |
145 | 145 | ||
146 | // Transcoding, so wait more that 22 seconds | 146 | // Transcoding, so wait more than 22000 |
147 | await wait(42000) | 147 | await wait(60000) |
148 | 148 | ||
149 | // All pods should have this video | 149 | // All pods should have this video |
150 | for (const server of servers) { | 150 | for (const server of servers) { |
151 | let baseMagnet = null | 151 | let baseMagnet = {} |
152 | 152 | ||
153 | const res = await getVideosList(server.url) | 153 | const res = await getVideosList(server.url) |
154 | 154 | ||
@@ -172,28 +172,51 @@ describe('Test multiple pods', function () { | |||
172 | expect(dateIsValid(video.updatedAt)).to.be.true | 172 | expect(dateIsValid(video.updatedAt)).to.be.true |
173 | expect(video.author).to.equal('root') | 173 | expect(video.author).to.equal('root') |
174 | 174 | ||
175 | expect(video.files).to.have.lengthOf(1) | 175 | expect(video.files).to.have.lengthOf(5) |
176 | 176 | ||
177 | const file = video.files[0] | 177 | // Check common attributes |
178 | const magnetUri = file.magnetUri | 178 | for (const file of video.files) { |
179 | expect(file.magnetUri).to.have.lengthOf.above(2) | 179 | expect(file.magnetUri).to.have.lengthOf.above(2) |
180 | expect(file.resolution).to.equal(0) | ||
181 | expect(file.resolutionLabel).to.equal('original') | ||
182 | expect(file.size).to.equal(942961) | ||
183 | 180 | ||
184 | if (server.url !== 'http://localhost:9002') { | 181 | if (server.url !== 'http://localhost:9002') { |
185 | expect(video.isLocal).to.be.false | 182 | expect(video.isLocal).to.be.false |
186 | } else { | 183 | } else { |
187 | expect(video.isLocal).to.be.true | 184 | expect(video.isLocal).to.be.true |
188 | } | 185 | } |
189 | 186 | ||
190 | // All pods should have the same magnet Uri | 187 | // All pods should have the same magnet Uri |
191 | if (baseMagnet === null) { | 188 | if (baseMagnet[file.resolution] === undefined) { |
192 | baseMagnet = magnetUri | 189 | baseMagnet[file.resolution] = file.magnet |
193 | } else { | 190 | } else { |
194 | expect(baseMagnet).to.equal(magnetUri) | 191 | expect(baseMagnet[file.resolution]).to.equal(file.magnet) |
192 | } | ||
195 | } | 193 | } |
196 | 194 | ||
195 | const originalFile = video.files.find(f => f.resolution === 0) | ||
196 | expect(originalFile).not.to.be.undefined | ||
197 | expect(originalFile.resolutionLabel).to.equal('original') | ||
198 | expect(originalFile.size).to.equal(711327) | ||
199 | |||
200 | const file240p = video.files.find(f => f.resolution === 1) | ||
201 | expect(file240p).not.to.be.undefined | ||
202 | expect(file240p.resolutionLabel).to.equal('240p') | ||
203 | expect(file240p.size).to.equal(139953) | ||
204 | |||
205 | const file360p = video.files.find(f => f.resolution === 2) | ||
206 | expect(file360p).not.to.be.undefined | ||
207 | expect(file360p.resolutionLabel).to.equal('360p') | ||
208 | expect(file360p.size).to.equal(169926) | ||
209 | |||
210 | const file480p = video.files.find(f => f.resolution === 3) | ||
211 | expect(file480p).not.to.be.undefined | ||
212 | expect(file480p.resolutionLabel).to.equal('480p') | ||
213 | expect(file480p.size).to.equal(206758) | ||
214 | |||
215 | const file720p = video.files.find(f => f.resolution === 4) | ||
216 | expect(file720p).not.to.be.undefined | ||
217 | expect(file720p.resolutionLabel).to.equal('720p') | ||
218 | expect(file720p.size).to.equal(314913) | ||
219 | |||
197 | const test = await testVideoImage(server.url, 'video_short2.webm', video.thumbnailPath) | 220 | const test = await testVideoImage(server.url, 'video_short2.webm', video.thumbnailPath) |
198 | expect(test).to.equal(true) | 221 | expect(test).to.equal(true) |
199 | } | 222 | } |
diff --git a/server/tests/api/video-transcoder.ts b/server/tests/api/video-transcoder.ts index c6d4c61f5..b5d84d9e7 100644 --- a/server/tests/api/video-transcoder.ts +++ b/server/tests/api/video-transcoder.ts | |||
@@ -42,6 +42,8 @@ describe('Test video transcoding', function () { | |||
42 | 42 | ||
43 | const res = await getVideosList(servers[0].url) | 43 | const res = await getVideosList(servers[0].url) |
44 | const video = res.body.data[0] | 44 | const video = res.body.data[0] |
45 | expect(video.files).to.have.lengthOf(1) | ||
46 | |||
45 | const magnetUri = video.files[0].magnetUri | 47 | const magnetUri = video.files[0].magnetUri |
46 | expect(magnetUri).to.match(/\.webm/) | 48 | expect(magnetUri).to.match(/\.webm/) |
47 | 49 | ||
@@ -66,6 +68,8 @@ describe('Test video transcoding', function () { | |||
66 | const res = await getVideosList(servers[1].url) | 68 | const res = await getVideosList(servers[1].url) |
67 | 69 | ||
68 | const video = res.body.data[0] | 70 | const video = res.body.data[0] |
71 | expect(video.files).to.have.lengthOf(5) | ||
72 | |||
69 | const magnetUri = video.files[0].magnetUri | 73 | const magnetUri = video.files[0].magnetUri |
70 | expect(magnetUri).to.match(/\.mp4/) | 74 | expect(magnetUri).to.match(/\.mp4/) |
71 | 75 | ||
diff --git a/server/tests/cli/update-host.ts b/server/tests/cli/update-host.ts index 644b3807e..e31a84156 100644 --- a/server/tests/cli/update-host.ts +++ b/server/tests/cli/update-host.ts | |||
@@ -12,14 +12,15 @@ import { | |||
12 | runServer, | 12 | runServer, |
13 | ServerInfo, | 13 | ServerInfo, |
14 | setAccessTokensToServers, | 14 | setAccessTokensToServers, |
15 | uploadVideo | 15 | uploadVideo, |
16 | wait | ||
16 | } from '../utils' | 17 | } from '../utils' |
17 | 18 | ||
18 | describe('Test update host scripts', function () { | 19 | describe('Test update host scripts', function () { |
19 | let server: ServerInfo | 20 | let server: ServerInfo |
20 | 21 | ||
21 | before(async function () { | 22 | before(async function () { |
22 | this.timeout(30000) | 23 | this.timeout(60000) |
23 | 24 | ||
24 | await flushTests() | 25 | await flushTests() |
25 | 26 | ||
@@ -28,36 +29,43 @@ describe('Test update host scripts', function () { | |||
28 | port: 9256 | 29 | port: 9256 |
29 | } | 30 | } |
30 | } | 31 | } |
31 | server = await runServer(1, overrideConfig) | 32 | // Run server 2 to have transcoding enabled |
33 | server = await runServer(2, overrideConfig) | ||
32 | await setAccessTokensToServers([ server ]) | 34 | await setAccessTokensToServers([ server ]) |
33 | 35 | ||
34 | // Upload two videos for our needs | 36 | // Upload two videos for our needs |
35 | const videoAttributes = {} | 37 | const videoAttributes = {} |
36 | await uploadVideo(server.url, server.accessToken, videoAttributes) | 38 | await uploadVideo(server.url, server.accessToken, videoAttributes) |
37 | await uploadVideo(server.url, server.accessToken, videoAttributes) | 39 | await uploadVideo(server.url, server.accessToken, videoAttributes) |
40 | await wait(30000) | ||
38 | }) | 41 | }) |
39 | 42 | ||
40 | it('Should update torrent hosts', async function () { | 43 | it('Should update torrent hosts', async function () { |
41 | this.timeout(30000) | 44 | this.timeout(30000) |
42 | 45 | ||
43 | killallServers([ server ]) | 46 | killallServers([ server ]) |
44 | server = await runServer(1) | 47 | // Run server with standard configuration |
48 | server = await runServer(2) | ||
45 | 49 | ||
46 | const env = getEnvCli(server) | 50 | const env = getEnvCli(server) |
47 | await execCLI(`${env} npm run update-host`) | 51 | await execCLI(`${env} npm run update-host`) |
48 | 52 | ||
49 | const res = await getVideosList(server.url) | 53 | const res = await getVideosList(server.url) |
50 | const videos = res.body.data | 54 | const videos = res.body.data |
55 | expect(videos).to.have.lengthOf(2) | ||
51 | 56 | ||
52 | expect(videos[0].files[0].magnetUri).to.contain('localhost%3A9001%2Ftracker%2Fsocket') | 57 | for (const video of videos) { |
53 | expect(videos[0].files[0].magnetUri).to.contain('localhost%3A9001%2Fstatic%2Fwebseed%2F') | 58 | expect(video.files).to.have.lengthOf(5) |
54 | 59 | ||
55 | expect(videos[1].files[0].magnetUri).to.contain('localhost%3A9001%2Ftracker%2Fsocket') | 60 | for (const file of video.files) { |
56 | expect(videos[1].files[0].magnetUri).to.contain('localhost%3A9001%2Fstatic%2Fwebseed%2F') | 61 | expect(file.magnetUri).to.contain('localhost%3A9002%2Ftracker%2Fsocket') |
62 | expect(file.magnetUri).to.contain('localhost%3A9002%2Fstatic%2Fwebseed%2F') | ||
57 | 63 | ||
58 | const torrent = await parseTorrentVideo(server, videos[0].uuid) | 64 | const torrent = await parseTorrentVideo(server, video.uuid, file.resolutionLabel) |
59 | expect(torrent.announce[0]).to.equal('ws://localhost:9001/tracker/socket') | 65 | expect(torrent.announce[0]).to.equal('ws://localhost:9002/tracker/socket') |
60 | expect(torrent.urlList[0]).to.contain('http://localhost:9001/static/webseed') | 66 | expect(torrent.urlList[0]).to.contain('http://localhost:9002/static/webseed') |
67 | } | ||
68 | } | ||
61 | }) | 69 | }) |
62 | 70 | ||
63 | after(async function () { | 71 | after(async function () { |
diff --git a/server/tests/utils/videos.ts b/server/tests/utils/videos.ts index 0de506cd9..7f8bd39c0 100644 --- a/server/tests/utils/videos.ts +++ b/server/tests/utils/videos.ts | |||
@@ -238,9 +238,10 @@ function rateVideo (url: string, accessToken: string, id: number, rating: string | |||
238 | .expect(specialStatus) | 238 | .expect(specialStatus) |
239 | } | 239 | } |
240 | 240 | ||
241 | function parseTorrentVideo (server: ServerInfo, videoUUID: string) { | 241 | function parseTorrentVideo (server: ServerInfo, videoUUID: string, resolutionLabel: string) { |
242 | return new Promise<any>((res, rej) => { | 242 | return new Promise<any>((res, rej) => { |
243 | const torrentPath = join(__dirname, '..', '..', '..', 'test' + server.serverNumber, 'torrents', videoUUID + '.torrent') | 243 | const torrentName = videoUUID + '-' + resolutionLabel + '.torrent' |
244 | const torrentPath = join(__dirname, '..', '..', '..', 'test' + server.serverNumber, 'torrents', torrentName) | ||
244 | readFile(torrentPath, (err, data) => { | 245 | readFile(torrentPath, (err, data) => { |
245 | if (err) return rej(err) | 246 | if (err) return rej(err) |
246 | 247 | ||