1
0
Fork 0

Introduce debug command

This commit is contained in:
Chocobozzz 2021-07-06 16:02:11 +02:00
parent a9c58393d3
commit 883a901908
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
10 changed files with 51 additions and 50 deletions

View File

@ -1,8 +1,8 @@
import * as express from 'express'
import { InboxManager } from '@server/lib/activitypub/inbox-manager'
import { RemoveDanglingResumableUploadsScheduler } from '@server/lib/schedulers/remove-dangling-resumable-uploads-scheduler'
import { Debug, SendDebugCommand } from '@shared/models'
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
import { SendDebugCommand } from '@shared/models'
import * as express from 'express'
import { UserRight } from '../../../../shared/models/users'
import { authenticate, ensureUserHasRight } from '../../../middlewares'
@ -32,7 +32,7 @@ function getDebug (req: express.Request, res: express.Response) {
return res.json({
ip: req.ip,
activityPubMessagesWaiting: InboxManager.Instance.getActivityPubMessagesWaiting()
})
} as Debug)
}
async function runCommand (req: express.Request, res: express.Response) {

View File

@ -6,7 +6,7 @@ import { sequelizeTypescript } from '@server/initializers/database'
import { logger } from './logger'
function retryTransactionWrapper <T, A, B, C, D> (
functionToRetry: (arg1: A, arg2: B, arg3: C, arg4: D) => Promise<T> | Bluebird<T>,
functionToRetry: (arg1: A, arg2: B, arg3: C, arg4: D) => Promise<T>,
arg1: A,
arg2: B,
arg3: C,
@ -14,20 +14,20 @@ function retryTransactionWrapper <T, A, B, C, D> (
): Promise<T>
function retryTransactionWrapper <T, A, B, C> (
functionToRetry: (arg1: A, arg2: B, arg3: C) => Promise<T> | Bluebird<T>,
functionToRetry: (arg1: A, arg2: B, arg3: C) => Promise<T>,
arg1: A,
arg2: B,
arg3: C
): Promise<T>
function retryTransactionWrapper <T, A, B> (
functionToRetry: (arg1: A, arg2: B) => Promise<T> | Bluebird<T>,
functionToRetry: (arg1: A, arg2: B) => Promise<T>,
arg1: A,
arg2: B
): Promise<T>
function retryTransactionWrapper <T, A> (
functionToRetry: (arg1: A) => Promise<T> | Bluebird<T>,
functionToRetry: (arg1: A) => Promise<T>,
arg1: A
): Promise<T>
@ -36,7 +36,7 @@ function retryTransactionWrapper <T> (
): Promise<T>
function retryTransactionWrapper <T> (
functionToRetry: (...args: any[]) => Promise<T> | Bluebird<T>,
functionToRetry: (...args: any[]) => Promise<T>,
...args: any[]
): Promise<T> {
return transactionRetryer<T>(callback => {

View File

@ -12,7 +12,6 @@ import {
flushAndRunServer,
getMyUserInformation,
prepareResumableUpload,
sendDebugCommand,
sendResumableChunks,
ServerInfo,
setAccessTokensToServers,
@ -138,13 +137,13 @@ describe('Test resumable upload', function () {
})
it('Should not delete recent uploads', async function () {
await sendDebugCommand(server.url, server.accessToken, { command: 'remove-dandling-resumable-uploads' })
await server.debugCommand.sendCommand({ body: { command: 'remove-dandling-resumable-uploads' } })
expect(await countResumableUploads()).to.equal(2)
})
it('Should delete old uploads', async function () {
await sendDebugCommand(server.url, server.accessToken, { command: 'remove-dandling-resumable-uploads' })
await server.debugCommand.sendCommand({ body: { command: 'remove-dandling-resumable-uploads' } })
expect(await countResumableUploads()).to.equal(0)
})

View File

@ -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'

View File

@ -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<Debug>({
...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
})
}
}

View File

@ -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
}

View File

@ -1 +1,2 @@
export * from './contact-form-command'
export * from './debug-command'

View File

@ -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
}

View File

@ -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)
})

View File

@ -1,5 +1,6 @@
export interface Debug {
ip: string
activityPubMessagesWaiting: number
}
export interface SendDebugCommand {