PeerTube/packages/tests/src/api/server/jobs.ts

129 lines
3.5 KiB
TypeScript
Raw Normal View History

2020-01-31 16:56:52 +01:00
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2017-11-30 10:51:13 +01:00
2022-08-17 15:44:32 +02:00
import { expect } from 'chai'
import { dateIsValid } from '@tests/shared/checks.js'
import { wait } from '@peertube/peertube-core-utils'
2021-07-07 09:34:56 +02:00
import {
cleanupTests,
2021-07-16 14:27:30 +02:00
createMultipleServers,
2021-07-07 09:34:56 +02:00
doubleFollow,
2021-07-16 09:47:51 +02:00
PeerTubeServer,
2021-07-07 09:34:56 +02:00
setAccessTokensToServers,
waitJobs
} from '@peertube/peertube-server-commands'
2017-11-30 10:51:13 +01:00
describe('Test jobs', function () {
2021-07-16 09:47:51 +02:00
let servers: PeerTubeServer[]
2017-11-30 10:51:13 +01:00
before(async function () {
2022-08-16 14:49:16 +02:00
this.timeout(240000)
2017-11-30 10:51:13 +01:00
2021-07-16 09:47:51 +02:00
servers = await createMultipleServers(2)
2017-11-30 10:51:13 +01:00
await setAccessTokensToServers(servers)
// Server 1 and server 2 follow each other
await doubleFollow(servers[0], servers[1])
})
it('Should create some jobs', async function () {
this.timeout(240000)
2017-11-30 10:51:13 +01:00
2021-07-16 09:04:35 +02:00
await servers[1].videos.upload({ attributes: { name: 'video1' } })
await servers[1].videos.upload({ attributes: { name: 'video2' } })
2017-11-30 10:51:13 +01:00
await waitJobs(servers)
2017-11-30 10:51:13 +01:00
})
it('Should list jobs', async function () {
2021-08-25 15:13:41 +02:00
const body = await servers[1].jobs.list({ state: 'completed' })
2021-07-07 09:34:56 +02:00
expect(body.total).to.be.above(2)
expect(body.data).to.have.length.above(2)
2017-11-30 10:51:13 +01:00
})
2019-12-04 14:49:59 +01:00
it('Should list jobs with sort, pagination and job type', async function () {
{
2021-08-25 15:13:41 +02:00
const body = await servers[1].jobs.list({
2019-12-04 14:49:59 +01:00
state: 'completed',
start: 1,
count: 2,
sort: 'createdAt'
})
2021-07-07 09:34:56 +02:00
expect(body.total).to.be.above(2)
expect(body.data).to.have.lengthOf(2)
2019-12-04 14:49:59 +01:00
2021-07-07 09:34:56 +02:00
let job = body.data[0]
2019-12-04 14:49:59 +01:00
// Skip repeat jobs
if (job.type === 'videos-views-stats') job = body.data[1]
2019-12-04 14:49:59 +01:00
expect(job.state).to.equal('completed')
expect(dateIsValid(job.createdAt as string)).to.be.true
expect(dateIsValid(job.processedOn as string)).to.be.true
expect(dateIsValid(job.finishedOn as string)).to.be.true
}
2017-11-30 10:51:13 +01:00
2019-12-04 14:49:59 +01:00
{
2021-08-25 15:13:41 +02:00
const body = await servers[1].jobs.list({
2019-12-04 14:49:59 +01:00
state: 'completed',
start: 0,
count: 100,
sort: 'createdAt',
jobType: 'activitypub-http-broadcast'
})
2021-07-07 09:34:56 +02:00
expect(body.total).to.be.above(2)
2021-07-07 09:34:56 +02:00
for (const j of body.data) {
2019-12-04 14:49:59 +01:00
expect(j.type).to.equal('activitypub-http-broadcast')
}
}
2017-11-30 10:51:13 +01:00
})
2020-12-14 12:00:35 +01:00
it('Should list all jobs', async function () {
2021-08-25 15:13:41 +02:00
const body = await servers[1].jobs.list()
2021-07-07 09:34:56 +02:00
expect(body.total).to.be.above(2)
2020-12-14 12:00:35 +01:00
2021-07-07 09:34:56 +02:00
const jobs = body.data
2020-12-14 12:00:35 +01:00
expect(jobs).to.have.length.above(2)
expect(jobs.find(j => j.state === 'completed')).to.not.be.undefined
})
it('Should pause the job queue', async function () {
this.timeout(120000)
2022-03-16 18:21:36 +01:00
const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video2' } })
await waitJobs(servers)
2022-03-16 18:21:36 +01:00
await servers[1].jobs.pauseJobQueue()
await servers[1].videos.runTranscoding({ videoId: uuid, transcodingType: 'hls' })
await wait(5000)
2022-08-09 11:35:07 +02:00
{
const body = await servers[1].jobs.list({ state: 'waiting', jobType: 'video-transcoding' })
// waiting includes waiting-children
expect(body.data).to.have.lengthOf(4)
}
{
const body = await servers[1].jobs.list({ state: 'waiting-children', jobType: 'video-transcoding' })
expect(body.data).to.have.lengthOf(1)
}
})
it('Should resume the job queue', async function () {
this.timeout(120000)
await servers[1].jobs.resumeJobQueue()
await waitJobs(servers)
const body = await servers[1].jobs.list({ state: 'waiting', jobType: 'video-transcoding' })
expect(body.data).to.have.lengthOf(0)
})
2019-04-24 15:10:37 +02:00
after(async function () {
await cleanupTests(servers)
2017-11-30 10:51:13 +01:00
})
})