Increase tests timeout
[oweals/peertube.git] / server / tests / api / videos / video-transcoder.ts
1 /* tslint:disable:no-unused-expression */
2
3 import * as chai from 'chai'
4 import 'mocha'
5 import {
6   flushAndRunMultipleServers, flushTests, getVideo, getVideosList, killallServers, ServerInfo, setAccessTokensToServers, uploadVideo,
7   wait, webtorrentAdd
8 } from '../../utils'
9
10 const expect = chai.expect
11
12 describe('Test video transcoding', function () {
13   let servers: ServerInfo[] = []
14
15   before(async function () {
16     this.timeout(30000)
17
18     // Run servers
19     servers = await flushAndRunMultipleServers(2)
20
21     await setAccessTokensToServers(servers)
22   })
23
24   it('Should not transcode video on server 1', async function () {
25     this.timeout(60000)
26
27     const videoAttributes = {
28       name: 'my super name for server 1',
29       description: 'my super description for server 1',
30       fixture: 'video_short.webm'
31     }
32     await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
33
34     await wait(10000)
35
36     const res = await getVideosList(servers[0].url)
37     const video = res.body.data[0]
38
39     const res2 = await getVideo(servers[0].url, video.id)
40     const videoDetails = res2.body
41     expect(videoDetails.files).to.have.lengthOf(1)
42
43     const magnetUri = videoDetails.files[0].magnetUri
44     expect(magnetUri).to.match(/\.webm/)
45
46     const torrent = await webtorrentAdd(magnetUri)
47     expect(torrent.files).to.be.an('array')
48     expect(torrent.files.length).to.equal(1)
49     expect(torrent.files[0].path).match(/\.webm$/)
50   })
51
52   it('Should transcode video on server 2', async function () {
53     this.timeout(60000)
54
55     const videoAttributes = {
56       name: 'my super name for server 2',
57       description: 'my super description for server 2',
58       fixture: 'video_short.webm'
59     }
60     await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes)
61
62     await wait(20000)
63
64     const res = await getVideosList(servers[1].url)
65
66     const video = res.body.data[0]
67     const res2 = await getVideo(servers[1].url, video.id)
68     const videoDetails = res2.body
69
70     expect(videoDetails.files).to.have.lengthOf(4)
71
72     const magnetUri = videoDetails.files[0].magnetUri
73     expect(magnetUri).to.match(/\.mp4/)
74
75     const torrent = await webtorrentAdd(magnetUri)
76     expect(torrent.files).to.be.an('array')
77     expect(torrent.files.length).to.equal(1)
78     expect(torrent.files[0].path).match(/\.mp4$/)
79   })
80
81   after(async function () {
82     killallServers(servers)
83
84     // Keep the logs if the test failed
85     if (this['ok']) {
86       await flushTests()
87     }
88   })
89 })