From 9c6327f803aaf4200672f1fc40b2f43786daca47 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 7 Jul 2021 09:34:56 +0200 Subject: Introduce jobs command --- server/tests/api/server/handle-down.ts | 7 ++-- server/tests/api/server/jobs.ts | 50 ++++++++++++++--------------- server/tests/api/videos/video-transcoder.ts | 8 ++--- 3 files changed, 28 insertions(+), 37 deletions(-) (limited to 'server') diff --git a/server/tests/api/server/handle-down.ts b/server/tests/api/server/handle-down.ts index eff4451e5..c6202fdaa 100644 --- a/server/tests/api/server/handle-down.ts +++ b/server/tests/api/server/handle-down.ts @@ -10,7 +10,6 @@ import { closeAllSequelize, completeVideoCheck, flushAndRunMultipleServers, - getJobsListPaginationAndSort, getVideo, getVideoCommentThreads, getVideosList, @@ -181,15 +180,13 @@ describe('Test handle downs', function () { const states: JobState[] = [ 'waiting', 'active' ] for (const state of states) { - const res = await getJobsListPaginationAndSort({ - url: servers[0].url, - accessToken: servers[0].accessToken, + const body = await servers[0].jobsCommand.getJobsList({ state: state, start: 0, count: 50, sort: '-createdAt' }) - expect(res.body.data).to.have.length(0) + expect(body.data).to.have.length(0) } }) diff --git a/server/tests/api/server/jobs.ts b/server/tests/api/server/jobs.ts index 6576dd7af..c0b9facff 100644 --- a/server/tests/api/server/jobs.ts +++ b/server/tests/api/server/jobs.ts @@ -2,13 +2,16 @@ import 'mocha' import * as chai from 'chai' -import { cleanupTests, ServerInfo, setAccessTokensToServers } from '../../../../shared/extra-utils/index' -import { dateIsValid } from '../../../../shared/extra-utils/miscs/miscs' -import { doubleFollow } from '../../../../shared/extra-utils/server/follows' -import { getJobsList, getJobsListPaginationAndSort, waitJobs } from '../../../../shared/extra-utils/server/jobs' -import { flushAndRunMultipleServers } from '../../../../shared/extra-utils/server/servers' -import { uploadVideo } from '../../../../shared/extra-utils/videos/videos' -import { Job } from '../../../../shared/models/server' +import { + cleanupTests, + dateIsValid, + doubleFollow, + flushAndRunMultipleServers, + ServerInfo, + setAccessTokensToServers, + uploadVideo, + waitJobs +} from '@shared/extra-utils' const expect = chai.expect @@ -36,27 +39,25 @@ describe('Test jobs', function () { }) it('Should list jobs', async function () { - const res = await getJobsList(servers[1].url, servers[1].accessToken, 'completed') - expect(res.body.total).to.be.above(2) - expect(res.body.data).to.have.length.above(2) + const body = await servers[1].jobsCommand.getJobsList({ state: 'completed' }) + expect(body.total).to.be.above(2) + expect(body.data).to.have.length.above(2) }) it('Should list jobs with sort, pagination and job type', async function () { { - const res = await getJobsListPaginationAndSort({ - url: servers[1].url, - accessToken: servers[1].accessToken, + const body = await servers[1].jobsCommand.getJobsList({ state: 'completed', start: 1, count: 2, sort: 'createdAt' }) - expect(res.body.total).to.be.above(2) - expect(res.body.data).to.have.lengthOf(2) + expect(body.total).to.be.above(2) + expect(body.data).to.have.lengthOf(2) - let job: Job = res.body.data[0] + let job = body.data[0] // Skip repeat jobs - if (job.type === 'videos-views') job = res.body.data[1] + if (job.type === 'videos-views') job = body.data[1] expect(job.state).to.equal('completed') expect(job.type.startsWith('activitypub-')).to.be.true @@ -66,29 +67,26 @@ describe('Test jobs', function () { } { - const res = await getJobsListPaginationAndSort({ - url: servers[1].url, - accessToken: servers[1].accessToken, + const body = await servers[1].jobsCommand.getJobsList({ state: 'completed', start: 0, count: 100, sort: 'createdAt', jobType: 'activitypub-http-broadcast' }) - expect(res.body.total).to.be.above(2) + expect(body.total).to.be.above(2) - for (const j of res.body.data as Job[]) { + for (const j of body.data) { expect(j.type).to.equal('activitypub-http-broadcast') } } }) it('Should list all jobs', async function () { - const res = await getJobsList(servers[1].url, servers[1].accessToken) + const body = await servers[1].jobsCommand.getJobsList() + expect(body.total).to.be.above(2) - const jobs = res.body.data as Job[] - - expect(res.body.total).to.be.above(2) + const jobs = body.data expect(jobs).to.have.length.above(2) // We know there are a least 1 delayed job (video views) and 1 completed job (broadcast) diff --git a/server/tests/api/videos/video-transcoder.ts b/server/tests/api/videos/video-transcoder.ts index ea5ffd239..c95053a29 100644 --- a/server/tests/api/videos/video-transcoder.ts +++ b/server/tests/api/videos/video-transcoder.ts @@ -16,7 +16,6 @@ import { flushAndRunMultipleServers, generateHighBitrateVideo, generateVideoWithFramerate, - getJobsListPaginationAndSort, getMyVideos, getServerFileSize, getVideo, @@ -709,17 +708,14 @@ describe('Test video transcoding', function () { describe('Transcoding job queue', function () { it('Should have the appropriate priorities for transcoding jobs', async function () { - const res = await getJobsListPaginationAndSort({ - url: servers[1].url, - accessToken: servers[1].accessToken, + const body = await servers[1].jobsCommand.getJobsList({ start: 0, count: 100, sort: '-createdAt', jobType: 'video-transcoding' }) - const jobs = res.body.data as Job[] - + const jobs = body.data const transcodingJobs = jobs.filter(j => j.data.videoUUID === video4k) expect(transcodingJobs).to.have.lengthOf(14) -- cgit v1.2.3