]>
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, | |
7 | dateIsValid, | |
8 | doubleFollow, | |
9 | flushAndRunMultipleServers, | |
10 | ServerInfo, | |
11 | setAccessTokensToServers, | |
12 | uploadVideo, | |
13 | waitJobs | |
14 | } from '@shared/extra-utils' | |
5cd80545 C |
15 | |
16 | const expect = chai.expect | |
17 | ||
18 | describe('Test jobs', function () { | |
19 | let servers: ServerInfo[] | |
20 | ||
21 | before(async function () { | |
22 | this.timeout(30000) | |
23 | ||
24 | servers = await flushAndRunMultipleServers(2) | |
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 () { | |
b345a804 | 33 | this.timeout(60000) |
5cd80545 C |
34 | |
35 | await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video1' }) | |
36 | await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video2' }) | |
37 | ||
3cd0734f | 38 | await waitJobs(servers) |
5cd80545 C |
39 | }) |
40 | ||
41 | it('Should list jobs', async function () { | |
9c6327f8 C |
42 | const body = await servers[1].jobsCommand.getJobsList({ state: 'completed' }) |
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 | { | |
9c6327f8 | 49 | const body = await servers[1].jobsCommand.getJobsList({ |
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 |
9c6327f8 | 60 | if (job.type === 'videos-views') 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 | { |
9c6327f8 | 70 | const body = await servers[1].jobsCommand.getJobsList({ |
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 () { |
9c6327f8 C |
86 | const body = await servers[1].jobsCommand.getJobsList() |
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 | ||
92 | // We know there are a least 1 delayed job (video views) and 1 completed job (broadcast) | |
93 | expect(jobs.find(j => j.state === 'delayed')).to.not.be.undefined | |
94 | expect(jobs.find(j => j.state === 'completed')).to.not.be.undefined | |
95 | }) | |
96 | ||
7c3b7976 C |
97 | after(async function () { |
98 | await cleanupTests(servers) | |
5cd80545 C |
99 | }) |
100 | }) |