]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/server/jobs.ts
Bumped to version v5.2.1
[github/Chocobozzz/PeerTube.git] / server / tests / api / server / jobs.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
5cd80545 2
86347717 3import { expect } from 'chai'
c55e3d72 4import { dateIsValid } from '@server/tests/shared'
db1ccd05 5import { wait } from '@shared/core-utils'
9c6327f8
C
6import {
7 cleanupTests,
4c7e60bc 8 createMultipleServers,
9c6327f8 9 doubleFollow,
254d3579 10 PeerTubeServer,
9c6327f8 11 setAccessTokensToServers,
9c6327f8 12 waitJobs
bf54587a 13} from '@shared/server-commands'
5cd80545 14
5cd80545 15describe('Test jobs', function () {
254d3579 16 let servers: PeerTubeServer[]
5cd80545
C
17
18 before(async function () {
7804e577 19 this.timeout(240000)
5cd80545 20
254d3579 21 servers = await createMultipleServers(2)
5cd80545
C
22
23 await setAccessTokensToServers(servers)
24
25 // Server 1 and server 2 follow each other
26 await doubleFollow(servers[0], servers[1])
27 })
28
29 it('Should create some jobs', async function () {
ea139ca8 30 this.timeout(240000)
5cd80545 31
89d241a7
C
32 await servers[1].videos.upload({ attributes: { name: 'video1' } })
33 await servers[1].videos.upload({ attributes: { name: 'video2' } })
5cd80545 34
3cd0734f 35 await waitJobs(servers)
5cd80545
C
36 })
37
38 it('Should list jobs', async function () {
851675c5 39 const body = await servers[1].jobs.list({ state: 'completed' })
9c6327f8
C
40 expect(body.total).to.be.above(2)
41 expect(body.data).to.have.length.above(2)
5cd80545
C
42 })
43
1061c73f
C
44 it('Should list jobs with sort, pagination and job type', async function () {
45 {
851675c5 46 const body = await servers[1].jobs.list({
1061c73f
C
47 state: 'completed',
48 start: 1,
49 count: 2,
50 sort: 'createdAt'
51 })
9c6327f8
C
52 expect(body.total).to.be.above(2)
53 expect(body.data).to.have.lengthOf(2)
1061c73f 54
9c6327f8 55 let job = body.data[0]
1061c73f 56 // Skip repeat jobs
51353d9a 57 if (job.type === 'videos-views-stats') job = body.data[1]
1061c73f
C
58
59 expect(job.state).to.equal('completed')
1061c73f
C
60 expect(dateIsValid(job.createdAt as string)).to.be.true
61 expect(dateIsValid(job.processedOn as string)).to.be.true
62 expect(dateIsValid(job.finishedOn as string)).to.be.true
63 }
5cd80545 64
1061c73f 65 {
851675c5 66 const body = await servers[1].jobs.list({
1061c73f
C
67 state: 'completed',
68 start: 0,
69 count: 100,
70 sort: 'createdAt',
71 jobType: 'activitypub-http-broadcast'
72 })
9c6327f8 73 expect(body.total).to.be.above(2)
94a5ff8a 74
9c6327f8 75 for (const j of body.data) {
1061c73f
C
76 expect(j.type).to.equal('activitypub-http-broadcast')
77 }
78 }
5cd80545
C
79 })
80
402145b8 81 it('Should list all jobs', async function () {
851675c5 82 const body = await servers[1].jobs.list()
9c6327f8 83 expect(body.total).to.be.above(2)
402145b8 84
9c6327f8 85 const jobs = body.data
402145b8
C
86 expect(jobs).to.have.length.above(2)
87
402145b8
C
88 expect(jobs.find(j => j.state === 'completed')).to.not.be.undefined
89 })
90
419b520c
C
91 it('Should pause the job queue', async function () {
92 this.timeout(120000)
93
52fe4b67
C
94 const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video2' } })
95 await waitJobs(servers)
419b520c 96
52fe4b67
C
97 await servers[1].jobs.pauseJobQueue()
98 await servers[1].videos.runTranscoding({ videoId: uuid, transcodingType: 'hls' })
419b520c
C
99
100 await wait(5000)
101
e2b2c726
C
102 {
103 const body = await servers[1].jobs.list({ state: 'waiting', jobType: 'video-transcoding' })
104 // waiting includes waiting-children
105 expect(body.data).to.have.lengthOf(4)
106 }
107
108 {
109 const body = await servers[1].jobs.list({ state: 'waiting-children', jobType: 'video-transcoding' })
110 expect(body.data).to.have.lengthOf(1)
111 }
419b520c
C
112 })
113
114 it('Should resume the job queue', async function () {
115 this.timeout(120000)
116
117 await servers[1].jobs.resumeJobQueue()
118
119 await waitJobs(servers)
120
121 const body = await servers[1].jobs.list({ state: 'waiting', jobType: 'video-transcoding' })
122 expect(body.data).to.have.lengthOf(0)
123 })
124
7c3b7976
C
125 after(async function () {
126 await cleanupTests(servers)
5cd80545
C
127 })
128})