From 883a9019085ff9013079d6b1539b86f2f519175a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 6 Jul 2021 16:02:11 +0200 Subject: Introduce debug command --- shared/extra-utils/index.ts | 1 - shared/extra-utils/server/debug-command.ts | 32 +++++++++++++++++++++++++++++ shared/extra-utils/server/debug.ts | 33 ------------------------------ shared/extra-utils/server/index.ts | 1 + shared/extra-utils/server/jobs.ts | 9 ++++---- shared/extra-utils/server/servers.ts | 3 +++ shared/models/server/debug.model.ts | 1 + 7 files changed, 41 insertions(+), 39 deletions(-) create mode 100644 shared/extra-utils/server/debug-command.ts delete mode 100644 shared/extra-utils/server/debug.ts (limited to 'shared') diff --git a/shared/extra-utils/index.ts b/shared/extra-utils/index.ts index 9e0f6374a..7b5835e47 100644 --- a/shared/extra-utils/index.ts +++ b/shared/extra-utils/index.ts @@ -15,7 +15,6 @@ export * from './search' export * from './server/clients' export * from './server/config' -export * from './server/debug' export * from './server/follows' export * from './server/jobs' export * from './server/plugins' diff --git a/shared/extra-utils/server/debug-command.ts b/shared/extra-utils/server/debug-command.ts new file mode 100644 index 000000000..eecbb1711 --- /dev/null +++ b/shared/extra-utils/server/debug-command.ts @@ -0,0 +1,32 @@ +import { Debug, SendDebugCommand } from '@shared/models' +import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' +import { AbstractCommand, OverrideCommandOptions } from '../shared' + +export class DebugCommand extends AbstractCommand { + + getDebug (options: OverrideCommandOptions = {}) { + const path = '/api/v1/server/debug' + + return this.getRequestBody({ + ...options, + + path, + defaultExpectedStatus: HttpStatusCode.OK_200 + }) + } + + sendCommand (options: OverrideCommandOptions & { + body: SendDebugCommand + }) { + const { body } = options + const path = '/api/v1/server/debug/run-command' + + return this.postBodyRequest({ + ...options, + + path, + fields: body, + defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 + }) + } +} diff --git a/shared/extra-utils/server/debug.ts b/shared/extra-utils/server/debug.ts deleted file mode 100644 index f196812b7..000000000 --- a/shared/extra-utils/server/debug.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { makeGetRequest, makePostBodyRequest } from '../requests/requests' -import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' -import { SendDebugCommand } from '@shared/models' - -function getDebug (url: string, token: string) { - const path = '/api/v1/server/debug' - - return makeGetRequest({ - url, - path, - token, - statusCodeExpected: HttpStatusCode.OK_200 - }) -} - -function sendDebugCommand (url: string, token: string, body: SendDebugCommand) { - const path = '/api/v1/server/debug/run-command' - - return makePostBodyRequest({ - url, - path, - token, - fields: body, - statusCodeExpected: HttpStatusCode.NO_CONTENT_204 - }) -} - -// --------------------------------------------------------------------------- - -export { - getDebug, - sendDebugCommand -} diff --git a/shared/extra-utils/server/index.ts b/shared/extra-utils/server/index.ts index 4121c8828..f0071ba72 100644 --- a/shared/extra-utils/server/index.ts +++ b/shared/extra-utils/server/index.ts @@ -1 +1,2 @@ export * from './contact-form-command' +export * from './debug-command' diff --git a/shared/extra-utils/server/jobs.ts b/shared/extra-utils/server/jobs.ts index 763374e03..a3683913a 100644 --- a/shared/extra-utils/server/jobs.ts +++ b/shared/extra-utils/server/jobs.ts @@ -1,7 +1,7 @@ import * as request from 'supertest' import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' -import { getDebug, makeGetRequest } from '../../../shared/extra-utils' -import { Job, JobState, JobType, ServerDebug } from '../../models' +import { makeGetRequest } from '../../../shared/extra-utils' +import { Job, JobState, JobType } from '../../models' import { wait } from '../miscs/miscs' import { ServerInfo } from './servers' @@ -90,9 +90,8 @@ async function waitJobs (serversArg: ServerInfo[] | ServerInfo) { tasks.push(p) } - const p = getDebug(server.url, server.accessToken) - .then(res => res.body) - .then((obj: ServerDebug) => { + const p = server.debugCommand.getDebug() + .then(obj => { if (obj.activityPubMessagesWaiting !== 0) { pendingRequests = true } diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index b58639ba6..30e712ab8 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts @@ -17,6 +17,7 @@ import { OverviewsCommand } from '../overviews' import { makeGetRequest } from '../requests/requests' import { SearchCommand } from '../search' import { ContactFormCommand } from './contact-form-command' +import { DebugCommand } from './debug-command' interface ServerInfo { app: ChildProcess @@ -79,6 +80,7 @@ interface ServerInfo { overviewsCommand?: OverviewsCommand searchCommand?: SearchCommand contactFormCommand?: ContactFormCommand + debugCommand?: DebugCommand } function parallelTests () { @@ -293,6 +295,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = [] server.overviewsCommand = new OverviewsCommand(server) server.searchCommand = new SearchCommand(server) server.contactFormCommand = new ContactFormCommand(server) + server.debugCommand = new DebugCommand(server) res(server) }) diff --git a/shared/models/server/debug.model.ts b/shared/models/server/debug.model.ts index 7ceff9137..2ecabdeca 100644 --- a/shared/models/server/debug.model.ts +++ b/shared/models/server/debug.model.ts @@ -1,5 +1,6 @@ export interface Debug { ip: string + activityPubMessagesWaiting: number } export interface SendDebugCommand { -- cgit v1.2.3