]>
Commit | Line | Data |
---|---|---|
68e70a74 C |
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | ||
3 | import 'mocha' | |
4 | import * as chai from 'chai' | |
a1bb73f9 | 5 | import { VideoDetails, VideoPrivacy } from '@shared/models' |
68e70a74 C |
6 | import { |
7 | checkLiveCleanup, | |
8 | cleanupTests, | |
65e6e260 | 9 | ConfigCommand, |
68e70a74 | 10 | createLive, |
68e70a74 C |
11 | doubleFollow, |
12 | flushAndRunMultipleServers, | |
a1bb73f9 | 13 | generateUser, |
68e70a74 C |
14 | getVideo, |
15 | runAndTestFfmpegStreamError, | |
16 | ServerInfo, | |
17 | setAccessTokensToServers, | |
18 | setDefaultVideoChannel, | |
68e70a74 | 19 | updateUser, |
68e70a74 | 20 | wait, |
300cb723 C |
21 | waitJobs, |
22 | waitUntilLivePublished | |
68e70a74 C |
23 | } from '../../../../shared/extra-utils' |
24 | ||
25 | const expect = chai.expect | |
26 | ||
27 | describe('Test live constraints', function () { | |
28 | let servers: ServerInfo[] = [] | |
29 | let userId: number | |
30 | let userAccessToken: string | |
31 | let userChannelId: number | |
32 | ||
33 | async function createLiveWrapper (saveReplay: boolean) { | |
34 | const liveAttributes = { | |
35 | name: 'user live', | |
36 | channelId: userChannelId, | |
37 | privacy: VideoPrivacy.PUBLIC, | |
38 | saveReplay | |
39 | } | |
40 | ||
41 | const res = await createLive(servers[0].url, userAccessToken, liveAttributes) | |
42 | return res.body.video.uuid as string | |
43 | } | |
44 | ||
45 | async function checkSaveReplay (videoId: string, resolutions = [ 720 ]) { | |
46 | for (const server of servers) { | |
47 | const res = await getVideo(server.url, videoId) | |
48 | ||
49 | const video: VideoDetails = res.body | |
50 | expect(video.isLive).to.be.false | |
51 | expect(video.duration).to.be.greaterThan(0) | |
52 | } | |
53 | ||
54 | await checkLiveCleanup(servers[0], videoId, resolutions) | |
55 | } | |
56 | ||
300cb723 C |
57 | async function waitUntilLivePublishedOnAllServers (videoId: string) { |
58 | for (const server of servers) { | |
59 | await waitUntilLivePublished(server.url, server.accessToken, videoId) | |
60 | } | |
61 | } | |
62 | ||
a1bb73f9 C |
63 | function updateQuota (options: { total: number, daily: number }) { |
64 | return updateUser({ | |
65 | url: servers[0].url, | |
66 | accessToken: servers[0].accessToken, | |
67 | userId, | |
68 | videoQuota: options.total, | |
69 | videoQuotaDaily: options.daily | |
70 | }) | |
71 | } | |
72 | ||
68e70a74 C |
73 | before(async function () { |
74 | this.timeout(120000) | |
75 | ||
76 | servers = await flushAndRunMultipleServers(2) | |
77 | ||
78 | // Get the access tokens | |
79 | await setAccessTokensToServers(servers) | |
80 | await setDefaultVideoChannel(servers) | |
81 | ||
65e6e260 C |
82 | await servers[0].configCommand.updateCustomSubConfig({ |
83 | newConfig: { | |
84 | live: { | |
85 | enabled: true, | |
86 | allowReplay: true, | |
87 | transcoding: { | |
88 | enabled: false | |
89 | } | |
68e70a74 C |
90 | } |
91 | } | |
92 | }) | |
93 | ||
94 | { | |
a1bb73f9 C |
95 | const res = await generateUser(servers[0], 'user1') |
96 | userId = res.userId | |
97 | userChannelId = res.userChannelId | |
98 | userAccessToken = res.token | |
99 | ||
100 | await updateQuota({ total: 1, daily: -1 }) | |
68e70a74 C |
101 | } |
102 | ||
103 | // Server 1 and server 2 follow each other | |
104 | await doubleFollow(servers[0], servers[1]) | |
105 | }) | |
106 | ||
107 | it('Should not have size limit if save replay is disabled', async function () { | |
108 | this.timeout(60000) | |
109 | ||
110 | const userVideoLiveoId = await createLiveWrapper(false) | |
111 | await runAndTestFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, false) | |
112 | }) | |
113 | ||
114 | it('Should have size limit depending on user global quota if save replay is enabled', async function () { | |
115 | this.timeout(60000) | |
116 | ||
117 | // Wait for user quota memoize cache invalidation | |
118 | await wait(5000) | |
119 | ||
120 | const userVideoLiveoId = await createLiveWrapper(true) | |
121 | await runAndTestFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, true) | |
122 | ||
300cb723 | 123 | await waitUntilLivePublishedOnAllServers(userVideoLiveoId) |
68e70a74 C |
124 | await waitJobs(servers) |
125 | ||
126 | await checkSaveReplay(userVideoLiveoId) | |
127 | }) | |
128 | ||
129 | it('Should have size limit depending on user daily quota if save replay is enabled', async function () { | |
130 | this.timeout(60000) | |
131 | ||
132 | // Wait for user quota memoize cache invalidation | |
133 | await wait(5000) | |
134 | ||
a1bb73f9 | 135 | await updateQuota({ total: -1, daily: 1 }) |
68e70a74 C |
136 | |
137 | const userVideoLiveoId = await createLiveWrapper(true) | |
138 | await runAndTestFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, true) | |
139 | ||
300cb723 | 140 | await waitUntilLivePublishedOnAllServers(userVideoLiveoId) |
68e70a74 C |
141 | await waitJobs(servers) |
142 | ||
143 | await checkSaveReplay(userVideoLiveoId) | |
144 | }) | |
145 | ||
146 | it('Should succeed without quota limit', async function () { | |
147 | this.timeout(60000) | |
148 | ||
149 | // Wait for user quota memoize cache invalidation | |
150 | await wait(5000) | |
151 | ||
a1bb73f9 | 152 | await updateQuota({ total: 10 * 1000 * 1000, daily: -1 }) |
68e70a74 C |
153 | |
154 | const userVideoLiveoId = await createLiveWrapper(true) | |
155 | await runAndTestFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, false) | |
156 | }) | |
157 | ||
158 | it('Should have max duration limit', async function () { | |
ffc12d3a | 159 | this.timeout(60000) |
68e70a74 | 160 | |
65e6e260 C |
161 | await servers[0].configCommand.updateCustomSubConfig({ |
162 | newConfig: { | |
163 | live: { | |
68e70a74 | 164 | enabled: true, |
65e6e260 C |
165 | allowReplay: true, |
166 | maxDuration: 1, | |
167 | transcoding: { | |
168 | enabled: true, | |
169 | resolutions: ConfigCommand.getCustomConfigResolutions(true) | |
170 | } | |
68e70a74 C |
171 | } |
172 | } | |
173 | }) | |
174 | ||
175 | const userVideoLiveoId = await createLiveWrapper(true) | |
176 | await runAndTestFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, true) | |
177 | ||
300cb723 | 178 | await waitUntilLivePublishedOnAllServers(userVideoLiveoId) |
68e70a74 C |
179 | await waitJobs(servers) |
180 | ||
181 | await checkSaveReplay(userVideoLiveoId, [ 720, 480, 360, 240 ]) | |
182 | }) | |
183 | ||
184 | after(async function () { | |
185 | await cleanupTests(servers) | |
186 | }) | |
187 | }) |