]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
74cd011b C |
2 | |
3 | import 'mocha' | |
4 | import * as chai from 'chai' | |
679c12e6 | 5 | import { getMaxBitrate } from '@shared/core-utils' |
74cd011b | 6 | import { |
7c3b7976 | 7 | cleanupTests, |
254d3579 | 8 | createMultipleServers, |
4c7e60bc | 9 | doubleFollow, |
7243f84d | 10 | generateHighBitrateVideo, |
254d3579 | 11 | PeerTubeServer, |
74cd011b | 12 | setAccessTokensToServers, |
d23dd9fb C |
13 | wait, |
14 | waitJobs | |
15 | } from '@shared/extra-utils' | |
daf6e480 | 16 | import { getVideoFileBitrate, getVideoFileFPS, getVideoFileResolution } from '../../helpers/ffprobe-utils' |
74cd011b C |
17 | |
18 | const expect = chai.expect | |
19 | ||
20 | describe('Test optimize old videos', function () { | |
254d3579 | 21 | let servers: PeerTubeServer[] = [] |
74cd011b C |
22 | |
23 | before(async function () { | |
24 | this.timeout(200000) | |
25 | ||
74cd011b | 26 | // Run server 2 to have transcoding enabled |
254d3579 | 27 | servers = await createMultipleServers(2) |
74cd011b C |
28 | await setAccessTokensToServers(servers) |
29 | ||
30 | await doubleFollow(servers[0], servers[1]) | |
31 | ||
679c12e6 | 32 | const tempFixturePath = await generateHighBitrateVideo() |
74cd011b C |
33 | |
34 | // Upload two videos for our needs | |
89d241a7 C |
35 | await servers[0].videos.upload({ attributes: { name: 'video1', fixture: tempFixturePath } }) |
36 | await servers[0].videos.upload({ attributes: { name: 'video2', fixture: tempFixturePath } }) | |
74cd011b C |
37 | |
38 | await waitJobs(servers) | |
39 | }) | |
40 | ||
41 | it('Should have two video files on each server', async function () { | |
42 | this.timeout(30000) | |
43 | ||
44 | for (const server of servers) { | |
89d241a7 | 45 | const { data } = await server.videos.list() |
d23dd9fb C |
46 | expect(data).to.have.lengthOf(2) |
47 | ||
48 | for (const video of data) { | |
89d241a7 | 49 | const videoDetails = await server.videos.get({ id: video.uuid }) |
d23dd9fb | 50 | expect(videoDetails.files).to.have.lengthOf(1) |
74cd011b C |
51 | } |
52 | } | |
53 | }) | |
54 | ||
55 | it('Should run optimize script', async function () { | |
5b77537c | 56 | this.timeout(200000) |
74cd011b | 57 | |
89d241a7 | 58 | await servers[0].cli.execWithEnv('npm run optimize-old-videos') |
74cd011b C |
59 | await waitJobs(servers) |
60 | ||
61 | for (const server of servers) { | |
89d241a7 | 62 | const { data } = await server.videos.list() |
d23dd9fb | 63 | expect(data).to.have.lengthOf(2) |
74cd011b | 64 | |
d23dd9fb | 65 | for (const video of data) { |
89d241a7 | 66 | await server.videos.view({ id: video.uuid }) |
74cd011b C |
67 | |
68 | // Refresh video | |
69 | await waitJobs(servers) | |
70 | await wait(5000) | |
71 | await waitJobs(servers) | |
72 | ||
89d241a7 | 73 | const videoDetails = await server.videos.get({ id: video.uuid }) |
74cd011b | 74 | |
d23dd9fb C |
75 | expect(videoDetails.files).to.have.lengthOf(1) |
76 | const file = videoDetails.files[0] | |
74cd011b | 77 | |
941c5eac | 78 | expect(file.size).to.be.below(8000000) |
74cd011b | 79 | |
764b1a14 | 80 | const path = servers[0].servers.buildWebTorrentFilePath(file.fileUrl) |
74cd011b C |
81 | const bitrate = await getVideoFileBitrate(path) |
82 | const fps = await getVideoFileFPS(path) | |
679c12e6 C |
83 | const data = await getVideoFileResolution(path) |
84 | ||
85 | expect(data.resolution).to.equal(file.resolution.id) | |
74cd011b | 86 | |
679c12e6 C |
87 | const maxBitrate = getMaxBitrate({ ...data, fps }) |
88 | expect(bitrate).to.be.below(maxBitrate) | |
74cd011b C |
89 | } |
90 | } | |
91 | }) | |
92 | ||
7c3b7976 C |
93 | after(async function () { |
94 | await cleanupTests(servers) | |
74cd011b C |
95 | }) |
96 | }) |