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