Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Introduce debug command

Chocobozzz883a9019085f
diff --git a/server/controllers/api/server/debug.ts b/server/controllers/api/server/debug.ts
index a6e9147f3c..31888e963a 100644
--- a/server/controllers/api/server/debug.ts
+++ b/server/controllers/api/server/debug.ts
@@ -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) {
diff --git a/server/helpers/database-utils.ts b/server/helpers/database-utils.ts
index b5dc70c17d..cbd7aa401f 100644
--- a/server/helpers/database-utils.ts
+++ b/server/helpers/database-utils.ts
@@ -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 => {
diff --git a/server/tests/api/videos/resumable-upload.ts b/server/tests/api/videos/resumable-upload.ts
index 4fc3317dfc..6c01c7e78f 100644
--- a/server/tests/api/videos/resumable-upload.ts
+++ b/server/tests/api/videos/resumable-upload.ts
@@ -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)
})
diff --git a/shared/extra-utils/index.ts b/shared/extra-utils/index.ts
index 9e0f6374ad..7b5835e47b 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 0000000000..eecbb17111
--- /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<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
+ })
+ }
+}
diff --git a/shared/extra-utils/server/debug.ts b/shared/extra-utils/server/debug.ts
deleted file mode 100644
index f196812b71..0000000000
--- 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 4121c88280..f0071ba72d 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 763374e030..a3683913a5 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 b58639ba63..30e712ab8d 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 7ceff91372..2ecabdecab 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 {