aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/api/check-params/jobs.ts11
-rw-r--r--server/tests/api/server/handle-down.ts10
-rw-r--r--server/tests/api/server/jobs.ts10
-rw-r--r--server/tests/api/videos/multiple-servers.ts21
-rw-r--r--server/tests/real-world/real-world.ts21
-rw-r--r--server/tests/utils/server/jobs.ts9
6 files changed, 45 insertions, 37 deletions
diff --git a/server/tests/api/check-params/jobs.ts b/server/tests/api/check-params/jobs.ts
index b12818bb1..ce3ac8809 100644
--- a/server/tests/api/check-params/jobs.ts
+++ b/server/tests/api/check-params/jobs.ts
@@ -7,7 +7,7 @@ import { checkBadCountPagination, checkBadSortPagination, checkBadStartPaginatio
7import { makeGetRequest } from '../../utils/requests/requests' 7import { makeGetRequest } from '../../utils/requests/requests'
8 8
9describe('Test jobs API validators', function () { 9describe('Test jobs API validators', function () {
10 const path = '/api/v1/jobs/' 10 const path = '/api/v1/jobs/failed'
11 let server: ServerInfo 11 let server: ServerInfo
12 let userAccessToken = '' 12 let userAccessToken = ''
13 13
@@ -31,6 +31,15 @@ describe('Test jobs API validators', function () {
31 }) 31 })
32 32
33 describe('When listing jobs', function () { 33 describe('When listing jobs', function () {
34
35 it('Should fail with a bad state', async function () {
36 await makeGetRequest({
37 url: server.url,
38 token: server.accessToken,
39 path: path + 'ade'
40 })
41 })
42
34 it('Should fail with a bad start pagination', async function () { 43 it('Should fail with a bad start pagination', async function () {
35 await checkBadStartPagination(server.url, path, server.accessToken) 44 await checkBadStartPagination(server.url, path, server.accessToken)
36 }) 45 })
diff --git a/server/tests/api/server/handle-down.ts b/server/tests/api/server/handle-down.ts
index de4e77b2f..4cedeb89e 100644
--- a/server/tests/api/server/handle-down.ts
+++ b/server/tests/api/server/handle-down.ts
@@ -2,6 +2,7 @@
2 2
3import * as chai from 'chai' 3import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { JobState } from '../../../../shared/models'
5import { VideoPrivacy } from '../../../../shared/models/videos' 6import { VideoPrivacy } from '../../../../shared/models/videos'
6import { VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model' 7import { VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model'
7import { completeVideoCheck, getVideo, immutableAssign, reRunServer, viewVideo } from '../../utils' 8import { completeVideoCheck, getVideo, immutableAssign, reRunServer, viewVideo } from '../../utils'
@@ -139,12 +140,11 @@ describe('Test handle downs', function () {
139 }) 140 })
140 141
141 it('Should not have pending/processing jobs anymore', async function () { 142 it('Should not have pending/processing jobs anymore', async function () {
142 const res = await getJobsListPaginationAndSort(servers[0].url, servers[0].accessToken, 0, 50, '-createdAt') 143 const states: JobState[] = [ 'inactive', 'active' ]
143 const jobs = res.body.data
144 144
145 for (const job of jobs) { 145 for (const state of states) {
146 expect(job.state).not.to.equal('pending') 146 const res = await getJobsListPaginationAndSort(servers[ 0 ].url, servers[ 0 ].accessToken, state,0, 50, '-createdAt')
147 expect(job.state).not.to.equal('processing') 147 expect(res.body.data).to.have.length(0)
148 } 148 }
149 }) 149 })
150 150
diff --git a/server/tests/api/server/jobs.ts b/server/tests/api/server/jobs.ts
index 2e17e71a4..671498769 100644
--- a/server/tests/api/server/jobs.ts
+++ b/server/tests/api/server/jobs.ts
@@ -35,20 +35,20 @@ describe('Test jobs', function () {
35 }) 35 })
36 36
37 it('Should list jobs', async function () { 37 it('Should list jobs', async function () {
38 const res = await getJobsList(servers[1].url, servers[1].accessToken) 38 const res = await getJobsList(servers[1].url, servers[1].accessToken, 'complete')
39 expect(res.body.total).to.be.above(2) 39 expect(res.body.total).to.be.above(2)
40 expect(res.body.data).to.have.length.above(2) 40 expect(res.body.data).to.have.length.above(2)
41 }) 41 })
42 42
43 it('Should list jobs with sort and pagination', async function () { 43 it('Should list jobs with sort and pagination', async function () {
44 const res = await getJobsListPaginationAndSort(servers[1].url, servers[1].accessToken, 4, 1, 'createdAt') 44 const res = await getJobsListPaginationAndSort(servers[1].url, servers[1].accessToken, 'complete', 1, 1, 'createdAt')
45 expect(res.body.total).to.be.above(2) 45 expect(res.body.total).to.be.above(2)
46 expect(res.body.data).to.have.lengthOf(1) 46 expect(res.body.data).to.have.lengthOf(1)
47 47
48 const job = res.body.data[0] 48 const job = res.body.data[0]
49 expect(job.state).to.equal('success') 49
50 expect(job.category).to.equal('transcoding') 50 expect(job.state).to.equal('complete')
51 expect(job.handlerName).to.have.length.above(3) 51 expect(job.type).to.equal('activitypub-http-unicast')
52 expect(dateIsValid(job.createdAt)).to.be.true 52 expect(dateIsValid(job.createdAt)).to.be.true
53 expect(dateIsValid(job.updatedAt)).to.be.true 53 expect(dateIsValid(job.updatedAt)).to.be.true
54 }) 54 })
diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts
index 4c4b5123d..0215b3011 100644
--- a/server/tests/api/videos/multiple-servers.ts
+++ b/server/tests/api/videos/multiple-servers.ts
@@ -475,16 +475,17 @@ describe('Test multiple servers', function () {
475 it('Should like and dislikes videos on different services', async function () { 475 it('Should like and dislikes videos on different services', async function () {
476 this.timeout(20000) 476 this.timeout(20000)
477 477
478 const tasks: Promise<any>[] = [] 478 await rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'like')
479 tasks.push(rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'like')) 479 await wait(200)
480 tasks.push(rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'dislike')) 480 await rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'dislike')
481 tasks.push(rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'like')) 481 await wait(200)
482 tasks.push(rateVideo(servers[2].url, servers[2].accessToken, localVideosServer3[1], 'like')) 482 await rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'like')
483 tasks.push(rateVideo(servers[2].url, servers[2].accessToken, localVideosServer3[1], 'dislike')) 483 await rateVideo(servers[2].url, servers[2].accessToken, localVideosServer3[1], 'like')
484 tasks.push(rateVideo(servers[2].url, servers[2].accessToken, remoteVideosServer3[1], 'dislike')) 484 await wait(200)
485 tasks.push(rateVideo(servers[2].url, servers[2].accessToken, remoteVideosServer3[0], 'like')) 485 await rateVideo(servers[2].url, servers[2].accessToken, localVideosServer3[1], 'dislike')
486 486 await rateVideo(servers[2].url, servers[2].accessToken, remoteVideosServer3[1], 'dislike')
487 await Promise.all(tasks) 487 await wait(200)
488 await rateVideo(servers[2].url, servers[2].accessToken, remoteVideosServer3[0], 'like')
488 489
489 await wait(10000) 490 await wait(10000)
490 491
diff --git a/server/tests/real-world/real-world.ts b/server/tests/real-world/real-world.ts
index e41203351..7f67525ed 100644
--- a/server/tests/real-world/real-world.ts
+++ b/server/tests/real-world/real-world.ts
@@ -3,6 +3,7 @@ process.env.NODE_ENV = 'test'
3 3
4import * as program from 'commander' 4import * as program from 'commander'
5import { Video, VideoFile, VideoRateType } from '../../../shared' 5import { Video, VideoFile, VideoRateType } from '../../../shared'
6import { JobState } from '../../../shared/models'
6import { 7import {
7 flushAndRunMultipleServers, 8 flushAndRunMultipleServers,
8 flushTests, follow, 9 flushTests, follow,
@@ -346,23 +347,19 @@ function goodbye () {
346} 347}
347 348
348async function isTherePendingRequests (servers: ServerInfo[]) { 349async function isTherePendingRequests (servers: ServerInfo[]) {
350 const states: JobState[] = [ 'inactive', 'active' ]
349 const tasks: Promise<any>[] = [] 351 const tasks: Promise<any>[] = []
350 let pendingRequests = false 352 let pendingRequests = false
351 353
352 // Check if each server has pending request 354 // Check if each server has pending request
353 for (const server of servers) { 355 for (const server of servers) {
354 const p = getJobsListPaginationAndSort(server.url, server.accessToken, 0, 10, '-createdAt') 356 for (const state of states) {
355 .then(res => { 357 const p = getJobsListPaginationAndSort(server.url, server.accessToken, state, 0, 10, '-createdAt')
356 const jobs = res.body.data 358 .then(res => {
357 359 if (res.body.total > 0) pendingRequests = true
358 for (const job of jobs) { 360 })
359 if (job.state === 'pending' || job.state === 'processing') { 361 tasks.push(p)
360 pendingRequests = true 362 }
361 }
362 }
363 })
364
365 tasks.push(p)
366 } 363 }
367 364
368 await Promise.all(tasks) 365 await Promise.all(tasks)
diff --git a/server/tests/utils/server/jobs.ts b/server/tests/utils/server/jobs.ts
index 0a8c51575..4053dd40b 100644
--- a/server/tests/utils/server/jobs.ts
+++ b/server/tests/utils/server/jobs.ts
@@ -1,7 +1,8 @@
1import * as request from 'supertest' 1import * as request from 'supertest'
2import { JobState } from '../../../../shared/models'
2 3
3function getJobsList (url: string, accessToken: string) { 4function getJobsList (url: string, accessToken: string, state: JobState) {
4 const path = '/api/v1/jobs' 5 const path = '/api/v1/jobs/' + state
5 6
6 return request(url) 7 return request(url)
7 .get(path) 8 .get(path)
@@ -11,8 +12,8 @@ function getJobsList (url: string, accessToken: string) {
11 .expect('Content-Type', /json/) 12 .expect('Content-Type', /json/)
12} 13}
13 14
14function getJobsListPaginationAndSort (url: string, accessToken: string, start: number, count: number, sort: string) { 15function getJobsListPaginationAndSort (url: string, accessToken: string, state: JobState, start: number, count: number, sort: string) {
15 const path = '/api/v1/jobs' 16 const path = '/api/v1/jobs/' + state
16 17
17 return request(url) 18 return request(url)
18 .get(path) 19 .get(path)