]>
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' | |
a1bb73f9 | 5 | import { VideoDetails, VideoPrivacy } from '@shared/models' |
68e70a74 C |
6 | import { |
7 | checkLiveCleanup, | |
8 | cleanupTests, | |
9 | createLive, | |
68e70a74 C |
10 | doubleFollow, |
11 | flushAndRunMultipleServers, | |
a1bb73f9 C |
12 | generateUser, |
13 | getCustomConfigResolutions, | |
68e70a74 C |
14 | getVideo, |
15 | runAndTestFfmpegStreamError, | |
16 | ServerInfo, | |
17 | setAccessTokensToServers, | |
18 | setDefaultVideoChannel, | |
19 | updateCustomSubConfig, | |
20 | updateUser, | |
68e70a74 | 21 | wait, |
300cb723 C |
22 | waitJobs, |
23 | waitUntilLivePublished | |
68e70a74 C |
24 | } from '../../../../shared/extra-utils' |
25 | ||
26 | const expect = chai.expect | |
27 | ||
28 | describe('Test live constraints', function () { | |
29 | let servers: ServerInfo[] = [] | |
30 | let userId: number | |
31 | let userAccessToken: string | |
32 | let userChannelId: number | |
33 | ||
34 | async function createLiveWrapper (saveReplay: boolean) { | |
35 | const liveAttributes = { | |
36 | name: 'user live', | |
37 | channelId: userChannelId, | |
38 | privacy: VideoPrivacy.PUBLIC, | |
39 | saveReplay | |
40 | } | |
41 | ||
42 | const res = await createLive(servers[0].url, userAccessToken, liveAttributes) | |
43 | return res.body.video.uuid as string | |
44 | } | |
45 | ||
46 | async function checkSaveReplay (videoId: string, resolutions = [ 720 ]) { | |
47 | for (const server of servers) { | |
48 | const res = await getVideo(server.url, videoId) | |
49 | ||
50 | const video: VideoDetails = res.body | |
51 | expect(video.isLive).to.be.false | |
52 | expect(video.duration).to.be.greaterThan(0) | |
53 | } | |
54 | ||
55 | await checkLiveCleanup(servers[0], videoId, resolutions) | |
56 | } | |
57 | ||
300cb723 C |
58 | async function waitUntilLivePublishedOnAllServers (videoId: string) { |
59 | for (const server of servers) { | |
60 | await waitUntilLivePublished(server.url, server.accessToken, videoId) | |
61 | } | |
62 | } | |
63 | ||
a1bb73f9 C |
64 | function updateQuota (options: { total: number, daily: number }) { |
65 | return updateUser({ | |
66 | url: servers[0].url, | |
67 | accessToken: servers[0].accessToken, | |
68 | userId, | |
69 | videoQuota: options.total, | |
70 | videoQuotaDaily: options.daily | |
71 | }) | |
72 | } | |
73 | ||
68e70a74 C |
74 | before(async function () { |
75 | this.timeout(120000) | |
76 | ||
77 | servers = await flushAndRunMultipleServers(2) | |
78 | ||
79 | // Get the access tokens | |
80 | await setAccessTokensToServers(servers) | |
81 | await setDefaultVideoChannel(servers) | |
82 | ||
83 | await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { | |
84 | live: { | |
85 | enabled: true, | |
86 | allowReplay: true, | |
87 | transcoding: { | |
88 | enabled: false | |
89 | } | |
90 | } | |
91 | }) | |
92 | ||
93 | { | |
a1bb73f9 C |
94 | const res = await generateUser(servers[0], 'user1') |
95 | userId = res.userId | |
96 | userChannelId = res.userChannelId | |
97 | userAccessToken = res.token | |
98 | ||
99 | await updateQuota({ total: 1, daily: -1 }) | |
68e70a74 C |
100 | } |
101 | ||
102 | // Server 1 and server 2 follow each other | |
103 | await doubleFollow(servers[0], servers[1]) | |
104 | }) | |
105 | ||
106 | it('Should not have size limit if save replay is disabled', async function () { | |
107 | this.timeout(60000) | |
108 | ||
109 | const userVideoLiveoId = await createLiveWrapper(false) | |
110 | await runAndTestFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, false) | |
111 | }) | |
112 | ||
113 | it('Should have size limit depending on user global quota if save replay is enabled', async function () { | |
114 | this.timeout(60000) | |
115 | ||
116 | // Wait for user quota memoize cache invalidation | |
117 | await wait(5000) | |
118 | ||
119 | const userVideoLiveoId = await createLiveWrapper(true) | |
120 | await runAndTestFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, true) | |
121 | ||
300cb723 | 122 | await waitUntilLivePublishedOnAllServers(userVideoLiveoId) |
68e70a74 C |
123 | await waitJobs(servers) |
124 | ||
125 | await checkSaveReplay(userVideoLiveoId) | |
126 | }) | |
127 | ||
128 | it('Should have size limit depending on user daily quota if save replay is enabled', async function () { | |
129 | this.timeout(60000) | |
130 | ||
131 | // Wait for user quota memoize cache invalidation | |
132 | await wait(5000) | |
133 | ||
a1bb73f9 | 134 | await updateQuota({ total: -1, daily: 1 }) |
68e70a74 C |
135 | |
136 | const userVideoLiveoId = await createLiveWrapper(true) | |
137 | await runAndTestFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, true) | |
138 | ||
300cb723 | 139 | await waitUntilLivePublishedOnAllServers(userVideoLiveoId) |
68e70a74 C |
140 | await waitJobs(servers) |
141 | ||
142 | await checkSaveReplay(userVideoLiveoId) | |
143 | }) | |
144 | ||
145 | it('Should succeed without quota limit', 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: 10 * 1000 * 1000, daily: -1 }) |
68e70a74 C |
152 | |
153 | const userVideoLiveoId = await createLiveWrapper(true) | |
154 | await runAndTestFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, false) | |
155 | }) | |
156 | ||
157 | it('Should have max duration limit', async function () { | |
ffc12d3a | 158 | this.timeout(60000) |
68e70a74 C |
159 | |
160 | await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { | |
161 | live: { | |
162 | enabled: true, | |
163 | allowReplay: true, | |
164 | maxDuration: 1, | |
165 | transcoding: { | |
166 | enabled: true, | |
a1bb73f9 | 167 | resolutions: getCustomConfigResolutions(true) |
68e70a74 C |
168 | } |
169 | } | |
170 | }) | |
171 | ||
172 | const userVideoLiveoId = await createLiveWrapper(true) | |
173 | await runAndTestFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, true) | |
174 | ||
300cb723 | 175 | await waitUntilLivePublishedOnAllServers(userVideoLiveoId) |
68e70a74 C |
176 | await waitJobs(servers) |
177 | ||
178 | await checkSaveReplay(userVideoLiveoId, [ 720, 480, 360, 240 ]) | |
179 | }) | |
180 | ||
181 | after(async function () { | |
182 | await cleanupTests(servers) | |
183 | }) | |
184 | }) |