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