diff options
Diffstat (limited to 'packages/tests/src/api/server/jobs.ts')
-rw-r--r-- | packages/tests/src/api/server/jobs.ts | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/packages/tests/src/api/server/jobs.ts b/packages/tests/src/api/server/jobs.ts new file mode 100644 index 000000000..3d60b1431 --- /dev/null +++ b/packages/tests/src/api/server/jobs.ts | |||
@@ -0,0 +1,128 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import { expect } from 'chai' | ||
4 | import { dateIsValid } from '@tests/shared/checks.js' | ||
5 | import { wait } from '@peertube/peertube-core-utils' | ||
6 | import { | ||
7 | cleanupTests, | ||
8 | createMultipleServers, | ||
9 | doubleFollow, | ||
10 | PeerTubeServer, | ||
11 | setAccessTokensToServers, | ||
12 | waitJobs | ||
13 | } from '@peertube/peertube-server-commands' | ||
14 | |||
15 | describe('Test jobs', function () { | ||
16 | let servers: PeerTubeServer[] | ||
17 | |||
18 | before(async function () { | ||
19 | this.timeout(240000) | ||
20 | |||
21 | servers = await createMultipleServers(2) | ||
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 () { | ||
30 | this.timeout(240000) | ||
31 | |||
32 | await servers[1].videos.upload({ attributes: { name: 'video1' } }) | ||
33 | await servers[1].videos.upload({ attributes: { name: 'video2' } }) | ||
34 | |||
35 | await waitJobs(servers) | ||
36 | }) | ||
37 | |||
38 | it('Should list jobs', async function () { | ||
39 | const body = await servers[1].jobs.list({ state: 'completed' }) | ||
40 | expect(body.total).to.be.above(2) | ||
41 | expect(body.data).to.have.length.above(2) | ||
42 | }) | ||
43 | |||
44 | it('Should list jobs with sort, pagination and job type', async function () { | ||
45 | { | ||
46 | const body = await servers[1].jobs.list({ | ||
47 | state: 'completed', | ||
48 | start: 1, | ||
49 | count: 2, | ||
50 | sort: 'createdAt' | ||
51 | }) | ||
52 | expect(body.total).to.be.above(2) | ||
53 | expect(body.data).to.have.lengthOf(2) | ||
54 | |||
55 | let job = body.data[0] | ||
56 | // Skip repeat jobs | ||
57 | if (job.type === 'videos-views-stats') job = body.data[1] | ||
58 | |||
59 | expect(job.state).to.equal('completed') | ||
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 | } | ||
64 | |||
65 | { | ||
66 | const body = await servers[1].jobs.list({ | ||
67 | state: 'completed', | ||
68 | start: 0, | ||
69 | count: 100, | ||
70 | sort: 'createdAt', | ||
71 | jobType: 'activitypub-http-broadcast' | ||
72 | }) | ||
73 | expect(body.total).to.be.above(2) | ||
74 | |||
75 | for (const j of body.data) { | ||
76 | expect(j.type).to.equal('activitypub-http-broadcast') | ||
77 | } | ||
78 | } | ||
79 | }) | ||
80 | |||
81 | it('Should list all jobs', async function () { | ||
82 | const body = await servers[1].jobs.list() | ||
83 | expect(body.total).to.be.above(2) | ||
84 | |||
85 | const jobs = body.data | ||
86 | expect(jobs).to.have.length.above(2) | ||
87 | |||
88 | expect(jobs.find(j => j.state === 'completed')).to.not.be.undefined | ||
89 | }) | ||
90 | |||
91 | it('Should pause the job queue', async function () { | ||
92 | this.timeout(120000) | ||
93 | |||
94 | const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video2' } }) | ||
95 | await waitJobs(servers) | ||
96 | |||
97 | await servers[1].jobs.pauseJobQueue() | ||
98 | await servers[1].videos.runTranscoding({ videoId: uuid, transcodingType: 'hls' }) | ||
99 | |||
100 | await wait(5000) | ||
101 | |||
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 | } | ||
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 | |||
125 | after(async function () { | ||
126 | await cleanupTests(servers) | ||
127 | }) | ||
128 | }) | ||