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,
15 setAccessTokensToServers,
16 setDefaultVideoChannel,
20 } from '../../../../shared/extra-utils'
22 const expect = chai.expect
24 describe('Test live constraints', function () {
25 let servers: ServerInfo[] = []
27 let userAccessToken: string
28 let userChannelId: number
30 async function createLiveWrapper (saveReplay: boolean) {
31 const liveAttributes = {
33 channelId: userChannelId,
34 privacy: VideoPrivacy.PUBLIC,
38 const { uuid } = await servers[0].liveCommand.createLive({ token: userAccessToken, fields: liveAttributes })
42 async function checkSaveReplay (videoId: string, resolutions = [ 720 ]) {
43 for (const server of servers) {
44 const res = await getVideo(server.url, videoId)
46 const video: VideoDetails = res.body
47 expect(video.isLive).to.be.false
48 expect(video.duration).to.be.greaterThan(0)
51 await checkLiveCleanup(servers[0], videoId, resolutions)
54 async function waitUntilLivePublishedOnAllServers (videoId: string) {
55 for (const server of servers) {
56 await server.liveCommand.waitUntilLivePublished({ videoId })
60 function updateQuota (options: { total: number, daily: number }) {
63 accessToken: servers[0].accessToken,
65 videoQuota: options.total,
66 videoQuotaDaily: options.daily
70 before(async function () {
73 servers = await flushAndRunMultipleServers(2)
75 // Get the access tokens
76 await setAccessTokensToServers(servers)
77 await setDefaultVideoChannel(servers)
79 await servers[0].configCommand.updateCustomSubConfig({
92 const res = await generateUser(servers[0], 'user1')
94 userChannelId = res.userChannelId
95 userAccessToken = res.token
97 await updateQuota({ total: 1, daily: -1 })
100 // Server 1 and server 2 follow each other
101 await doubleFollow(servers[0], servers[1])
104 it('Should not have size limit if save replay is disabled', async function () {
107 const userVideoLiveoId = await createLiveWrapper(false)
108 await servers[0].liveCommand.runAndTestFfmpegStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: false })
111 it('Should have size limit depending on user global quota if save replay is enabled', async function () {
114 // Wait for user quota memoize cache invalidation
117 const userVideoLiveoId = await createLiveWrapper(true)
118 await servers[0].liveCommand.runAndTestFfmpegStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: true })
120 await waitUntilLivePublishedOnAllServers(userVideoLiveoId)
121 await waitJobs(servers)
123 await checkSaveReplay(userVideoLiveoId)
126 it('Should have size limit depending on user daily quota if save replay is enabled', async function () {
129 // Wait for user quota memoize cache invalidation
132 await updateQuota({ total: -1, daily: 1 })
134 const userVideoLiveoId = await createLiveWrapper(true)
135 await servers[0].liveCommand.runAndTestFfmpegStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: true })
137 await waitUntilLivePublishedOnAllServers(userVideoLiveoId)
138 await waitJobs(servers)
140 await checkSaveReplay(userVideoLiveoId)
143 it('Should succeed without quota limit', async function () {
146 // Wait for user quota memoize cache invalidation
149 await updateQuota({ total: 10 * 1000 * 1000, daily: -1 })
151 const userVideoLiveoId = await createLiveWrapper(true)
152 await servers[0].liveCommand.runAndTestFfmpegStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: false })
155 it('Should have max duration limit', async function () {
158 await servers[0].configCommand.updateCustomSubConfig({
166 resolutions: ConfigCommand.getCustomConfigResolutions(true)
172 const userVideoLiveoId = await createLiveWrapper(true)
173 await servers[0].liveCommand.runAndTestFfmpegStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: 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)