diff options
Diffstat (limited to 'server/tests/api/live/live-save-replay.ts')
-rw-r--r-- | server/tests/api/live/live-save-replay.ts | 126 |
1 files changed, 58 insertions, 68 deletions
diff --git a/server/tests/api/live/live-save-replay.ts b/server/tests/api/live/live-save-replay.ts index 3d4736c8f..8f1fb78a5 100644 --- a/server/tests/api/live/live-save-replay.ts +++ b/server/tests/api/live/live-save-replay.ts | |||
@@ -3,97 +3,85 @@ | |||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import * as chai from 'chai' | 4 | import * as chai from 'chai' |
5 | import { FfmpegCommand } from 'fluent-ffmpeg' | 5 | import { FfmpegCommand } from 'fluent-ffmpeg' |
6 | import { LiveVideoCreate, VideoDetails, VideoPrivacy, VideoState } from '@shared/models' | ||
7 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
8 | import { | 6 | import { |
9 | addVideoToBlacklist, | 7 | checkLiveCleanupAfterSave, |
10 | checkLiveCleanup, | ||
11 | cleanupTests, | 8 | cleanupTests, |
12 | createLive, | 9 | ConfigCommand, |
10 | createMultipleServers, | ||
13 | doubleFollow, | 11 | doubleFollow, |
14 | flushAndRunMultipleServers, | 12 | PeerTubeServer, |
15 | getCustomConfigResolutions, | ||
16 | getVideo, | ||
17 | getVideosList, | ||
18 | removeVideo, | ||
19 | sendRTMPStreamInVideo, | ||
20 | ServerInfo, | ||
21 | setAccessTokensToServers, | 13 | setAccessTokensToServers, |
22 | setDefaultVideoChannel, | 14 | setDefaultVideoChannel, |
23 | stopFfmpeg, | 15 | stopFfmpeg, |
24 | testFfmpegStreamError, | 16 | testFfmpegStreamError, |
25 | updateCustomSubConfig, | ||
26 | updateVideo, | ||
27 | wait, | 17 | wait, |
28 | waitJobs, | 18 | waitJobs |
29 | waitUntilLiveEnded, | 19 | } from '@shared/extra-utils' |
30 | waitUntilLivePublished, | 20 | import { HttpStatusCode, LiveVideoCreate, VideoPrivacy, VideoState } from '@shared/models' |
31 | waitUntilLiveSaved | ||
32 | } from '../../../../shared/extra-utils' | ||
33 | 21 | ||
34 | const expect = chai.expect | 22 | const expect = chai.expect |
35 | 23 | ||
36 | describe('Save replay setting', function () { | 24 | describe('Save replay setting', function () { |
37 | let servers: ServerInfo[] = [] | 25 | let servers: PeerTubeServer[] = [] |
38 | let liveVideoUUID: string | 26 | let liveVideoUUID: string |
39 | let ffmpegCommand: FfmpegCommand | 27 | let ffmpegCommand: FfmpegCommand |
40 | 28 | ||
41 | async function createLiveWrapper (saveReplay: boolean) { | 29 | async function createLiveWrapper (saveReplay: boolean) { |
42 | if (liveVideoUUID) { | 30 | if (liveVideoUUID) { |
43 | try { | 31 | try { |
44 | await removeVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) | 32 | await servers[0].videos.remove({ id: liveVideoUUID }) |
45 | await waitJobs(servers) | 33 | await waitJobs(servers) |
46 | } catch {} | 34 | } catch {} |
47 | } | 35 | } |
48 | 36 | ||
49 | const attributes: LiveVideoCreate = { | 37 | const attributes: LiveVideoCreate = { |
50 | channelId: servers[0].videoChannel.id, | 38 | channelId: servers[0].store.channel.id, |
51 | privacy: VideoPrivacy.PUBLIC, | 39 | privacy: VideoPrivacy.PUBLIC, |
52 | name: 'my super live', | 40 | name: 'my super live', |
53 | saveReplay | 41 | saveReplay |
54 | } | 42 | } |
55 | 43 | ||
56 | const res = await createLive(servers[0].url, servers[0].accessToken, attributes) | 44 | const { uuid } = await servers[0].live.create({ fields: attributes }) |
57 | return res.body.video.uuid | 45 | return uuid |
58 | } | 46 | } |
59 | 47 | ||
60 | async function checkVideosExist (videoId: string, existsInList: boolean, getStatus?: number) { | 48 | async function checkVideosExist (videoId: string, existsInList: boolean, expectedStatus?: number) { |
61 | for (const server of servers) { | 49 | for (const server of servers) { |
62 | const length = existsInList ? 1 : 0 | 50 | const length = existsInList ? 1 : 0 |
63 | 51 | ||
64 | const resVideos = await getVideosList(server.url) | 52 | const { data, total } = await server.videos.list() |
65 | expect(resVideos.body.data).to.have.lengthOf(length) | 53 | expect(data).to.have.lengthOf(length) |
66 | expect(resVideos.body.total).to.equal(length) | 54 | expect(total).to.equal(length) |
67 | 55 | ||
68 | if (getStatus) { | 56 | if (expectedStatus) { |
69 | await getVideo(server.url, videoId, getStatus) | 57 | await server.videos.get({ id: videoId, expectedStatus }) |
70 | } | 58 | } |
71 | } | 59 | } |
72 | } | 60 | } |
73 | 61 | ||
74 | async function checkVideoState (videoId: string, state: VideoState) { | 62 | async function checkVideoState (videoId: string, state: VideoState) { |
75 | for (const server of servers) { | 63 | for (const server of servers) { |
76 | const res = await getVideo(server.url, videoId) | 64 | const video = await server.videos.get({ id: videoId }) |
77 | expect((res.body as VideoDetails).state.id).to.equal(state) | 65 | expect(video.state.id).to.equal(state) |
78 | } | 66 | } |
79 | } | 67 | } |
80 | 68 | ||
81 | async function waitUntilLivePublishedOnAllServers (videoId: string) { | 69 | async function waitUntilLivePublishedOnAllServers (videoId: string) { |
82 | for (const server of servers) { | 70 | for (const server of servers) { |
83 | await waitUntilLivePublished(server.url, server.accessToken, videoId) | 71 | await server.live.waitUntilPublished({ videoId }) |
84 | } | 72 | } |
85 | } | 73 | } |
86 | 74 | ||
87 | async function waitUntilLiveSavedOnAllServers (videoId: string) { | 75 | async function waitUntilLiveSavedOnAllServers (videoId: string) { |
88 | for (const server of servers) { | 76 | for (const server of servers) { |
89 | await waitUntilLiveSaved(server.url, server.accessToken, videoId) | 77 | await server.live.waitUntilSaved({ videoId }) |
90 | } | 78 | } |
91 | } | 79 | } |
92 | 80 | ||
93 | before(async function () { | 81 | before(async function () { |
94 | this.timeout(120000) | 82 | this.timeout(120000) |
95 | 83 | ||
96 | servers = await flushAndRunMultipleServers(2) | 84 | servers = await createMultipleServers(2) |
97 | 85 | ||
98 | // Get the access tokens | 86 | // Get the access tokens |
99 | await setAccessTokensToServers(servers) | 87 | await setAccessTokensToServers(servers) |
@@ -102,14 +90,16 @@ describe('Save replay setting', function () { | |||
102 | // Server 1 and server 2 follow each other | 90 | // Server 1 and server 2 follow each other |
103 | await doubleFollow(servers[0], servers[1]) | 91 | await doubleFollow(servers[0], servers[1]) |
104 | 92 | ||
105 | await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { | 93 | await servers[0].config.updateCustomSubConfig({ |
106 | live: { | 94 | newConfig: { |
107 | enabled: true, | 95 | live: { |
108 | allowReplay: true, | 96 | enabled: true, |
109 | maxDuration: -1, | 97 | allowReplay: true, |
110 | transcoding: { | 98 | maxDuration: -1, |
111 | enabled: false, | 99 | transcoding: { |
112 | resolutions: getCustomConfigResolutions(true) | 100 | enabled: false, |
101 | resolutions: ConfigCommand.getCustomConfigResolutions(true) | ||
102 | } | ||
113 | } | 103 | } |
114 | } | 104 | } |
115 | }) | 105 | }) |
@@ -135,7 +125,7 @@ describe('Save replay setting', function () { | |||
135 | it('Should correctly have updated the live and federated it when streaming in the live', async function () { | 125 | it('Should correctly have updated the live and federated it when streaming in the live', async function () { |
136 | this.timeout(30000) | 126 | this.timeout(30000) |
137 | 127 | ||
138 | ffmpegCommand = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) | 128 | ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) |
139 | 129 | ||
140 | await waitUntilLivePublishedOnAllServers(liveVideoUUID) | 130 | await waitUntilLivePublishedOnAllServers(liveVideoUUID) |
141 | 131 | ||
@@ -151,7 +141,7 @@ describe('Save replay setting', function () { | |||
151 | await stopFfmpeg(ffmpegCommand) | 141 | await stopFfmpeg(ffmpegCommand) |
152 | 142 | ||
153 | for (const server of servers) { | 143 | for (const server of servers) { |
154 | await waitUntilLiveEnded(server.url, server.accessToken, liveVideoUUID) | 144 | await server.live.waitUntilEnded({ videoId: liveVideoUUID }) |
155 | } | 145 | } |
156 | await waitJobs(servers) | 146 | await waitJobs(servers) |
157 | 147 | ||
@@ -160,7 +150,7 @@ describe('Save replay setting', function () { | |||
160 | await checkVideoState(liveVideoUUID, VideoState.LIVE_ENDED) | 150 | await checkVideoState(liveVideoUUID, VideoState.LIVE_ENDED) |
161 | 151 | ||
162 | // No resolutions saved since we did not save replay | 152 | // No resolutions saved since we did not save replay |
163 | await checkLiveCleanup(servers[0], liveVideoUUID, []) | 153 | await checkLiveCleanupAfterSave(servers[0], liveVideoUUID, []) |
164 | }) | 154 | }) |
165 | 155 | ||
166 | it('Should correctly terminate the stream on blacklist and delete the live', async function () { | 156 | it('Should correctly terminate the stream on blacklist and delete the live', async function () { |
@@ -168,7 +158,7 @@ describe('Save replay setting', function () { | |||
168 | 158 | ||
169 | liveVideoUUID = await createLiveWrapper(false) | 159 | liveVideoUUID = await createLiveWrapper(false) |
170 | 160 | ||
171 | ffmpegCommand = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) | 161 | ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) |
172 | 162 | ||
173 | await waitUntilLivePublishedOnAllServers(liveVideoUUID) | 163 | await waitUntilLivePublishedOnAllServers(liveVideoUUID) |
174 | 164 | ||
@@ -176,7 +166,7 @@ describe('Save replay setting', function () { | |||
176 | await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200) | 166 | await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200) |
177 | 167 | ||
178 | await Promise.all([ | 168 | await Promise.all([ |
179 | addVideoToBlacklist(servers[0].url, servers[0].accessToken, liveVideoUUID, 'bad live', true), | 169 | servers[0].blacklist.add({ videoId: liveVideoUUID, reason: 'bad live', unfederate: true }), |
180 | testFfmpegStreamError(ffmpegCommand, true) | 170 | testFfmpegStreamError(ffmpegCommand, true) |
181 | ]) | 171 | ]) |
182 | 172 | ||
@@ -184,12 +174,12 @@ describe('Save replay setting', function () { | |||
184 | 174 | ||
185 | await checkVideosExist(liveVideoUUID, false) | 175 | await checkVideosExist(liveVideoUUID, false) |
186 | 176 | ||
187 | await getVideo(servers[0].url, liveVideoUUID, HttpStatusCode.UNAUTHORIZED_401) | 177 | await servers[0].videos.get({ id: liveVideoUUID, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
188 | await getVideo(servers[1].url, liveVideoUUID, HttpStatusCode.NOT_FOUND_404) | 178 | await servers[1].videos.get({ id: liveVideoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) |
189 | 179 | ||
190 | await wait(5000) | 180 | await wait(5000) |
191 | await waitJobs(servers) | 181 | await waitJobs(servers) |
192 | await checkLiveCleanup(servers[0], liveVideoUUID, []) | 182 | await checkLiveCleanupAfterSave(servers[0], liveVideoUUID, []) |
193 | }) | 183 | }) |
194 | 184 | ||
195 | it('Should correctly terminate the stream on delete and delete the video', async function () { | 185 | it('Should correctly terminate the stream on delete and delete the video', async function () { |
@@ -197,7 +187,7 @@ describe('Save replay setting', function () { | |||
197 | 187 | ||
198 | liveVideoUUID = await createLiveWrapper(false) | 188 | liveVideoUUID = await createLiveWrapper(false) |
199 | 189 | ||
200 | ffmpegCommand = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) | 190 | ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) |
201 | 191 | ||
202 | await waitUntilLivePublishedOnAllServers(liveVideoUUID) | 192 | await waitUntilLivePublishedOnAllServers(liveVideoUUID) |
203 | 193 | ||
@@ -206,14 +196,14 @@ describe('Save replay setting', function () { | |||
206 | 196 | ||
207 | await Promise.all([ | 197 | await Promise.all([ |
208 | testFfmpegStreamError(ffmpegCommand, true), | 198 | testFfmpegStreamError(ffmpegCommand, true), |
209 | removeVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) | 199 | servers[0].videos.remove({ id: liveVideoUUID }) |
210 | ]) | 200 | ]) |
211 | 201 | ||
212 | await wait(5000) | 202 | await wait(5000) |
213 | await waitJobs(servers) | 203 | await waitJobs(servers) |
214 | 204 | ||
215 | await checkVideosExist(liveVideoUUID, false, HttpStatusCode.NOT_FOUND_404) | 205 | await checkVideosExist(liveVideoUUID, false, HttpStatusCode.NOT_FOUND_404) |
216 | await checkLiveCleanup(servers[0], liveVideoUUID, []) | 206 | await checkLiveCleanupAfterSave(servers[0], liveVideoUUID, []) |
217 | }) | 207 | }) |
218 | }) | 208 | }) |
219 | 209 | ||
@@ -233,7 +223,7 @@ describe('Save replay setting', function () { | |||
233 | it('Should correctly have updated the live and federated it when streaming in the live', async function () { | 223 | it('Should correctly have updated the live and federated it when streaming in the live', async function () { |
234 | this.timeout(20000) | 224 | this.timeout(20000) |
235 | 225 | ||
236 | ffmpegCommand = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) | 226 | ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) |
237 | await waitUntilLivePublishedOnAllServers(liveVideoUUID) | 227 | await waitUntilLivePublishedOnAllServers(liveVideoUUID) |
238 | 228 | ||
239 | await waitJobs(servers) | 229 | await waitJobs(servers) |
@@ -258,18 +248,18 @@ describe('Save replay setting', function () { | |||
258 | it('Should update the saved live and correctly federate the updated attributes', async function () { | 248 | it('Should update the saved live and correctly federate the updated attributes', async function () { |
259 | this.timeout(30000) | 249 | this.timeout(30000) |
260 | 250 | ||
261 | await updateVideo(servers[0].url, servers[0].accessToken, liveVideoUUID, { name: 'video updated' }) | 251 | await servers[0].videos.update({ id: liveVideoUUID, attributes: { name: 'video updated' } }) |
262 | await waitJobs(servers) | 252 | await waitJobs(servers) |
263 | 253 | ||
264 | for (const server of servers) { | 254 | for (const server of servers) { |
265 | const res = await getVideo(server.url, liveVideoUUID) | 255 | const video = await server.videos.get({ id: liveVideoUUID }) |
266 | expect(res.body.name).to.equal('video updated') | 256 | expect(video.name).to.equal('video updated') |
267 | expect(res.body.isLive).to.be.false | 257 | expect(video.isLive).to.be.false |
268 | } | 258 | } |
269 | }) | 259 | }) |
270 | 260 | ||
271 | it('Should have cleaned up the live files', async function () { | 261 | it('Should have cleaned up the live files', async function () { |
272 | await checkLiveCleanup(servers[0], liveVideoUUID, [ 720 ]) | 262 | await checkLiveCleanupAfterSave(servers[0], liveVideoUUID, [ 720 ]) |
273 | }) | 263 | }) |
274 | 264 | ||
275 | it('Should correctly terminate the stream on blacklist and blacklist the saved replay video', async function () { | 265 | it('Should correctly terminate the stream on blacklist and blacklist the saved replay video', async function () { |
@@ -277,14 +267,14 @@ describe('Save replay setting', function () { | |||
277 | 267 | ||
278 | liveVideoUUID = await createLiveWrapper(true) | 268 | liveVideoUUID = await createLiveWrapper(true) |
279 | 269 | ||
280 | ffmpegCommand = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) | 270 | ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) |
281 | await waitUntilLivePublishedOnAllServers(liveVideoUUID) | 271 | await waitUntilLivePublishedOnAllServers(liveVideoUUID) |
282 | 272 | ||
283 | await waitJobs(servers) | 273 | await waitJobs(servers) |
284 | await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200) | 274 | await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200) |
285 | 275 | ||
286 | await Promise.all([ | 276 | await Promise.all([ |
287 | addVideoToBlacklist(servers[0].url, servers[0].accessToken, liveVideoUUID, 'bad live', true), | 277 | servers[0].blacklist.add({ videoId: liveVideoUUID, reason: 'bad live', unfederate: true }), |
288 | testFfmpegStreamError(ffmpegCommand, true) | 278 | testFfmpegStreamError(ffmpegCommand, true) |
289 | ]) | 279 | ]) |
290 | 280 | ||
@@ -292,12 +282,12 @@ describe('Save replay setting', function () { | |||
292 | 282 | ||
293 | await checkVideosExist(liveVideoUUID, false) | 283 | await checkVideosExist(liveVideoUUID, false) |
294 | 284 | ||
295 | await getVideo(servers[0].url, liveVideoUUID, HttpStatusCode.UNAUTHORIZED_401) | 285 | await servers[0].videos.get({ id: liveVideoUUID, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
296 | await getVideo(servers[1].url, liveVideoUUID, HttpStatusCode.NOT_FOUND_404) | 286 | await servers[1].videos.get({ id: liveVideoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) |
297 | 287 | ||
298 | await wait(5000) | 288 | await wait(5000) |
299 | await waitJobs(servers) | 289 | await waitJobs(servers) |
300 | await checkLiveCleanup(servers[0], liveVideoUUID, [ 720 ]) | 290 | await checkLiveCleanupAfterSave(servers[0], liveVideoUUID, [ 720 ]) |
301 | }) | 291 | }) |
302 | 292 | ||
303 | it('Should correctly terminate the stream on delete and delete the video', async function () { | 293 | it('Should correctly terminate the stream on delete and delete the video', async function () { |
@@ -305,14 +295,14 @@ describe('Save replay setting', function () { | |||
305 | 295 | ||
306 | liveVideoUUID = await createLiveWrapper(true) | 296 | liveVideoUUID = await createLiveWrapper(true) |
307 | 297 | ||
308 | ffmpegCommand = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) | 298 | ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) |
309 | await waitUntilLivePublishedOnAllServers(liveVideoUUID) | 299 | await waitUntilLivePublishedOnAllServers(liveVideoUUID) |
310 | 300 | ||
311 | await waitJobs(servers) | 301 | await waitJobs(servers) |
312 | await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200) | 302 | await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200) |
313 | 303 | ||
314 | await Promise.all([ | 304 | await Promise.all([ |
315 | removeVideo(servers[0].url, servers[0].accessToken, liveVideoUUID), | 305 | servers[0].videos.remove({ id: liveVideoUUID }), |
316 | testFfmpegStreamError(ffmpegCommand, true) | 306 | testFfmpegStreamError(ffmpegCommand, true) |
317 | ]) | 307 | ]) |
318 | 308 | ||
@@ -320,7 +310,7 @@ describe('Save replay setting', function () { | |||
320 | await waitJobs(servers) | 310 | await waitJobs(servers) |
321 | 311 | ||
322 | await checkVideosExist(liveVideoUUID, false, HttpStatusCode.NOT_FOUND_404) | 312 | await checkVideosExist(liveVideoUUID, false, HttpStatusCode.NOT_FOUND_404) |
323 | await checkLiveCleanup(servers[0], liveVideoUUID, []) | 313 | await checkLiveCleanupAfterSave(servers[0], liveVideoUUID, []) |
324 | }) | 314 | }) |
325 | }) | 315 | }) |
326 | 316 | ||