]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/live/live.ts
Add latency setting support
[github/Chocobozzz/PeerTube.git] / server / tests / api / live / live.ts
CommitLineData
af4ae64f
C
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import 'mocha'
4import * as chai from 'chai'
764b1a14 5import { basename, join } from 'path'
c729caf6 6import { ffprobePromise, getVideoStream } from '@server/helpers/ffmpeg'
c55e3d72
C
7import { checkLiveCleanupAfterSave, checkLiveSegmentHash, checkResolutionsInMasterPlaylist, testImage } from '@server/tests/shared'
8import { wait } from '@shared/core-utils'
9import {
10 HttpStatusCode,
11 LiveVideo,
12 LiveVideoCreate,
f443a746 13 LiveVideoLatencyMode,
c55e3d72
C
14 VideoDetails,
15 VideoPrivacy,
16 VideoState,
17 VideoStreamingPlaylistType
18} from '@shared/models'
af4ae64f 19import {
af4ae64f 20 cleanupTests,
254d3579 21 createMultipleServers,
4c7e60bc 22 doubleFollow,
5c0904fc 23 killallServers,
4f219914 24 LiveCommand,
af4ae64f 25 makeRawRequest,
254d3579 26 PeerTubeServer,
4c7e60bc 27 sendRTMPStream,
af4ae64f
C
28 setAccessTokensToServers,
29 setDefaultVideoChannel,
bd54ad19 30 stopFfmpeg,
97969c4e 31 testFfmpegStreamError,
bd54ad19 32 waitJobs,
4f219914 33 waitUntilLivePublishedOnAllServers
bf54587a 34} from '@shared/server-commands'
af4ae64f
C
35
36const expect = chai.expect
37
38describe('Test live', function () {
254d3579 39 let servers: PeerTubeServer[] = []
4f219914 40 let commands: LiveCommand[]
af4ae64f
C
41
42 before(async function () {
43 this.timeout(120000)
44
254d3579 45 servers = await createMultipleServers(2)
af4ae64f
C
46
47 // Get the access tokens
48 await setAccessTokensToServers(servers)
49 await setDefaultVideoChannel(servers)
50
89d241a7 51 await servers[0].config.updateCustomSubConfig({
65e6e260
C
52 newConfig: {
53 live: {
54 enabled: true,
55 allowReplay: true,
f443a746
C
56 latencySetting: {
57 enabled: true
58 },
65e6e260
C
59 transcoding: {
60 enabled: false
61 }
68e70a74 62 }
af4ae64f
C
63 }
64 })
65
66 // Server 1 and server 2 follow each other
67 await doubleFollow(servers[0], servers[1])
4f219914 68
89d241a7 69 commands = servers.map(s => s.live)
af4ae64f
C
70 })
71
72 describe('Live creation, update and delete', function () {
68e70a74 73 let liveVideoUUID: string
af4ae64f
C
74
75 it('Should create a live with the appropriate parameters', async function () {
76 this.timeout(20000)
77
78 const attributes: LiveVideoCreate = {
79 category: 1,
80 licence: 2,
81 language: 'fr',
82 description: 'super live description',
83 support: 'support field',
89d241a7 84 channelId: servers[0].store.channel.id,
af4ae64f
C
85 nsfw: false,
86 waitTranscoding: false,
87 name: 'my super live',
88 tags: [ 'tag1', 'tag2' ],
89 commentsEnabled: false,
90 downloadEnabled: false,
91 saveReplay: true,
f443a746 92 latencyMode: LiveVideoLatencyMode.SMALL_LATENCY,
af4ae64f
C
93 privacy: VideoPrivacy.PUBLIC,
94 previewfile: 'video_short1-preview.webm.jpg',
95 thumbnailfile: 'video_short1.webm.jpg'
96 }
97
04aed767 98 const live = await commands[0].create({ fields: attributes })
4f219914 99 liveVideoUUID = live.uuid
af4ae64f
C
100
101 await waitJobs(servers)
102
103 for (const server of servers) {
89d241a7 104 const video = await server.videos.get({ id: liveVideoUUID })
af4ae64f
C
105
106 expect(video.category.id).to.equal(1)
107 expect(video.licence.id).to.equal(2)
108 expect(video.language.id).to.equal('fr')
109 expect(video.description).to.equal('super live description')
110 expect(video.support).to.equal('support field')
111
89d241a7
C
112 expect(video.channel.name).to.equal(servers[0].store.channel.name)
113 expect(video.channel.host).to.equal(servers[0].store.channel.host)
af4ae64f 114
1ab60243
C
115 expect(video.isLive).to.be.true
116
af4ae64f
C
117 expect(video.nsfw).to.be.false
118 expect(video.waitTranscoding).to.be.false
119 expect(video.name).to.equal('my super live')
120 expect(video.tags).to.deep.equal([ 'tag1', 'tag2' ])
121 expect(video.commentsEnabled).to.be.false
122 expect(video.downloadEnabled).to.be.false
123 expect(video.privacy.id).to.equal(VideoPrivacy.PUBLIC)
124
125 await testImage(server.url, 'video_short1-preview.webm', video.previewPath)
126 await testImage(server.url, 'video_short1.webm', video.thumbnailPath)
127
89d241a7 128 const live = await server.live.get({ videoId: liveVideoUUID })
af4ae64f
C
129
130 if (server.url === servers[0].url) {
c655c9ef 131 expect(live.rtmpUrl).to.equal('rtmp://' + server.hostname + ':' + servers[0].rtmpPort + '/live')
af4ae64f
C
132 expect(live.streamKey).to.not.be.empty
133 } else {
134 expect(live.rtmpUrl).to.be.null
135 expect(live.streamKey).to.be.null
136 }
137
138 expect(live.saveReplay).to.be.true
f443a746 139 expect(live.latencyMode).to.equal(LiveVideoLatencyMode.SMALL_LATENCY)
af4ae64f
C
140 }
141 })
142
143 it('Should have a default preview and thumbnail', async function () {
144 this.timeout(20000)
145
146 const attributes: LiveVideoCreate = {
147 name: 'default live thumbnail',
89d241a7 148 channelId: servers[0].store.channel.id,
af4ae64f
C
149 privacy: VideoPrivacy.UNLISTED,
150 nsfw: true
151 }
152
04aed767 153 const live = await commands[0].create({ fields: attributes })
4f219914 154 const videoId = live.uuid
af4ae64f
C
155
156 await waitJobs(servers)
157
158 for (const server of servers) {
89d241a7 159 const video = await server.videos.get({ id: videoId })
af4ae64f
C
160 expect(video.privacy.id).to.equal(VideoPrivacy.UNLISTED)
161 expect(video.nsfw).to.be.true
162
f2eb23cd
RK
163 await makeRawRequest(server.url + video.thumbnailPath, HttpStatusCode.OK_200)
164 await makeRawRequest(server.url + video.previewPath, HttpStatusCode.OK_200)
af4ae64f
C
165 }
166 })
167
168 it('Should not have the live listed since nobody streams into', async function () {
169 for (const server of servers) {
89d241a7 170 const { total, data } = await server.videos.list()
af4ae64f 171
d23dd9fb
C
172 expect(total).to.equal(0)
173 expect(data).to.have.lengthOf(0)
af4ae64f
C
174 }
175 })
176
177 it('Should not be able to update a live of another server', async function () {
04aed767 178 await commands[1].update({ videoId: liveVideoUUID, fields: { saveReplay: false }, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
af4ae64f
C
179 })
180
181 it('Should update the live', async function () {
182 this.timeout(10000)
183
f443a746 184 await commands[0].update({ videoId: liveVideoUUID, fields: { saveReplay: false, latencyMode: LiveVideoLatencyMode.DEFAULT } })
af4ae64f
C
185 await waitJobs(servers)
186 })
187
188 it('Have the live updated', async function () {
189 for (const server of servers) {
89d241a7 190 const live = await server.live.get({ videoId: liveVideoUUID })
af4ae64f
C
191
192 if (server.url === servers[0].url) {
c655c9ef 193 expect(live.rtmpUrl).to.equal('rtmp://' + server.hostname + ':' + servers[0].rtmpPort + '/live')
af4ae64f
C
194 expect(live.streamKey).to.not.be.empty
195 } else {
196 expect(live.rtmpUrl).to.be.null
197 expect(live.streamKey).to.be.null
198 }
199
200 expect(live.saveReplay).to.be.false
f443a746 201 expect(live.latencyMode).to.equal(LiveVideoLatencyMode.DEFAULT)
af4ae64f
C
202 }
203 })
204
205 it('Delete the live', async function () {
206 this.timeout(10000)
207
89d241a7 208 await servers[0].videos.remove({ id: liveVideoUUID })
af4ae64f
C
209 await waitJobs(servers)
210 })
211
212 it('Should have the live deleted', async function () {
213 for (const server of servers) {
89d241a7
C
214 await server.videos.get({ id: liveVideoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
215 await server.live.get({ videoId: liveVideoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
af4ae64f
C
216 }
217 })
218 })
219
1fd61899 220 describe('Live filters', function () {
4f219914 221 let ffmpegCommand: any
1fd61899
C
222 let liveVideoId: string
223 let vodVideoId: string
224
225 before(async function () {
226 this.timeout(120000)
227
89d241a7 228 vodVideoId = (await servers[0].videos.quickUpload({ name: 'vod video' })).uuid
1fd61899 229
89d241a7 230 const liveOptions = { name: 'live', privacy: VideoPrivacy.PUBLIC, channelId: servers[0].store.channel.id }
04aed767 231 const live = await commands[0].create({ fields: liveOptions })
4f219914 232 liveVideoId = live.uuid
1fd61899 233
89d241a7 234 ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoId })
8ebf2a5d 235 await waitUntilLivePublishedOnAllServers(servers, liveVideoId)
1fd61899
C
236 await waitJobs(servers)
237 })
238
239 it('Should only display lives', async function () {
89d241a7 240 const { data, total } = await servers[0].videos.list({ isLive: true })
1fd61899 241
d23dd9fb
C
242 expect(total).to.equal(1)
243 expect(data).to.have.lengthOf(1)
244 expect(data[0].name).to.equal('live')
1fd61899
C
245 })
246
247 it('Should not display lives', async function () {
89d241a7 248 const { data, total } = await servers[0].videos.list({ isLive: false })
1fd61899 249
d23dd9fb
C
250 expect(total).to.equal(1)
251 expect(data).to.have.lengthOf(1)
252 expect(data[0].name).to.equal('vod video')
1fd61899
C
253 })
254
255 it('Should display my lives', async function () {
256 this.timeout(60000)
257
4f219914 258 await stopFfmpeg(ffmpegCommand)
1fd61899
C
259 await waitJobs(servers)
260
89d241a7 261 const { data } = await servers[0].videos.listMyVideos({ isLive: true })
1fd61899 262
d23dd9fb 263 const result = data.every(v => v.isLive)
1fd61899
C
264 expect(result).to.be.true
265 })
266
267 it('Should not display my lives', async function () {
89d241a7 268 const { data } = await servers[0].videos.listMyVideos({ isLive: false })
1fd61899 269
d23dd9fb 270 const result = data.every(v => !v.isLive)
1fd61899
C
271 expect(result).to.be.true
272 })
273
274 after(async function () {
89d241a7
C
275 await servers[0].videos.remove({ id: vodVideoId })
276 await servers[0].videos.remove({ id: liveVideoId })
1fd61899
C
277 })
278 })
279
68e70a74
C
280 describe('Stream checks', function () {
281 let liveVideo: LiveVideo & VideoDetails
282 let rtmpUrl: string
283
284 before(function () {
c655c9ef 285 rtmpUrl = 'rtmp://' + servers[0].hostname + ':' + servers[0].rtmpPort + ''
68e70a74 286 })
af4ae64f 287
68e70a74 288 async function createLiveWrapper () {
97969c4e
C
289 const liveAttributes = {
290 name: 'user live',
89d241a7 291 channelId: servers[0].store.channel.id,
97969c4e 292 privacy: VideoPrivacy.PUBLIC,
68e70a74 293 saveReplay: false
97969c4e
C
294 }
295
04aed767 296 const { uuid } = await commands[0].create({ fields: liveAttributes })
97969c4e 297
04aed767 298 const live = await commands[0].get({ videoId: uuid })
89d241a7 299 const video = await servers[0].videos.get({ id: uuid })
97969c4e 300
d23dd9fb 301 return Object.assign(video, live)
68e70a74 302 }
97969c4e 303
68e70a74 304 it('Should not allow a stream without the appropriate path', async function () {
2df6f943 305 this.timeout(60000)
97969c4e 306
68e70a74 307 liveVideo = await createLiveWrapper()
97969c4e 308
c826f34a 309 const command = sendRTMPStream({ rtmpBaseUrl: rtmpUrl + '/bad-live', streamKey: liveVideo.streamKey })
68e70a74 310 await testFfmpegStreamError(command, true)
af4ae64f
C
311 })
312
68e70a74 313 it('Should not allow a stream without the appropriate stream key', async function () {
2df6f943 314 this.timeout(60000)
97969c4e 315
c826f34a 316 const command = sendRTMPStream({ rtmpBaseUrl: rtmpUrl + '/live', streamKey: 'bad-stream-key' })
68e70a74 317 await testFfmpegStreamError(command, true)
97969c4e
C
318 })
319
68e70a74 320 it('Should succeed with the correct params', async function () {
2df6f943 321 this.timeout(60000)
97969c4e 322
c826f34a 323 const command = sendRTMPStream({ rtmpBaseUrl: rtmpUrl + '/live', streamKey: liveVideo.streamKey })
68e70a74 324 await testFfmpegStreamError(command, false)
af4ae64f
C
325 })
326
1ab60243
C
327 it('Should list this live now someone stream into it', async function () {
328 for (const server of servers) {
89d241a7 329 const { total, data } = await server.videos.list()
1ab60243 330
d23dd9fb
C
331 expect(total).to.equal(1)
332 expect(data).to.have.lengthOf(1)
1ab60243 333
d23dd9fb 334 const video = data[0]
1ab60243
C
335 expect(video.name).to.equal('user live')
336 expect(video.isLive).to.be.true
337 }
338 })
339
68e70a74 340 it('Should not allow a stream on a live that was blacklisted', async function () {
2df6f943 341 this.timeout(60000)
97969c4e 342
68e70a74 343 liveVideo = await createLiveWrapper()
af4ae64f 344
89d241a7 345 await servers[0].blacklist.add({ videoId: liveVideo.uuid })
af4ae64f 346
c826f34a 347 const command = sendRTMPStream({ rtmpBaseUrl: rtmpUrl + '/live', streamKey: liveVideo.streamKey })
68e70a74 348 await testFfmpegStreamError(command, true)
af4ae64f
C
349 })
350
68e70a74 351 it('Should not allow a stream on a live that was deleted', async function () {
2df6f943 352 this.timeout(60000)
af4ae64f 353
68e70a74 354 liveVideo = await createLiveWrapper()
af4ae64f 355
89d241a7 356 await servers[0].videos.remove({ id: liveVideo.uuid })
af4ae64f 357
c826f34a 358 const command = sendRTMPStream({ rtmpBaseUrl: rtmpUrl + '/live', streamKey: liveVideo.streamKey })
68e70a74 359 await testFfmpegStreamError(command, true)
af4ae64f
C
360 })
361 })
362
363 describe('Live transcoding', function () {
bd54ad19
C
364 let liveVideoId: string
365
366 async function createLiveWrapper (saveReplay: boolean) {
367 const liveAttributes = {
368 name: 'live video',
89d241a7 369 channelId: servers[0].store.channel.id,
bd54ad19
C
370 privacy: VideoPrivacy.PUBLIC,
371 saveReplay
372 }
373
04aed767 374 const { uuid } = await commands[0].create({ fields: liveAttributes })
4f219914 375 return uuid
bd54ad19
C
376 }
377
378 async function testVideoResolutions (liveVideoId: string, resolutions: number[]) {
379 for (const server of servers) {
89d241a7 380 const { data } = await server.videos.list()
d23dd9fb 381 expect(data.find(v => v.uuid === liveVideoId)).to.exist
bd54ad19 382
89d241a7 383 const video = await server.videos.get({ id: liveVideoId })
bd54ad19
C
384
385 expect(video.streamingPlaylists).to.have.lengthOf(1)
386
387 const hlsPlaylist = video.streamingPlaylists.find(s => s.type === VideoStreamingPlaylistType.HLS)
388 expect(hlsPlaylist).to.exist
389
390 // Only finite files are displayed
391 expect(hlsPlaylist.files).to.have.lengthOf(0)
392
57f879a5 393 await checkResolutionsInMasterPlaylist({ server, playlistUrl: hlsPlaylist.playlistUrl, resolutions })
5c0904fc
C
394
395 for (let i = 0; i < resolutions.length; i++) {
a800dbf3 396 const segmentNum = 3
0d8de275 397 const segmentName = `${i}-00000${segmentNum}.ts`
04aed767 398 await commands[0].waitUntilSegmentGeneration({ videoUUID: video.uuid, resolution: i, segment: segmentNum })
5c0904fc 399
89d241a7 400 const subPlaylist = await servers[0].streamingPlaylists.get({
57f879a5
C
401 url: `${servers[0].url}/static/streaming-playlists/hls/${video.uuid}/${i}.m3u8`
402 })
5c0904fc
C
403
404 expect(subPlaylist).to.contain(segmentName)
405
406 const baseUrlAndPath = servers[0].url + '/static/streaming-playlists/hls'
57f879a5
C
407 await checkLiveSegmentHash({
408 server,
409 baseUrlSegment: baseUrlAndPath,
410 videoUUID: video.uuid,
411 segmentName,
412 hlsPlaylist
413 })
5c0904fc 414 }
bd54ad19
C
415 }
416 }
417
418 function updateConf (resolutions: number[]) {
89d241a7 419 return servers[0].config.updateCustomSubConfig({
65e6e260
C
420 newConfig: {
421 live: {
bd54ad19 422 enabled: true,
65e6e260
C
423 allowReplay: true,
424 maxDuration: -1,
425 transcoding: {
426 enabled: true,
427 resolutions: {
8dd754c7 428 '144p': resolutions.includes(144),
65e6e260
C
429 '240p': resolutions.includes(240),
430 '360p': resolutions.includes(360),
431 '480p': resolutions.includes(480),
432 '720p': resolutions.includes(720),
433 '1080p': resolutions.includes(1080),
434 '2160p': resolutions.includes(2160)
435 }
bd54ad19
C
436 }
437 }
438 }
439 })
440 }
441
442 before(async function () {
443 await updateConf([])
444 })
af4ae64f
C
445
446 it('Should enable transcoding without additional resolutions', async function () {
d8fb3a2f 447 this.timeout(120000)
bd54ad19
C
448
449 liveVideoId = await createLiveWrapper(false)
450
4f219914 451 const ffmpegCommand = await commands[0].sendRTMPStreamInVideo({ videoId: liveVideoId })
8ebf2a5d 452 await waitUntilLivePublishedOnAllServers(servers, liveVideoId)
bd54ad19 453 await waitJobs(servers)
af4ae64f 454
bd54ad19
C
455 await testVideoResolutions(liveVideoId, [ 720 ])
456
4f219914 457 await stopFfmpeg(ffmpegCommand)
af4ae64f
C
458 })
459
460 it('Should enable transcoding with some resolutions', async function () {
d8fb3a2f 461 this.timeout(120000)
bd54ad19
C
462
463 const resolutions = [ 240, 480 ]
464 await updateConf(resolutions)
465 liveVideoId = await createLiveWrapper(false)
466
4f219914 467 const ffmpegCommand = await commands[0].sendRTMPStreamInVideo({ videoId: liveVideoId })
8ebf2a5d 468 await waitUntilLivePublishedOnAllServers(servers, liveVideoId)
bd54ad19
C
469 await waitJobs(servers)
470
471 await testVideoResolutions(liveVideoId, resolutions)
472
4f219914 473 await stopFfmpeg(ffmpegCommand)
af4ae64f
C
474 })
475
c826f34a
C
476 it('Should correctly set the appropriate bitrate depending on the input', async function () {
477 this.timeout(120000)
478
479 liveVideoId = await createLiveWrapper(false)
480
481 const ffmpegCommand = await commands[0].sendRTMPStreamInVideo({
482 videoId: liveVideoId,
483 fixtureName: 'video_short.mp4',
484 copyCodecs: true
485 })
486 await waitUntilLivePublishedOnAllServers(servers, liveVideoId)
487 await waitJobs(servers)
488
489 const video = await servers[0].videos.get({ id: liveVideoId })
490
491 const masterPlaylist = video.streamingPlaylists[0].playlistUrl
492 const probe = await ffprobePromise(masterPlaylist)
493
494 const bitrates = probe.streams.map(s => parseInt(s.tags.variant_bitrate))
495 for (const bitrate of bitrates) {
496 expect(bitrate).to.exist
497 expect(isNaN(bitrate)).to.be.false
498 expect(bitrate).to.be.below(61_000_000) // video_short.mp4 bitrate
499 }
500
501 await stopFfmpeg(ffmpegCommand)
502 })
503
af4ae64f 504 it('Should enable transcoding with some resolutions and correctly save them', async function () {
5c08e1c2 505 this.timeout(400_000)
bd54ad19
C
506
507 const resolutions = [ 240, 360, 720 ]
ca5c612b 508
bd54ad19
C
509 await updateConf(resolutions)
510 liveVideoId = await createLiveWrapper(true)
511
4f219914 512 const ffmpegCommand = await commands[0].sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_short2.webm' })
8ebf2a5d 513 await waitUntilLivePublishedOnAllServers(servers, liveVideoId)
bd54ad19
C
514 await waitJobs(servers)
515
516 await testVideoResolutions(liveVideoId, resolutions)
517
4f219914 518 await stopFfmpeg(ffmpegCommand)
04aed767 519 await commands[0].waitUntilEnded({ videoId: liveVideoId })
34caef7f 520
bd54ad19
C
521 await waitJobs(servers)
522
8ebf2a5d 523 await waitUntilLivePublishedOnAllServers(servers, liveVideoId)
e0783718 524
9f430a53
C
525 const maxBitrateLimits = {
526 720: 6500 * 1000, // 60FPS
527 360: 1250 * 1000,
528 240: 700 * 1000
529 }
530
531 const minBitrateLimits = {
532 720: 5500 * 1000,
533 360: 1000 * 1000,
534 240: 550 * 1000
ca5c612b
C
535 }
536
bd54ad19 537 for (const server of servers) {
89d241a7 538 const video = await server.videos.get({ id: liveVideoId })
bd54ad19 539
e0783718 540 expect(video.state.id).to.equal(VideoState.PUBLISHED)
bd54ad19
C
541 expect(video.duration).to.be.greaterThan(1)
542 expect(video.files).to.have.lengthOf(0)
543
544 const hlsPlaylist = video.streamingPlaylists.find(s => s.type === VideoStreamingPlaylistType.HLS)
f2eb23cd
RK
545 await makeRawRequest(hlsPlaylist.playlistUrl, HttpStatusCode.OK_200)
546 await makeRawRequest(hlsPlaylist.segmentsSha256Url, HttpStatusCode.OK_200)
bd54ad19 547
764b1a14
C
548 // We should have generated random filenames
549 expect(basename(hlsPlaylist.playlistUrl)).to.not.equal('master.m3u8')
550 expect(basename(hlsPlaylist.segmentsSha256Url)).to.not.equal('segments-sha256.json')
551
bd54ad19
C
552 expect(hlsPlaylist.files).to.have.lengthOf(resolutions.length)
553
554 for (const resolution of resolutions) {
555 const file = hlsPlaylist.files.find(f => f.resolution.id === resolution)
556
557 expect(file).to.exist
bd54ad19
C
558 expect(file.size).to.be.greaterThan(1)
559
884d2c39
C
560 if (resolution >= 720) {
561 expect(file.fps).to.be.approximately(60, 2)
562 } else {
563 expect(file.fps).to.be.approximately(30, 2)
564 }
565
764b1a14
C
566 const filename = basename(file.fileUrl)
567 expect(filename).to.not.contain(video.uuid)
568
89d241a7 569 const segmentPath = servers[0].servers.buildDirectory(join('streaming-playlists', 'hls', video.uuid, filename))
ca5c612b
C
570
571 const probe = await ffprobePromise(segmentPath)
c729caf6 572 const videoStream = await getVideoStream(segmentPath, probe)
6b67897e 573
9f430a53
C
574 expect(probe.format.bit_rate).to.be.below(maxBitrateLimits[videoStream.height])
575 expect(probe.format.bit_rate).to.be.at.least(minBitrateLimits[videoStream.height])
ca5c612b 576
f2eb23cd
RK
577 await makeRawRequest(file.torrentUrl, HttpStatusCode.OK_200)
578 await makeRawRequest(file.fileUrl, HttpStatusCode.OK_200)
bd54ad19
C
579 }
580 }
af4ae64f
C
581 })
582
583 it('Should correctly have cleaned up the live files', async function () {
bd54ad19
C
584 this.timeout(30000)
585
764b1a14 586 await checkLiveCleanupAfterSave(servers[0], liveVideoId, [ 240, 360, 720 ])
af4ae64f
C
587 })
588 })
589
5c0904fc
C
590 describe('After a server restart', function () {
591 let liveVideoId: string
592 let liveVideoReplayId: string
593
594 async function createLiveWrapper (saveReplay: boolean) {
595 const liveAttributes = {
596 name: 'live video',
89d241a7 597 channelId: servers[0].store.channel.id,
5c0904fc
C
598 privacy: VideoPrivacy.PUBLIC,
599 saveReplay
600 }
601
04aed767 602 const { uuid } = await commands[0].create({ fields: liveAttributes })
4f219914 603 return uuid
5c0904fc
C
604 }
605
606 before(async function () {
0d8de275 607 this.timeout(120000)
5c0904fc
C
608
609 liveVideoId = await createLiveWrapper(false)
610 liveVideoReplayId = await createLiveWrapper(true)
611
612 await Promise.all([
4f219914
C
613 commands[0].sendRTMPStreamInVideo({ videoId: liveVideoId }),
614 commands[0].sendRTMPStreamInVideo({ videoId: liveVideoReplayId })
5c0904fc
C
615 ])
616
617 await Promise.all([
04aed767
C
618 commands[0].waitUntilPublished({ videoId: liveVideoId }),
619 commands[0].waitUntilPublished({ videoId: liveVideoReplayId })
5c0904fc
C
620 ])
621
04aed767
C
622 await commands[0].waitUntilSegmentGeneration({ videoUUID: liveVideoId, resolution: 0, segment: 2 })
623 await commands[0].waitUntilSegmentGeneration({ videoUUID: liveVideoReplayId, resolution: 0, segment: 2 })
0d8de275 624
9293139f 625 await killallServers([ servers[0] ])
254d3579 626 await servers[0].run()
5c0904fc
C
627
628 await wait(5000)
629 })
630
631 it('Should cleanup lives', async function () {
632 this.timeout(60000)
633
04aed767 634 await commands[0].waitUntilEnded({ videoId: liveVideoId })
5c0904fc
C
635 })
636
637 it('Should save a live replay', async function () {
0d8de275 638 this.timeout(120000)
5c0904fc 639
04aed767 640 await commands[0].waitUntilPublished({ videoId: liveVideoReplayId })
5c0904fc
C
641 })
642 })
643
af4ae64f
C
644 after(async function () {
645 await cleanupTests(servers)
646 })
647})