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