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