]>
Commit | Line | Data |
---|---|---|
68e70a74 C |
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | ||
86347717 | 3 | import { expect } from 'chai' |
c55e3d72 | 4 | import { wait } from '@shared/core-utils' |
26e3e98f | 5 | import { LiveVideoError, VideoPrivacy } from '@shared/models' |
68e70a74 | 6 | import { |
68e70a74 | 7 | cleanupTests, |
65e6e260 | 8 | ConfigCommand, |
254d3579 | 9 | createMultipleServers, |
4c7e60bc | 10 | doubleFollow, |
254d3579 | 11 | PeerTubeServer, |
68e70a74 C |
12 | setAccessTokensToServers, |
13 | setDefaultVideoChannel, | |
9a82ce24 | 14 | stopFfmpeg, |
26e3e98f | 15 | waitJobs, |
9295c68b | 16 | waitUntilLiveReplacedByReplayOnAllServers, |
26e3e98f | 17 | waitUntilLiveWaitingOnAllServers |
c55e3d72 | 18 | } from '@shared/server-commands' |
4ec52d04 | 19 | import { checkLiveCleanup } from '../../shared' |
68e70a74 | 20 | |
68e70a74 | 21 | describe('Test live constraints', function () { |
254d3579 | 22 | let servers: PeerTubeServer[] = [] |
68e70a74 C |
23 | let userId: number |
24 | let userAccessToken: string | |
25 | let userChannelId: number | |
26 | ||
26e3e98f C |
27 | async function createLiveWrapper (options: { |
28 | replay: boolean | |
29 | permanent: boolean | |
30 | }) { | |
31 | const { replay, permanent } = options | |
32 | ||
68e70a74 C |
33 | const liveAttributes = { |
34 | name: 'user live', | |
35 | channelId: userChannelId, | |
36 | privacy: VideoPrivacy.PUBLIC, | |
26e3e98f C |
37 | saveReplay: replay, |
38 | permanentLive: permanent | |
68e70a74 C |
39 | } |
40 | ||
89d241a7 | 41 | const { uuid } = await servers[0].live.create({ token: userAccessToken, fields: liveAttributes }) |
4f219914 | 42 | return uuid |
68e70a74 C |
43 | } |
44 | ||
45 | async function checkSaveReplay (videoId: string, resolutions = [ 720 ]) { | |
46 | for (const server of servers) { | |
89d241a7 | 47 | const video = await server.videos.get({ id: videoId }) |
68e70a74 C |
48 | expect(video.isLive).to.be.false |
49 | expect(video.duration).to.be.greaterThan(0) | |
50 | } | |
51 | ||
4ec52d04 | 52 | await checkLiveCleanup(servers[0], videoId, resolutions) |
68e70a74 C |
53 | } |
54 | ||
a1bb73f9 | 55 | function updateQuota (options: { total: number, daily: number }) { |
89d241a7 | 56 | return servers[0].users.update({ |
a1bb73f9 C |
57 | userId, |
58 | videoQuota: options.total, | |
59 | videoQuotaDaily: options.daily | |
60 | }) | |
61 | } | |
62 | ||
68e70a74 C |
63 | before(async function () { |
64 | this.timeout(120000) | |
65 | ||
254d3579 | 66 | servers = await createMultipleServers(2) |
68e70a74 C |
67 | |
68 | // Get the access tokens | |
69 | await setAccessTokensToServers(servers) | |
70 | await setDefaultVideoChannel(servers) | |
71 | ||
89d241a7 | 72 | await servers[0].config.updateCustomSubConfig({ |
65e6e260 C |
73 | newConfig: { |
74 | live: { | |
75 | enabled: true, | |
76 | allowReplay: true, | |
77 | transcoding: { | |
78 | enabled: false | |
79 | } | |
68e70a74 C |
80 | } |
81 | } | |
82 | }) | |
83 | ||
84 | { | |
89d241a7 | 85 | const res = await servers[0].users.generate('user1') |
a1bb73f9 C |
86 | userId = res.userId |
87 | userChannelId = res.userChannelId | |
88 | userAccessToken = res.token | |
89 | ||
90 | await updateQuota({ total: 1, daily: -1 }) | |
68e70a74 C |
91 | } |
92 | ||
93 | // Server 1 and server 2 follow each other | |
94 | await doubleFollow(servers[0], servers[1]) | |
95 | }) | |
96 | ||
97 | it('Should not have size limit if save replay is disabled', async function () { | |
98 | this.timeout(60000) | |
99 | ||
26e3e98f | 100 | const userVideoLiveoId = await createLiveWrapper({ replay: false, permanent: false }) |
89d241a7 | 101 | await servers[0].live.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: false }) |
68e70a74 C |
102 | }) |
103 | ||
26e3e98f | 104 | it('Should have size limit depending on user global quota if save replay is enabled on non permanent live', async function () { |
68e70a74 C |
105 | this.timeout(60000) |
106 | ||
107 | // Wait for user quota memoize cache invalidation | |
108 | await wait(5000) | |
109 | ||
26e3e98f | 110 | const userVideoLiveoId = await createLiveWrapper({ replay: true, permanent: false }) |
89d241a7 | 111 | await servers[0].live.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: true }) |
68e70a74 | 112 | |
9295c68b | 113 | await waitUntilLiveReplacedByReplayOnAllServers(servers, userVideoLiveoId) |
68e70a74 C |
114 | await waitJobs(servers) |
115 | ||
116 | await checkSaveReplay(userVideoLiveoId) | |
26e3e98f C |
117 | |
118 | const session = await servers[0].live.getReplaySession({ videoId: userVideoLiveoId }) | |
119 | expect(session.error).to.equal(LiveVideoError.QUOTA_EXCEEDED) | |
120 | }) | |
121 | ||
122 | it('Should have size limit depending on user global quota if save replay is enabled on a permanent live', async function () { | |
123 | this.timeout(60000) | |
124 | ||
125 | // Wait for user quota memoize cache invalidation | |
126 | await wait(5000) | |
127 | ||
128 | const userVideoLiveoId = await createLiveWrapper({ replay: true, permanent: true }) | |
129 | await servers[0].live.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: true }) | |
130 | ||
131 | await waitJobs(servers) | |
132 | await waitUntilLiveWaitingOnAllServers(servers, userVideoLiveoId) | |
133 | ||
134 | const session = await servers[0].live.findLatestSession({ videoId: userVideoLiveoId }) | |
135 | expect(session.error).to.equal(LiveVideoError.QUOTA_EXCEEDED) | |
68e70a74 C |
136 | }) |
137 | ||
138 | it('Should have size limit depending on user daily quota if save replay is enabled', async function () { | |
139 | this.timeout(60000) | |
140 | ||
141 | // Wait for user quota memoize cache invalidation | |
142 | await wait(5000) | |
143 | ||
a1bb73f9 | 144 | await updateQuota({ total: -1, daily: 1 }) |
68e70a74 | 145 | |
26e3e98f | 146 | const userVideoLiveoId = await createLiveWrapper({ replay: true, permanent: false }) |
89d241a7 | 147 | await servers[0].live.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: true }) |
68e70a74 | 148 | |
9295c68b | 149 | await waitUntilLiveReplacedByReplayOnAllServers(servers, userVideoLiveoId) |
68e70a74 C |
150 | await waitJobs(servers) |
151 | ||
152 | await checkSaveReplay(userVideoLiveoId) | |
26e3e98f C |
153 | |
154 | const session = await servers[0].live.getReplaySession({ videoId: userVideoLiveoId }) | |
155 | expect(session.error).to.equal(LiveVideoError.QUOTA_EXCEEDED) | |
68e70a74 C |
156 | }) |
157 | ||
158 | it('Should succeed without quota limit', async function () { | |
159 | this.timeout(60000) | |
160 | ||
161 | // Wait for user quota memoize cache invalidation | |
162 | await wait(5000) | |
163 | ||
a1bb73f9 | 164 | await updateQuota({ total: 10 * 1000 * 1000, daily: -1 }) |
68e70a74 | 165 | |
26e3e98f | 166 | const userVideoLiveoId = await createLiveWrapper({ replay: true, permanent: false }) |
89d241a7 | 167 | await servers[0].live.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: false }) |
68e70a74 C |
168 | }) |
169 | ||
9a82ce24 C |
170 | it('Should have the same quota in admin and as a user', async function () { |
171 | this.timeout(120000) | |
172 | ||
173 | const userVideoLiveoId = await createLiveWrapper({ replay: true, permanent: false }) | |
174 | const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ token: userAccessToken, videoId: userVideoLiveoId }) | |
175 | ||
176 | await servers[0].live.waitUntilPublished({ videoId: userVideoLiveoId }) | |
177 | ||
178 | await wait(3000) | |
179 | ||
180 | const quotaUser = await servers[0].users.getMyQuotaUsed({ token: userAccessToken }) | |
181 | ||
182 | const { data } = await servers[0].users.list() | |
183 | const quotaAdmin = data.find(u => u.username === 'user1') | |
184 | ||
185 | expect(quotaUser.videoQuotaUsed).to.equal(quotaAdmin.videoQuotaUsed) | |
186 | expect(quotaUser.videoQuotaUsedDaily).to.equal(quotaAdmin.videoQuotaUsedDaily) | |
187 | ||
188 | expect(quotaUser.videoQuotaUsed).to.be.above(10) | |
189 | expect(quotaUser.videoQuotaUsedDaily).to.be.above(10) | |
190 | ||
191 | await stopFfmpeg(ffmpegCommand) | |
192 | }) | |
193 | ||
68e70a74 | 194 | it('Should have max duration limit', async function () { |
ffc12d3a | 195 | this.timeout(60000) |
68e70a74 | 196 | |
89d241a7 | 197 | await servers[0].config.updateCustomSubConfig({ |
65e6e260 C |
198 | newConfig: { |
199 | live: { | |
68e70a74 | 200 | enabled: true, |
65e6e260 C |
201 | allowReplay: true, |
202 | maxDuration: 1, | |
203 | transcoding: { | |
204 | enabled: true, | |
205 | resolutions: ConfigCommand.getCustomConfigResolutions(true) | |
206 | } | |
68e70a74 C |
207 | } |
208 | } | |
209 | }) | |
210 | ||
26e3e98f | 211 | const userVideoLiveoId = await createLiveWrapper({ replay: true, permanent: false }) |
89d241a7 | 212 | await servers[0].live.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: true }) |
68e70a74 | 213 | |
9295c68b | 214 | await waitUntilLiveReplacedByReplayOnAllServers(servers, userVideoLiveoId) |
68e70a74 C |
215 | await waitJobs(servers) |
216 | ||
8dd754c7 | 217 | await checkSaveReplay(userVideoLiveoId, [ 720, 480, 360, 240, 144 ]) |
26e3e98f C |
218 | |
219 | const session = await servers[0].live.getReplaySession({ videoId: userVideoLiveoId }) | |
220 | expect(session.error).to.equal(LiveVideoError.DURATION_EXCEEDED) | |
68e70a74 C |
221 | }) |
222 | ||
223 | after(async function () { | |
224 | await cleanupTests(servers) | |
225 | }) | |
226 | }) |