1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { VideoDetails, VideoPrivacy } from '@shared/models'
11 flushAndRunMultipleServers,
13 getCustomConfigResolutions,
15 runAndTestFfmpegStreamError,
17 setAccessTokensToServers,
18 setDefaultVideoChannel,
19 updateCustomSubConfig,
23 waitUntilLivePublished
24 } from '../../../../shared/extra-utils'
26 const expect = chai.expect
28 describe('Test live constraints', function () {
29 let servers: ServerInfo[] = []
31 let userAccessToken: string
32 let userChannelId: number
34 async function createLiveWrapper (saveReplay: boolean) {
35 const liveAttributes = {
37 channelId: userChannelId,
38 privacy: VideoPrivacy.PUBLIC,
42 const res = await createLive(servers[0].url, userAccessToken, liveAttributes)
43 return res.body.video.uuid as string
46 async function checkSaveReplay (videoId: string, resolutions = [ 720 ]) {
47 for (const server of servers) {
48 const res = await getVideo(server.url, videoId)
50 const video: VideoDetails = res.body
51 expect(video.isLive).to.be.false
52 expect(video.duration).to.be.greaterThan(0)
55 await checkLiveCleanup(servers[0], videoId, resolutions)
58 async function waitUntilLivePublishedOnAllServers (videoId: string) {
59 for (const server of servers) {
60 await waitUntilLivePublished(server.url, server.accessToken, videoId)
64 function updateQuota (options: { total: number, daily: number }) {
67 accessToken: servers[0].accessToken,
69 videoQuota: options.total,
70 videoQuotaDaily: options.daily
74 before(async function () {
77 servers = await flushAndRunMultipleServers(2)
79 // Get the access tokens
80 await setAccessTokensToServers(servers)
81 await setDefaultVideoChannel(servers)
83 await updateCustomSubConfig(servers[0].url, servers[0].accessToken, {
94 const res = await generateUser(servers[0], 'user1')
96 userChannelId = res.userChannelId
97 userAccessToken = res.token
99 await updateQuota({ total: 1, daily: -1 })
102 // Server 1 and server 2 follow each other
103 await doubleFollow(servers[0], servers[1])
106 it('Should not have size limit if save replay is disabled', async function () {
109 const userVideoLiveoId = await createLiveWrapper(false)
110 await runAndTestFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, false)
113 it('Should have size limit depending on user global quota if save replay is enabled', async function () {
116 // Wait for user quota memoize cache invalidation
119 const userVideoLiveoId = await createLiveWrapper(true)
120 await runAndTestFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, true)
122 await waitUntilLivePublishedOnAllServers(userVideoLiveoId)
123 await waitJobs(servers)
125 await checkSaveReplay(userVideoLiveoId)
128 it('Should have size limit depending on user daily quota if save replay is enabled', async function () {
131 // Wait for user quota memoize cache invalidation
134 await updateQuota({ total: -1, daily: 1 })
136 const userVideoLiveoId = await createLiveWrapper(true)
137 await runAndTestFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, true)
139 await waitUntilLivePublishedOnAllServers(userVideoLiveoId)
140 await waitJobs(servers)
142 await checkSaveReplay(userVideoLiveoId)
145 it('Should succeed without quota limit', async function () {
148 // Wait for user quota memoize cache invalidation
151 await updateQuota({ total: 10 * 1000 * 1000, daily: -1 })
153 const userVideoLiveoId = await createLiveWrapper(true)
154 await runAndTestFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, false)
157 it('Should have max duration limit', async function () {
160 await updateCustomSubConfig(servers[0].url, servers[0].accessToken, {
167 resolutions: getCustomConfigResolutions(true)
172 const userVideoLiveoId = await createLiveWrapper(true)
173 await runAndTestFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, true)
175 await waitUntilLivePublishedOnAllServers(userVideoLiveoId)
176 await waitJobs(servers)
178 await checkSaveReplay(userVideoLiveoId, [ 720, 480, 360, 240 ])
181 after(async function () {
182 await cleanupTests(servers)