]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/live/live-permanent.ts
Increase permanent live test timeout
[github/Chocobozzz/PeerTube.git] / server / tests / api / live / live-permanent.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import 'mocha'
4 import * as chai from 'chai'
5 import { LiveVideoCreate, VideoDetails, VideoPrivacy, VideoState } from '@shared/models'
6 import {
7 cleanupTests,
8 createLive,
9 doubleFollow,
10 flushAndRunMultipleServers,
11 getCustomConfigResolutions,
12 getLive,
13 getPlaylistsCount,
14 getVideo,
15 sendRTMPStreamInVideo,
16 ServerInfo,
17 setAccessTokensToServers,
18 setDefaultVideoChannel,
19 stopFfmpeg,
20 updateCustomSubConfig,
21 updateLive,
22 wait,
23 waitJobs,
24 waitUntilLivePublished,
25 waitUntilLiveWaiting
26 } from '../../../../shared/extra-utils'
27
28 const expect = chai.expect
29
30 describe('Permenant live', function () {
31 let servers: ServerInfo[] = []
32 let videoUUID: string
33
34 async function createLiveWrapper (permanentLive: boolean) {
35 const attributes: LiveVideoCreate = {
36 channelId: servers[0].videoChannel.id,
37 privacy: VideoPrivacy.PUBLIC,
38 name: 'my super live',
39 saveReplay: false,
40 permanentLive
41 }
42
43 const res = await createLive(servers[0].url, servers[0].accessToken, attributes)
44 return res.body.video.uuid
45 }
46
47 async function checkVideoState (videoId: string, state: VideoState) {
48 for (const server of servers) {
49 const res = await getVideo(server.url, videoId)
50 expect((res.body as VideoDetails).state.id).to.equal(state)
51 }
52 }
53
54 before(async function () {
55 this.timeout(120000)
56
57 servers = await flushAndRunMultipleServers(2)
58
59 // Get the access tokens
60 await setAccessTokensToServers(servers)
61 await setDefaultVideoChannel(servers)
62
63 // Server 1 and server 2 follow each other
64 await doubleFollow(servers[0], servers[1])
65
66 await updateCustomSubConfig(servers[0].url, servers[0].accessToken, {
67 live: {
68 enabled: true,
69 allowReplay: true,
70 maxDuration: -1,
71 transcoding: {
72 enabled: true,
73 resolutions: getCustomConfigResolutions(true)
74 }
75 }
76 })
77 })
78
79 it('Should create a non permanent live and update it to be a permanent live', async function () {
80 this.timeout(20000)
81
82 const videoUUID = await createLiveWrapper(false)
83
84 {
85 const res = await getLive(servers[0].url, servers[0].accessToken, videoUUID)
86 expect(res.body.permanentLive).to.be.false
87 }
88
89 await updateLive(servers[0].url, servers[0].accessToken, videoUUID, { permanentLive: true })
90
91 {
92 const res = await getLive(servers[0].url, servers[0].accessToken, videoUUID)
93 expect(res.body.permanentLive).to.be.true
94 }
95 })
96
97 it('Should create a permanent live', async function () {
98 this.timeout(20000)
99
100 videoUUID = await createLiveWrapper(true)
101
102 const res = await getLive(servers[0].url, servers[0].accessToken, videoUUID)
103 expect(res.body.permanentLive).to.be.true
104
105 await waitJobs(servers)
106 })
107
108 it('Should stream into this permanent live', async function () {
109 this.timeout(120000)
110
111 const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, videoUUID)
112
113 for (const server of servers) {
114 await waitUntilLivePublished(server.url, server.accessToken, videoUUID)
115 }
116
117 await checkVideoState(videoUUID, VideoState.PUBLISHED)
118
119 await stopFfmpeg(command)
120 await waitUntilLiveWaiting(servers[0].url, servers[0].accessToken, videoUUID)
121
122 await waitJobs(servers)
123 })
124
125 it('Should not have cleaned up this live', async function () {
126 this.timeout(40000)
127
128 await wait(5000)
129 await waitJobs(servers)
130
131 for (const server of servers) {
132 const res = await getVideo(server.url, videoUUID)
133
134 const videoDetails = res.body as VideoDetails
135 expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
136 }
137 })
138
139 it('Should have set this live to waiting for live state', async function () {
140 this.timeout(20000)
141
142 await checkVideoState(videoUUID, VideoState.WAITING_FOR_LIVE)
143 })
144
145 it('Should be able to stream again in the permanent live', async function () {
146 this.timeout(20000)
147
148 await updateCustomSubConfig(servers[0].url, servers[0].accessToken, {
149 live: {
150 enabled: true,
151 allowReplay: true,
152 maxDuration: -1,
153 transcoding: {
154 enabled: true,
155 resolutions: getCustomConfigResolutions(false)
156 }
157 }
158 })
159
160 const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, videoUUID)
161
162 for (const server of servers) {
163 await waitUntilLivePublished(server.url, server.accessToken, videoUUID)
164 }
165
166 await checkVideoState(videoUUID, VideoState.PUBLISHED)
167
168 const count = await getPlaylistsCount(servers[0], videoUUID)
169 // master playlist and 720p playlist
170 expect(count).to.equal(2)
171
172 await stopFfmpeg(command)
173 })
174
175 after(async function () {
176 await cleanupTests(servers)
177 })
178 })