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,
14 setAccessTokensToServers,
15 setDefaultVideoChannel,
18 } from '../../../../shared/extra-utils'
20 const expect = chai.expect
22 describe('Test live constraints', function () {
23 let servers: ServerInfo[] = []
25 let userAccessToken: string
26 let userChannelId: number
28 async function createLiveWrapper (saveReplay: boolean) {
29 const liveAttributes = {
31 channelId: userChannelId,
32 privacy: VideoPrivacy.PUBLIC,
36 const { uuid } = await servers[0].liveCommand.create({ token: userAccessToken, fields: liveAttributes })
40 async function checkSaveReplay (videoId: string, resolutions = [ 720 ]) {
41 for (const server of servers) {
42 const res = await getVideo(server.url, videoId)
44 const video: VideoDetails = res.body
45 expect(video.isLive).to.be.false
46 expect(video.duration).to.be.greaterThan(0)
49 await checkLiveCleanup(servers[0], videoId, resolutions)
52 async function waitUntilLivePublishedOnAllServers (videoId: string) {
53 for (const server of servers) {
54 await server.liveCommand.waitUntilPublished({ videoId })
58 function updateQuota (options: { total: number, daily: number }) {
59 return servers[0].usersCommand.update({
61 videoQuota: options.total,
62 videoQuotaDaily: options.daily
66 before(async function () {
69 servers = await flushAndRunMultipleServers(2)
71 // Get the access tokens
72 await setAccessTokensToServers(servers)
73 await setDefaultVideoChannel(servers)
75 await servers[0].configCommand.updateCustomSubConfig({
88 const res = await servers[0].usersCommand.generate('user1')
90 userChannelId = res.userChannelId
91 userAccessToken = res.token
93 await updateQuota({ total: 1, daily: -1 })
96 // Server 1 and server 2 follow each other
97 await doubleFollow(servers[0], servers[1])
100 it('Should not have size limit if save replay is disabled', async function () {
103 const userVideoLiveoId = await createLiveWrapper(false)
104 await servers[0].liveCommand.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: false })
107 it('Should have size limit depending on user global quota if save replay is enabled', async function () {
110 // Wait for user quota memoize cache invalidation
113 const userVideoLiveoId = await createLiveWrapper(true)
114 await servers[0].liveCommand.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: true })
116 await waitUntilLivePublishedOnAllServers(userVideoLiveoId)
117 await waitJobs(servers)
119 await checkSaveReplay(userVideoLiveoId)
122 it('Should have size limit depending on user daily quota if save replay is enabled', async function () {
125 // Wait for user quota memoize cache invalidation
128 await updateQuota({ total: -1, daily: 1 })
130 const userVideoLiveoId = await createLiveWrapper(true)
131 await servers[0].liveCommand.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: true })
133 await waitUntilLivePublishedOnAllServers(userVideoLiveoId)
134 await waitJobs(servers)
136 await checkSaveReplay(userVideoLiveoId)
139 it('Should succeed without quota limit', async function () {
142 // Wait for user quota memoize cache invalidation
145 await updateQuota({ total: 10 * 1000 * 1000, daily: -1 })
147 const userVideoLiveoId = await createLiveWrapper(true)
148 await servers[0].liveCommand.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: false })
151 it('Should have max duration limit', async function () {
154 await servers[0].configCommand.updateCustomSubConfig({
162 resolutions: ConfigCommand.getCustomConfigResolutions(true)
168 const userVideoLiveoId = await createLiveWrapper(true)
169 await servers[0].liveCommand.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: true })
171 await waitUntilLivePublishedOnAllServers(userVideoLiveoId)
172 await waitJobs(servers)
174 await checkSaveReplay(userVideoLiveoId, [ 720, 480, 360, 240 ])
177 after(async function () {
178 await cleanupTests(servers)