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