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