diff options
author | Chocobozzz <me@florianbigard.com> | 2021-02-18 14:44:12 +0100 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2021-02-19 09:36:50 +0100 |
commit | fae6e4da8f516a9d6c3bad9bf6f35811ccacbad8 (patch) | |
tree | 38df5942cb2fa6e5860c8e0e19471eb6b124e291 /shared | |
parent | 3f8ae0e4e4da90c964597e4b3e0724da5eaa1668 (diff) | |
download | PeerTube-fae6e4da8f516a9d6c3bad9bf6f35811ccacbad8.tar.gz PeerTube-fae6e4da8f516a9d6c3bad9bf6f35811ccacbad8.tar.zst PeerTube-fae6e4da8f516a9d6c3bad9bf6f35811ccacbad8.zip |
Try to speed up server tests
Diffstat (limited to 'shared')
-rw-r--r-- | shared/extra-utils/index.ts | 37 | ||||
-rw-r--r-- | shared/extra-utils/server/debug.ts | 19 | ||||
-rw-r--r-- | shared/extra-utils/server/jobs.ts | 23 | ||||
-rw-r--r-- | shared/models/server/index.ts | 1 | ||||
-rw-r--r-- | shared/models/server/server-debug.model.ts | 4 |
5 files changed, 61 insertions, 23 deletions
diff --git a/shared/extra-utils/index.ts b/shared/extra-utils/index.ts index 8f5c709ff..5c95a1b3e 100644 --- a/shared/extra-utils/index.ts +++ b/shared/extra-utils/index.ts | |||
@@ -1,32 +1,33 @@ | |||
1 | export * from './server/activitypub' | ||
2 | export * from './bulk/bulk' | 1 | export * from './bulk/bulk' |
3 | export * from './cli/cli' | 2 | export * from './cli/cli' |
4 | export * from './server/clients' | 3 | export * from './feeds/feeds' |
5 | export * from './server/config' | 4 | export * from './instances-index/mock-instances-index' |
6 | export * from './server/jobs' | ||
7 | export * from './users/login' | ||
8 | export * from './miscs/miscs' | 5 | export * from './miscs/miscs' |
9 | export * from './miscs/stubs' | ||
10 | export * from './miscs/sql' | 6 | export * from './miscs/sql' |
11 | export * from './server/follows' | 7 | export * from './miscs/stubs' |
12 | export * from './requests/requests' | 8 | export * from './moderation/abuses' |
9 | export * from './plugins/mock-blocklist' | ||
13 | export * from './requests/check-api-params' | 10 | export * from './requests/check-api-params' |
14 | export * from './server/servers' | 11 | export * from './requests/requests' |
12 | export * from './search/videos' | ||
13 | export * from './server/activitypub' | ||
14 | export * from './server/clients' | ||
15 | export * from './server/config' | ||
16 | export * from './server/debug' | ||
17 | export * from './server/follows' | ||
18 | export * from './server/jobs' | ||
15 | export * from './server/plugins' | 19 | export * from './server/plugins' |
16 | export * from './videos/video-playlists' | 20 | export * from './server/servers' |
17 | export * from './users/users' | ||
18 | export * from './users/accounts' | 21 | export * from './users/accounts' |
19 | export * from './moderation/abuses' | 22 | export * from './users/login' |
20 | export * from './videos/services' | 23 | export * from './users/users' |
21 | export * from './videos/live' | 24 | export * from './videos/live' |
25 | export * from './videos/services' | ||
22 | export * from './videos/video-blacklist' | 26 | export * from './videos/video-blacklist' |
23 | export * from './videos/video-captions' | 27 | export * from './videos/video-captions' |
28 | export * from './videos/video-change-ownership' | ||
24 | export * from './videos/video-channels' | 29 | export * from './videos/video-channels' |
25 | export * from './videos/video-comments' | 30 | export * from './videos/video-comments' |
31 | export * from './videos/video-playlists' | ||
26 | export * from './videos/video-streaming-playlists' | 32 | export * from './videos/video-streaming-playlists' |
27 | export * from './videos/videos' | 33 | export * from './videos/videos' |
28 | export * from './videos/video-change-ownership' | ||
29 | export * from './feeds/feeds' | ||
30 | export * from './instances-index/mock-instances-index' | ||
31 | export * from './search/videos' | ||
32 | export * from './plugins/mock-blocklist' | ||
diff --git a/shared/extra-utils/server/debug.ts b/shared/extra-utils/server/debug.ts new file mode 100644 index 000000000..5cf80a5fb --- /dev/null +++ b/shared/extra-utils/server/debug.ts | |||
@@ -0,0 +1,19 @@ | |||
1 | import { makeGetRequest } from '../requests/requests' | ||
2 | import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' | ||
3 | |||
4 | function getDebug (url: string, token: string) { | ||
5 | const path = '/api/v1/server/debug' | ||
6 | |||
7 | return makeGetRequest({ | ||
8 | url, | ||
9 | path, | ||
10 | token, | ||
11 | statusCodeExpected: HttpStatusCode.OK_200 | ||
12 | }) | ||
13 | } | ||
14 | |||
15 | // --------------------------------------------------------------------------- | ||
16 | |||
17 | export { | ||
18 | getDebug | ||
19 | } | ||
diff --git a/shared/extra-utils/server/jobs.ts b/shared/extra-utils/server/jobs.ts index a53749589..97971f960 100644 --- a/shared/extra-utils/server/jobs.ts +++ b/shared/extra-utils/server/jobs.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import * as request from 'supertest' | 1 | import * as request from 'supertest' |
2 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | 2 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' |
3 | import { makeGetRequest } from '../../../shared/extra-utils' | 3 | import { getDebug, makeGetRequest } from '../../../shared/extra-utils' |
4 | import { Job, JobState, JobType } from '../../models' | 4 | import { Job, JobState, JobType, ServerDebug } from '../../models' |
5 | import { wait } from '../miscs/miscs' | 5 | import { wait } from '../miscs/miscs' |
6 | import { ServerInfo } from './servers' | 6 | import { ServerInfo } from './servers' |
7 | 7 | ||
@@ -53,7 +53,10 @@ function getJobsListPaginationAndSort (options: { | |||
53 | } | 53 | } |
54 | 54 | ||
55 | async function waitJobs (serversArg: ServerInfo[] | ServerInfo) { | 55 | async function waitJobs (serversArg: ServerInfo[] | ServerInfo) { |
56 | const pendingJobWait = process.env.NODE_PENDING_JOB_WAIT ? parseInt(process.env.NODE_PENDING_JOB_WAIT, 10) : 2000 | 56 | const pendingJobWait = process.env.NODE_PENDING_JOB_WAIT |
57 | ? parseInt(process.env.NODE_PENDING_JOB_WAIT, 10) | ||
58 | : 500 | ||
59 | |||
57 | let servers: ServerInfo[] | 60 | let servers: ServerInfo[] |
58 | 61 | ||
59 | if (Array.isArray(serversArg) === false) servers = [ serversArg as ServerInfo ] | 62 | if (Array.isArray(serversArg) === false) servers = [ serversArg as ServerInfo ] |
@@ -75,16 +78,26 @@ async function waitJobs (serversArg: ServerInfo[] | ServerInfo) { | |||
75 | start: 0, | 78 | start: 0, |
76 | count: 10, | 79 | count: 10, |
77 | sort: '-createdAt' | 80 | sort: '-createdAt' |
78 | }) | 81 | }).then(res => res.body.data) |
79 | .then(res => res.body.data) | ||
80 | .then((jobs: Job[]) => jobs.filter(j => j.type !== 'videos-views')) | 82 | .then((jobs: Job[]) => jobs.filter(j => j.type !== 'videos-views')) |
81 | .then(jobs => { | 83 | .then(jobs => { |
82 | if (jobs.length !== 0) { | 84 | if (jobs.length !== 0) { |
83 | pendingRequests = true | 85 | pendingRequests = true |
84 | } | 86 | } |
85 | }) | 87 | }) |
88 | |||
86 | tasks.push(p) | 89 | tasks.push(p) |
87 | } | 90 | } |
91 | |||
92 | const p = getDebug(server.url, server.accessToken) | ||
93 | .then(res => res.body) | ||
94 | .then((obj: ServerDebug) => { | ||
95 | if (obj.activityPubMessagesWaiting !== 0) { | ||
96 | pendingRequests = true | ||
97 | } | ||
98 | }) | ||
99 | |||
100 | tasks.push(p) | ||
88 | } | 101 | } |
89 | 102 | ||
90 | return tasks | 103 | return tasks |
diff --git a/shared/models/server/index.ts b/shared/models/server/index.ts index f253a3a79..b5163954a 100644 --- a/shared/models/server/index.ts +++ b/shared/models/server/index.ts | |||
@@ -7,5 +7,6 @@ export * from './emailer.model' | |||
7 | export * from './job.model' | 7 | export * from './job.model' |
8 | export * from './log-level.type' | 8 | export * from './log-level.type' |
9 | export * from './server-config.model' | 9 | export * from './server-config.model' |
10 | export * from './server-debug.model' | ||
10 | export * from './server-error-code.enum' | 11 | export * from './server-error-code.enum' |
11 | export * from './server-stats.model' | 12 | export * from './server-stats.model' |
diff --git a/shared/models/server/server-debug.model.ts b/shared/models/server/server-debug.model.ts new file mode 100644 index 000000000..4b731bb90 --- /dev/null +++ b/shared/models/server/server-debug.model.ts | |||
@@ -0,0 +1,4 @@ | |||
1 | export interface ServerDebug { | ||
2 | ip: string | ||
3 | activityPubMessagesWaiting: number | ||
4 | } | ||