]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/object-storage/live.ts
Fix removed sha segments on fast restream
[github/Chocobozzz/PeerTube.git] / server / tests / api / object-storage / live.ts
CommitLineData
0305db28
JB
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import 'mocha'
4import * as chai from 'chai'
c55e3d72
C
5import { expectStartWith } from '@server/tests/shared'
6import { areObjectStorageTestsDisabled } from '@shared/core-utils'
7import { HttpStatusCode, LiveVideoCreate, VideoFile, VideoPrivacy } from '@shared/models'
0305db28 8import {
0305db28
JB
9 createMultipleServers,
10 doubleFollow,
4ec52d04 11 findExternalSavedVideo,
0305db28
JB
12 killallServers,
13 makeRawRequest,
14 ObjectStorageCommand,
15 PeerTubeServer,
16 setAccessTokensToServers,
17 setDefaultVideoChannel,
18 stopFfmpeg,
19 waitJobs,
20 waitUntilLivePublishedOnAllServers,
4ec52d04
C
21 waitUntilLiveReplacedByReplayOnAllServers,
22 waitUntilLiveWaitingOnAllServers
bf54587a 23} from '@shared/server-commands'
0305db28
JB
24
25const expect = chai.expect
26
4ec52d04 27async function createLive (server: PeerTubeServer, permanent: boolean) {
0305db28
JB
28 const attributes: LiveVideoCreate = {
29 channelId: server.store.channel.id,
30 privacy: VideoPrivacy.PUBLIC,
31 name: 'my super live',
4ec52d04
C
32 saveReplay: true,
33 permanentLive: permanent
0305db28
JB
34 }
35
36 const { uuid } = await server.live.create({ fields: attributes })
37
38 return uuid
39}
40
41async function checkFiles (files: VideoFile[]) {
42 for (const file of files) {
43 expectStartWith(file.fileUrl, ObjectStorageCommand.getPlaylistBaseUrl())
44
45 await makeRawRequest(file.fileUrl, HttpStatusCode.OK_200)
46 }
47}
48
4ec52d04
C
49async function getFiles (server: PeerTubeServer, videoUUID: string) {
50 const video = await server.videos.get({ id: videoUUID })
51
52 expect(video.files).to.have.lengthOf(0)
53 expect(video.streamingPlaylists).to.have.lengthOf(1)
54
55 return video.streamingPlaylists[0].files
56}
57
58async function streamAndEnd (servers: PeerTubeServer[], liveUUID: string) {
59 const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveUUID })
60 await waitUntilLivePublishedOnAllServers(servers, liveUUID)
61
62 const videoLiveDetails = await servers[0].videos.get({ id: liveUUID })
63 const liveDetails = await servers[0].live.get({ videoId: liveUUID })
64
65 await stopFfmpeg(ffmpegCommand)
66
67 if (liveDetails.permanentLive) {
68 await waitUntilLiveWaitingOnAllServers(servers, liveUUID)
69 } else {
70 await waitUntilLiveReplacedByReplayOnAllServers(servers, liveUUID)
71 }
72
73 await waitJobs(servers)
74
75 return { videoLiveDetails, liveDetails }
76}
77
0305db28
JB
78describe('Object storage for lives', function () {
79 if (areObjectStorageTestsDisabled()) return
80
0305db28 81 let servers: PeerTubeServer[]
0305db28
JB
82
83 before(async function () {
84 this.timeout(120000)
85
86 await ObjectStorageCommand.prepareDefaultBuckets()
87
88 servers = await createMultipleServers(2, ObjectStorageCommand.getDefaultConfig())
89
90 await setAccessTokensToServers(servers)
91 await setDefaultVideoChannel(servers)
92 await doubleFollow(servers[0], servers[1])
93
94 await servers[0].config.enableTranscoding()
95 })
96
97 describe('Without live transcoding', async function () {
4ec52d04 98 let videoUUID: string
0305db28
JB
99
100 before(async function () {
101 await servers[0].config.enableLive({ transcoding: false })
102
4ec52d04 103 videoUUID = await createLive(servers[0], false)
0305db28
JB
104 })
105
106 it('Should create a live and save the replay on object storage', async function () {
107 this.timeout(220000)
108
4ec52d04 109 await streamAndEnd(servers, videoUUID)
0305db28
JB
110
111 for (const server of servers) {
4ec52d04
C
112 const files = await getFiles(server, videoUUID)
113 expect(files).to.have.lengthOf(1)
0305db28
JB
114
115 await checkFiles(files)
116 }
117 })
118 })
119
120 describe('With live transcoding', async function () {
4ec52d04
C
121 let videoUUIDPermanent: string
122 let videoUUIDNonPermanent: string
0305db28
JB
123
124 before(async function () {
125 await servers[0].config.enableLive({ transcoding: true })
126
4ec52d04
C
127 videoUUIDPermanent = await createLive(servers[0], true)
128 videoUUIDNonPermanent = await createLive(servers[0], false)
0305db28
JB
129 })
130
4ec52d04 131 it('Should create a live and save the replay on object storage', async function () {
0305db28
JB
132 this.timeout(240000)
133
4ec52d04 134 await streamAndEnd(servers, videoUUIDNonPermanent)
0305db28 135
4ec52d04
C
136 for (const server of servers) {
137 const files = await getFiles(server, videoUUIDNonPermanent)
138 expect(files).to.have.lengthOf(5)
0305db28 139
4ec52d04
C
140 await checkFiles(files)
141 }
142 })
0305db28 143
4ec52d04
C
144 it('Should create a live and save the replay of permanent live on object storage', async function () {
145 this.timeout(240000)
146
147 const { videoLiveDetails } = await streamAndEnd(servers, videoUUIDPermanent)
0305db28 148
4ec52d04 149 const replay = await findExternalSavedVideo(servers[0], videoLiveDetails)
0305db28 150
4ec52d04
C
151 for (const server of servers) {
152 const files = await getFiles(server, replay.uuid)
8dd754c7 153 expect(files).to.have.lengthOf(5)
0305db28
JB
154
155 await checkFiles(files)
156 }
157 })
158 })
159
160 after(async function () {
161 await killallServers(servers)
162 })
163})