]>
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' |
9c6327f8 C |
5 | import { |
6 | cleanupTests, | |
4c7e60bc | 7 | createMultipleServers, |
9c6327f8 C |
8 | dateIsValid, |
9 | doubleFollow, | |
254d3579 | 10 | PeerTubeServer, |
9c6327f8 | 11 | setAccessTokensToServers, |
9c6327f8 C |
12 | waitJobs |
13 | } from '@shared/extra-utils' | |
5cd80545 C |
14 | |
15 | const expect = chai.expect | |
16 | ||
17 | describe('Test jobs', function () { | |
254d3579 | 18 | let servers: PeerTubeServer[] |
5cd80545 C |
19 | |
20 | before(async function () { | |
21 | this.timeout(30000) | |
22 | ||
254d3579 | 23 | servers = await createMultipleServers(2) |
5cd80545 C |
24 | |
25 | await setAccessTokensToServers(servers) | |
26 | ||
27 | // Server 1 and server 2 follow each other | |
28 | await doubleFollow(servers[0], servers[1]) | |
29 | }) | |
30 | ||
31 | it('Should create some jobs', async function () { | |
7926c5f9 | 32 | this.timeout(120000) |
5cd80545 | 33 | |
89d241a7 C |
34 | await servers[1].videos.upload({ attributes: { name: 'video1' } }) |
35 | await servers[1].videos.upload({ attributes: { name: 'video2' } }) | |
5cd80545 | 36 | |
3cd0734f | 37 | await waitJobs(servers) |
5cd80545 C |
38 | }) |
39 | ||
40 | it('Should list jobs', async function () { | |
89d241a7 | 41 | const body = await servers[1].jobs.getJobsList({ state: 'completed' }) |
9c6327f8 C |
42 | expect(body.total).to.be.above(2) |
43 | expect(body.data).to.have.length.above(2) | |
5cd80545 C |
44 | }) |
45 | ||
1061c73f C |
46 | it('Should list jobs with sort, pagination and job type', async function () { |
47 | { | |
89d241a7 | 48 | const body = await servers[1].jobs.getJobsList({ |
1061c73f C |
49 | state: 'completed', |
50 | start: 1, | |
51 | count: 2, | |
52 | sort: 'createdAt' | |
53 | }) | |
9c6327f8 C |
54 | expect(body.total).to.be.above(2) |
55 | expect(body.data).to.have.lengthOf(2) | |
1061c73f | 56 | |
9c6327f8 | 57 | let job = body.data[0] |
1061c73f | 58 | // Skip repeat jobs |
9c6327f8 | 59 | if (job.type === 'videos-views') job = body.data[1] |
1061c73f C |
60 | |
61 | expect(job.state).to.equal('completed') | |
62 | expect(job.type.startsWith('activitypub-')).to.be.true | |
63 | expect(dateIsValid(job.createdAt as string)).to.be.true | |
64 | expect(dateIsValid(job.processedOn as string)).to.be.true | |
65 | expect(dateIsValid(job.finishedOn as string)).to.be.true | |
66 | } | |
5cd80545 | 67 | |
1061c73f | 68 | { |
89d241a7 | 69 | const body = await servers[1].jobs.getJobsList({ |
1061c73f C |
70 | state: 'completed', |
71 | start: 0, | |
72 | count: 100, | |
73 | sort: 'createdAt', | |
74 | jobType: 'activitypub-http-broadcast' | |
75 | }) | |
9c6327f8 | 76 | expect(body.total).to.be.above(2) |
94a5ff8a | 77 | |
9c6327f8 | 78 | for (const j of body.data) { |
1061c73f C |
79 | expect(j.type).to.equal('activitypub-http-broadcast') |
80 | } | |
81 | } | |
5cd80545 C |
82 | }) |
83 | ||
402145b8 | 84 | it('Should list all jobs', async function () { |
89d241a7 | 85 | const body = await servers[1].jobs.getJobsList() |
9c6327f8 | 86 | expect(body.total).to.be.above(2) |
402145b8 | 87 | |
9c6327f8 | 88 | const jobs = body.data |
402145b8 C |
89 | expect(jobs).to.have.length.above(2) |
90 | ||
91 | // We know there are a least 1 delayed job (video views) and 1 completed job (broadcast) | |
92 | expect(jobs.find(j => j.state === 'delayed')).to.not.be.undefined | |
93 | expect(jobs.find(j => j.state === 'completed')).to.not.be.undefined | |
94 | }) | |
95 | ||
7c3b7976 C |
96 | after(async function () { |
97 | await cleanupTests(servers) | |
5cd80545 C |
98 | }) |
99 | }) |