diff options
Diffstat (limited to 'server/tests/api/live/live.ts')
-rw-r--r-- | server/tests/api/live/live.ts | 126 |
1 files changed, 122 insertions, 4 deletions
diff --git a/server/tests/api/live/live.ts b/server/tests/api/live/live.ts index e66c0cb26..f351e9650 100644 --- a/server/tests/api/live/live.ts +++ b/server/tests/api/live/live.ts | |||
@@ -2,14 +2,15 @@ | |||
2 | 2 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import * as chai from 'chai' | 4 | import * as chai from 'chai' |
5 | import { LiveVideo, LiveVideoCreate, VideoDetails, VideoPrivacy } from '@shared/models' | 5 | import { LiveVideo, LiveVideoCreate, User, VideoDetails, VideoPrivacy } from '@shared/models' |
6 | import { | 6 | import { |
7 | acceptChangeOwnership, | ||
8 | cleanupTests, | 7 | cleanupTests, |
9 | createLive, | 8 | createLive, |
9 | createUser, | ||
10 | doubleFollow, | 10 | doubleFollow, |
11 | flushAndRunMultipleServers, | 11 | flushAndRunMultipleServers, |
12 | getLive, | 12 | getLive, |
13 | getMyUserInformation, | ||
13 | getVideo, | 14 | getVideo, |
14 | getVideosList, | 15 | getVideosList, |
15 | makeRawRequest, | 16 | makeRawRequest, |
@@ -17,9 +18,13 @@ import { | |||
17 | ServerInfo, | 18 | ServerInfo, |
18 | setAccessTokensToServers, | 19 | setAccessTokensToServers, |
19 | setDefaultVideoChannel, | 20 | setDefaultVideoChannel, |
21 | testFfmpegStreamError, | ||
20 | testImage, | 22 | testImage, |
21 | updateCustomSubConfig, | 23 | updateCustomSubConfig, |
22 | updateLive, | 24 | updateLive, |
25 | updateUser, | ||
26 | userLogin, | ||
27 | wait, | ||
23 | waitJobs | 28 | waitJobs |
24 | } from '../../../../shared/extra-utils' | 29 | } from '../../../../shared/extra-utils' |
25 | 30 | ||
@@ -28,6 +33,9 @@ const expect = chai.expect | |||
28 | describe('Test live', function () { | 33 | describe('Test live', function () { |
29 | let servers: ServerInfo[] = [] | 34 | let servers: ServerInfo[] = [] |
30 | let liveVideoUUID: string | 35 | let liveVideoUUID: string |
36 | let userId: number | ||
37 | let userAccessToken: string | ||
38 | let userChannelId: number | ||
31 | 39 | ||
32 | before(async function () { | 40 | before(async function () { |
33 | this.timeout(120000) | 41 | this.timeout(120000) |
@@ -45,6 +53,22 @@ describe('Test live', function () { | |||
45 | } | 53 | } |
46 | }) | 54 | }) |
47 | 55 | ||
56 | { | ||
57 | const user = { username: 'user1', password: 'superpassword' } | ||
58 | const res = await createUser({ | ||
59 | url: servers[0].url, | ||
60 | accessToken: servers[0].accessToken, | ||
61 | username: user.username, | ||
62 | password: user.password | ||
63 | }) | ||
64 | userId = res.body.user.id | ||
65 | |||
66 | userAccessToken = await userLogin(servers[0], user) | ||
67 | |||
68 | const resMe = await getMyUserInformation(servers[0].url, userAccessToken) | ||
69 | userChannelId = (resMe.body as User).videoChannels[0].id | ||
70 | } | ||
71 | |||
48 | // Server 1 and server 2 follow each other | 72 | // Server 1 and server 2 follow each other |
49 | await doubleFollow(servers[0], servers[1]) | 73 | await doubleFollow(servers[0], servers[1]) |
50 | }) | 74 | }) |
@@ -198,17 +222,111 @@ describe('Test live', function () { | |||
198 | 222 | ||
199 | describe('Test live constraints', function () { | 223 | describe('Test live constraints', function () { |
200 | 224 | ||
225 | async function createLiveWrapper (saveReplay: boolean) { | ||
226 | const liveAttributes = { | ||
227 | name: 'user live', | ||
228 | channelId: userChannelId, | ||
229 | privacy: VideoPrivacy.PUBLIC, | ||
230 | saveReplay | ||
231 | } | ||
232 | |||
233 | const res = await createLive(servers[0].url, userAccessToken, liveAttributes) | ||
234 | return res.body.video.uuid as string | ||
235 | } | ||
236 | |||
237 | before(async function () { | ||
238 | await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { | ||
239 | live: { | ||
240 | enabled: true, | ||
241 | allowReplay: true | ||
242 | } | ||
243 | }) | ||
244 | |||
245 | await updateUser({ | ||
246 | url: servers[0].url, | ||
247 | userId, | ||
248 | accessToken: servers[0].accessToken, | ||
249 | videoQuota: 1, | ||
250 | videoQuotaDaily: -1 | ||
251 | }) | ||
252 | }) | ||
253 | |||
201 | it('Should not have size limit if save replay is disabled', async function () { | 254 | it('Should not have size limit if save replay is disabled', async function () { |
255 | this.timeout(30000) | ||
202 | 256 | ||
257 | const userVideoLiveoId = await createLiveWrapper(false) | ||
258 | await testFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, false) | ||
203 | }) | 259 | }) |
204 | 260 | ||
205 | it('Should have size limit if save replay is enabled', async function () { | 261 | it('Should have size limit depending on user global quota if save replay is enabled', async function () { |
206 | // daily quota + total quota | 262 | this.timeout(30000) |
263 | |||
264 | const userVideoLiveoId = await createLiveWrapper(true) | ||
265 | await testFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, true) | ||
266 | |||
267 | await waitJobs(servers) | ||
268 | |||
269 | for (const server of servers) { | ||
270 | const res = await getVideo(server.url, userVideoLiveoId) | ||
207 | 271 | ||
272 | const video: VideoDetails = res.body | ||
273 | expect(video.isLive).to.be.false | ||
274 | expect(video.duration).to.be.greaterThan(0) | ||
275 | } | ||
276 | |||
277 | // TODO: check stream correctly saved + cleaned | ||
278 | }) | ||
279 | |||
280 | it('Should have size limit depending on user daily quota if save replay is enabled', async function () { | ||
281 | this.timeout(30000) | ||
282 | |||
283 | await updateUser({ | ||
284 | url: servers[0].url, | ||
285 | userId, | ||
286 | accessToken: servers[0].accessToken, | ||
287 | videoQuota: -1, | ||
288 | videoQuotaDaily: 1 | ||
289 | }) | ||
290 | |||
291 | const userVideoLiveoId = await createLiveWrapper(true) | ||
292 | await testFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, true) | ||
293 | |||
294 | // TODO: check stream correctly saved + cleaned | ||
295 | }) | ||
296 | |||
297 | it('Should succeed without quota limit', async function () { | ||
298 | this.timeout(30000) | ||
299 | |||
300 | // Wait for user quota memoize cache invalidation | ||
301 | await wait(5000) | ||
302 | |||
303 | await updateUser({ | ||
304 | url: servers[0].url, | ||
305 | userId, | ||
306 | accessToken: servers[0].accessToken, | ||
307 | videoQuota: 10 * 1000 * 1000, | ||
308 | videoQuotaDaily: -1 | ||
309 | }) | ||
310 | |||
311 | const userVideoLiveoId = await createLiveWrapper(true) | ||
312 | await testFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, false) | ||
208 | }) | 313 | }) |
209 | 314 | ||
210 | it('Should have max duration limit', async function () { | 315 | it('Should have max duration limit', async function () { |
316 | this.timeout(30000) | ||
317 | |||
318 | await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { | ||
319 | live: { | ||
320 | enabled: true, | ||
321 | allowReplay: true, | ||
322 | maxDuration: 1 | ||
323 | } | ||
324 | }) | ||
325 | |||
326 | const userVideoLiveoId = await createLiveWrapper(true) | ||
327 | await testFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, true) | ||
211 | 328 | ||
329 | // TODO: check stream correctly saved + cleaned | ||
212 | }) | 330 | }) |
213 | }) | 331 | }) |
214 | 332 | ||