diff options
Diffstat (limited to 'server/tests/utils/server/jobs.ts')
-rw-r--r-- | server/tests/utils/server/jobs.ts | 77 |
1 files changed, 0 insertions, 77 deletions
diff --git a/server/tests/utils/server/jobs.ts b/server/tests/utils/server/jobs.ts deleted file mode 100644 index 4c02cace5..000000000 --- a/server/tests/utils/server/jobs.ts +++ /dev/null | |||
@@ -1,77 +0,0 @@ | |||
1 | import * as request from 'supertest' | ||
2 | import { Job, JobState } from '../../../../shared/models' | ||
3 | import { ServerInfo, wait } from '../index' | ||
4 | |||
5 | function getJobsList (url: string, accessToken: string, state: JobState) { | ||
6 | const path = '/api/v1/jobs/' + state | ||
7 | |||
8 | return request(url) | ||
9 | .get(path) | ||
10 | .set('Accept', 'application/json') | ||
11 | .set('Authorization', 'Bearer ' + accessToken) | ||
12 | .expect(200) | ||
13 | .expect('Content-Type', /json/) | ||
14 | } | ||
15 | |||
16 | function getJobsListPaginationAndSort (url: string, accessToken: string, state: JobState, start: number, count: number, sort: string) { | ||
17 | const path = '/api/v1/jobs/' + state | ||
18 | |||
19 | return request(url) | ||
20 | .get(path) | ||
21 | .query({ start }) | ||
22 | .query({ count }) | ||
23 | .query({ sort }) | ||
24 | .set('Accept', 'application/json') | ||
25 | .set('Authorization', 'Bearer ' + accessToken) | ||
26 | .expect(200) | ||
27 | .expect('Content-Type', /json/) | ||
28 | } | ||
29 | |||
30 | async function waitJobs (serversArg: ServerInfo[] | ServerInfo) { | ||
31 | let servers: ServerInfo[] | ||
32 | |||
33 | if (Array.isArray(serversArg) === false) servers = [ serversArg as ServerInfo ] | ||
34 | else servers = serversArg as ServerInfo[] | ||
35 | |||
36 | const states: JobState[] = [ 'waiting', 'active', 'delayed' ] | ||
37 | const tasks: Promise<any>[] = [] | ||
38 | let pendingRequests: boolean | ||
39 | |||
40 | do { | ||
41 | pendingRequests = false | ||
42 | |||
43 | // Check if each server has pending request | ||
44 | for (const server of servers) { | ||
45 | for (const state of states) { | ||
46 | const p = getJobsListPaginationAndSort(server.url, server.accessToken, state, 0, 10, '-createdAt') | ||
47 | .then(res => res.body.data) | ||
48 | .then((jobs: Job[]) => jobs.filter(j => j.type !== 'videos-views')) | ||
49 | .then(jobs => { | ||
50 | if (jobs.length !== 0) pendingRequests = true | ||
51 | }) | ||
52 | tasks.push(p) | ||
53 | } | ||
54 | } | ||
55 | |||
56 | await Promise.all(tasks) | ||
57 | |||
58 | // Retry, in case of new jobs were created | ||
59 | if (pendingRequests === false) { | ||
60 | await wait(1000) | ||
61 | |||
62 | await Promise.all(tasks) | ||
63 | } | ||
64 | |||
65 | if (pendingRequests) { | ||
66 | await wait(1000) | ||
67 | } | ||
68 | } while (pendingRequests) | ||
69 | } | ||
70 | |||
71 | // --------------------------------------------------------------------------- | ||
72 | |||
73 | export { | ||
74 | getJobsList, | ||
75 | waitJobs, | ||
76 | getJobsListPaginationAndSort | ||
77 | } | ||