1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import * as chai from 'chai'
4 import { dateIsValid } from '@server/tests/shared'
5 import { wait } from '@shared/core-utils'
11 setAccessTokensToServers,
13 } from '@shared/server-commands'
15 const expect = chai.expect
17 describe('Test jobs', function () {
18 let servers: PeerTubeServer[]
20 before(async function () {
23 servers = await createMultipleServers(2)
25 await setAccessTokensToServers(servers)
27 // Server 1 and server 2 follow each other
28 await doubleFollow(servers[0], servers[1])
31 it('Should create some jobs', async function () {
34 await servers[1].videos.upload({ attributes: { name: 'video1' } })
35 await servers[1].videos.upload({ attributes: { name: 'video2' } })
37 await waitJobs(servers)
40 it('Should list jobs', async function () {
41 const body = await servers[1].jobs.list({ state: 'completed' })
42 expect(body.total).to.be.above(2)
43 expect(body.data).to.have.length.above(2)
46 it('Should list jobs with sort, pagination and job type', async function () {
48 const body = await servers[1].jobs.list({
54 expect(body.total).to.be.above(2)
55 expect(body.data).to.have.lengthOf(2)
57 let job = body.data[0]
59 if (job.type === 'videos-views-stats') job = body.data[1]
61 expect(job.state).to.equal('completed')
62 expect(dateIsValid(job.createdAt as string)).to.be.true
63 expect(dateIsValid(job.processedOn as string)).to.be.true
64 expect(dateIsValid(job.finishedOn as string)).to.be.true
68 const body = await servers[1].jobs.list({
73 jobType: 'activitypub-http-broadcast'
75 expect(body.total).to.be.above(2)
77 for (const j of body.data) {
78 expect(j.type).to.equal('activitypub-http-broadcast')
83 it('Should list all jobs', async function () {
84 const body = await servers[1].jobs.list()
85 expect(body.total).to.be.above(2)
87 const jobs = body.data
88 expect(jobs).to.have.length.above(2)
90 expect(jobs.find(j => j.state === 'completed')).to.not.be.undefined
93 it('Should pause the job queue', async function () {
96 const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video2' } })
97 await waitJobs(servers)
99 await servers[1].jobs.pauseJobQueue()
100 await servers[1].videos.runTranscoding({ videoId: uuid, transcodingType: 'hls' })
105 const body = await servers[1].jobs.list({ state: 'waiting', jobType: 'video-transcoding' })
106 // waiting includes waiting-children
107 expect(body.data).to.have.lengthOf(4)
111 const body = await servers[1].jobs.list({ state: 'waiting-children', jobType: 'video-transcoding' })
112 expect(body.data).to.have.lengthOf(1)
116 it('Should resume the job queue', async function () {
119 await servers[1].jobs.resumeJobQueue()
121 await waitJobs(servers)
123 const body = await servers[1].jobs.list({ state: 'waiting', jobType: 'video-transcoding' })
124 expect(body.data).to.have.lengthOf(0)
127 after(async function () {
128 await cleanupTests(servers)