1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import { expect } from 'chai'
import { readFile } from 'fs-extra'
import { checkPersistentTmpIsEmpty, checkVideoDuration } from '@server/tests/shared'
import { buildAbsoluteFixturePath } from '@shared/core-utils'
import {
RunnerJobVideoEditionTranscodingPayload,
VideoEditionTranscodingSuccess,
VideoState,
VideoStudioTask,
VideoStudioTaskIntro
} from '@shared/models'
import {
cleanupTests,
createMultipleServers,
doubleFollow,
PeerTubeServer,
setAccessTokensToServers,
setDefaultVideoChannel,
VideoStudioCommand,
waitJobs
} from '@shared/server-commands'
describe('Test runner video studio transcoding', function () {
let servers: PeerTubeServer[] = []
let runnerToken: string
let videoUUID: string
let jobUUID: string
async function renewStudio (tasks: VideoStudioTask[] = VideoStudioCommand.getComplexTask()) {
const { uuid } = await servers[0].videos.quickUpload({ name: 'video' })
videoUUID = uuid
await waitJobs(servers)
await servers[0].videoStudio.createEditionTasks({ videoId: uuid, tasks })
await waitJobs(servers)
const { availableJobs } = await servers[0].runnerJobs.request({ runnerToken })
expect(availableJobs).to.have.lengthOf(1)
jobUUID = availableJobs[0].uuid
}
before(async function () {
this.timeout(120_000)
servers = await createMultipleServers(2)
await setAccessTokensToServers(servers)
await setDefaultVideoChannel(servers)
await doubleFollow(servers[0], servers[1])
await servers[0].config.enableTranscoding(true, true)
await servers[0].config.enableStudio()
await servers[0].config.enableRemoteStudio()
runnerToken = await servers[0].runners.autoRegisterRunner()
})
it('Should error a studio transcoding job', async function () {
this.timeout(60000)
await renewStudio()
for (let i = 0; i < 5; i++) {
const { job } = await servers[0].runnerJobs.accept({ runnerToken, jobUUID })
const jobToken = job.jobToken
await servers[0].runnerJobs.error({ runnerToken, jobUUID, jobToken, message: 'Error' })
}
const video = await servers[0].videos.get({ id: videoUUID })
expect(video.state.id).to.equal(VideoState.PUBLISHED)
await checkPersistentTmpIsEmpty(servers[0])
})
it('Should cancel a transcoding job', async function () {
this.timeout(60000)
await renewStudio()
await servers[0].runnerJobs.cancelByAdmin({ jobUUID })
const video = await servers[0].videos.get({ id: videoUUID })
expect(video.state.id).to.equal(VideoState.PUBLISHED)
await checkPersistentTmpIsEmpty(servers[0])
})
it('Should execute a remote studio job', async function () {
this.timeout(240_000)
const tasks = [
{
name: 'add-outro' as 'add-outro',
options: {
file: 'video_short.webm'
}
},
{
name: 'add-watermark' as 'add-watermark',
options: {
file: 'thumbnail.png'
}
},
{
name: 'add-intro' as 'add-intro',
options: {
file: 'video_very_short_240p.mp4'
}
}
]
await renewStudio(tasks)
for (const server of servers) {
await checkVideoDuration(server, videoUUID, 5)
}
const { job } = await servers[0].runnerJobs.accept<RunnerJobVideoEditionTranscodingPayload>({ runnerToken, jobUUID })
const jobToken = job.jobToken
expect(job.type === 'video-edition-transcoding')
expect(job.payload.input.videoFileUrl).to.exist
// Check video input file
{
await servers[0].runnerJobs.getJobFile({ url: job.payload.input.videoFileUrl, jobToken, runnerToken })
}
// Check task files
for (let i = 0; i < tasks.length; i++) {
const task = tasks[i]
const payloadTask = job.payload.tasks[i]
expect(payloadTask.name).to.equal(task.name)
const inputFile = await readFile(buildAbsoluteFixturePath(task.options.file))
const { body } = await servers[0].runnerJobs.getJobFile({
url: (payloadTask as VideoStudioTaskIntro).options.file as string,
jobToken,
runnerToken
})
expect(body).to.deep.equal(inputFile)
}
const payload: VideoEditionTranscodingSuccess = { videoFile: 'video_very_short_240p.mp4' }
await servers[0].runnerJobs.success({ runnerToken, jobUUID, jobToken, payload })
await waitJobs(servers)
for (const server of servers) {
await checkVideoDuration(server, videoUUID, 2)
}
await checkPersistentTmpIsEmpty(servers[0])
})
after(async function () {
await cleanupTests(servers)
})
})
|