mirror of
https://github.com/IT4Change/gradido.git
synced 2026-02-06 09:56:05 +00:00
move logger testSetup into config-schema, capture logs in test, add debugging config
This commit is contained in:
parent
c315d841bd
commit
a9651d6940
18
.vscode/launch.json
vendored
18
.vscode/launch.json
vendored
@ -9,7 +9,23 @@
|
||||
"request": "launch",
|
||||
"name": "Launch Chrome",
|
||||
"url": "http://localhost:3000",
|
||||
"webRoot": "${workspaceFolder}/frontend",
|
||||
"webRoot": "${workspaceFolder}/frontend"
|
||||
},
|
||||
{
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"name": "DHT-Node Debug Tests",
|
||||
"runtimeExecutable": "yarn",
|
||||
"runtimeArgs": [
|
||||
"run",
|
||||
"test:debug"
|
||||
],
|
||||
"skipFiles": [
|
||||
"<node_internals>/**"
|
||||
],
|
||||
"console": "integratedTerminal",
|
||||
"internalConsoleOptions": "neverOpen",
|
||||
"cwd": "${workspaceFolder}/dht-node"
|
||||
}
|
||||
]
|
||||
}
|
||||
13
bun.lock
13
bun.lock
@ -214,6 +214,7 @@
|
||||
"@swc/cli": "^0.7.3",
|
||||
"@swc/core": "^1.11.24",
|
||||
"@swc/helpers": "^0.5.17",
|
||||
"@swc/jest": "^0.2.38",
|
||||
"@types/dotenv": "^8.2.3",
|
||||
"@types/jest": "27.5.1",
|
||||
"@types/joi": "^17.2.3",
|
||||
@ -635,6 +636,8 @@
|
||||
|
||||
"@jest/core": ["@jest/core@27.5.1", "", { "dependencies": { "@jest/console": "^27.5.1", "@jest/reporters": "^27.5.1", "@jest/test-result": "^27.5.1", "@jest/transform": "^27.5.1", "@jest/types": "^27.5.1", "@types/node": "*", "ansi-escapes": "^4.2.1", "chalk": "^4.0.0", "emittery": "^0.8.1", "exit": "^0.1.2", "graceful-fs": "^4.2.9", "jest-changed-files": "^27.5.1", "jest-config": "^27.5.1", "jest-haste-map": "^27.5.1", "jest-message-util": "^27.5.1", "jest-regex-util": "^27.5.1", "jest-resolve": "^27.5.1", "jest-resolve-dependencies": "^27.5.1", "jest-runner": "^27.5.1", "jest-runtime": "^27.5.1", "jest-snapshot": "^27.5.1", "jest-util": "^27.5.1", "jest-validate": "^27.5.1", "jest-watcher": "^27.5.1", "micromatch": "^4.0.4", "rimraf": "^3.0.0", "slash": "^3.0.0", "strip-ansi": "^6.0.0" }, "peerDependencies": { "node-notifier": "^8.0.1 || ^9.0.0 || ^10.0.0" }, "optionalPeers": ["node-notifier"] }, "sha512-AK6/UTrvQD0Cd24NSqmIA6rKsu0tKIxfiCducZvqxYdmMisOYAsdItspT+fQDQYARPf8XgjAFZi0ogW2agH5nQ=="],
|
||||
|
||||
"@jest/create-cache-key-function": ["@jest/create-cache-key-function@29.7.0", "", { "dependencies": { "@jest/types": "^29.6.3" } }, "sha512-4QqS3LY5PBmTRHj9sAg1HLoPzqAI0uOX6wI/TRqHIcOxlFidy6YEmCQJk6FSZjNLGCeubDMfmkWL+qaLKhSGQA=="],
|
||||
|
||||
"@jest/environment": ["@jest/environment@27.5.1", "", { "dependencies": { "@jest/fake-timers": "^27.5.1", "@jest/types": "^27.5.1", "@types/node": "*", "jest-mock": "^27.5.1" } }, "sha512-/WQjhPJe3/ghaol/4Bq480JKXV/Rfw8nQdN7f41fM8VDHLcxKXou6QyXAh3EFr9/bVG3x74z1NWDkP87EiY8gA=="],
|
||||
|
||||
"@jest/fake-timers": ["@jest/fake-timers@27.5.1", "", { "dependencies": { "@jest/types": "^27.5.1", "@sinonjs/fake-timers": "^8.0.1", "@types/node": "*", "jest-message-util": "^27.5.1", "jest-mock": "^27.5.1", "jest-util": "^27.5.1" } }, "sha512-/aPowoolwa07k7/oM3aASneNeBGCmGQsc3ugN4u6s4C/+s5M64MFo/+djTdiwcbQlRfFElGuDXWzaWj6QgKObQ=="],
|
||||
@ -879,6 +882,8 @@
|
||||
|
||||
"@swc/helpers": ["@swc/helpers@0.5.17", "", { "dependencies": { "tslib": "^2.8.0" } }, "sha512-5IKx/Y13RsYd+sauPb2x+U/xZikHjolzfuDgTAl/Tdf3Q8rslRvC19NKDLgAJQ6wsqADk10ntlv08nPFw/gO/A=="],
|
||||
|
||||
"@swc/jest": ["@swc/jest@0.2.38", "", { "dependencies": { "@jest/create-cache-key-function": "^29.7.0", "@swc/counter": "^0.1.3", "jsonc-parser": "^3.2.0" }, "peerDependencies": { "@swc/core": "*" } }, "sha512-HMoZgXWMqChJwffdDjvplH53g9G2ALQes3HKXDEdliB/b85OQ0CTSbxG8VSeCwiAn7cOaDVEt4mwmZvbHcS52w=="],
|
||||
|
||||
"@swc/types": ["@swc/types@0.1.21", "", { "dependencies": { "@swc/counter": "^0.1.3" } }, "sha512-2YEtj5HJVbKivud9N4bpPBAyZhj4S2Ipe5LkUG94alTpr7in/GU/EARgPAd3BwU+YOmFVJC2+kjqhGRi3r0ZpQ=="],
|
||||
|
||||
"@szmarczak/http-timer": ["@szmarczak/http-timer@5.0.1", "", { "dependencies": { "defer-to-connect": "^2.0.1" } }, "sha512-+PmQX0PiAYPMeVYe237LJAYvOMYW1j2rH5YROyS3b4CTVJum34HfRvKvAzozHAQG0TnHNdUfY9nCeUyRAs//cw=="],
|
||||
@ -2237,6 +2242,8 @@
|
||||
|
||||
"jsonc-eslint-parser": ["jsonc-eslint-parser@2.4.0", "", { "dependencies": { "acorn": "^8.5.0", "eslint-visitor-keys": "^3.0.0", "espree": "^9.0.0", "semver": "^7.3.5" } }, "sha512-WYDyuc/uFcGp6YtM2H0uKmUwieOuzeE/5YocFJLnLfclZ4inf3mRn8ZVy1s7Hxji7Jxm6Ss8gqpexD/GlKoGgg=="],
|
||||
|
||||
"jsonc-parser": ["jsonc-parser@3.3.1", "", {}, "sha512-HUgH65KyejrUFPvHFPbqOY0rsFip3Bo5wb4ngvdi1EpCYWUQDC5V+Y7mZws+DLkr4M//zQJoanu1SP+87Dv1oQ=="],
|
||||
|
||||
"jsonfile": ["jsonfile@6.1.0", "", { "dependencies": { "universalify": "^2.0.0" }, "optionalDependencies": { "graceful-fs": "^4.1.6" } }, "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ=="],
|
||||
|
||||
"jstransformer": ["jstransformer@1.0.0", "", { "dependencies": { "is-promise": "^2.0.0", "promise": "^7.0.1" } }, "sha512-C9YK3Rf8q6VAPDCCU9fnqo3mAfOH6vUGnMcP4AQAYIEpWtfGLpwOTmZ+igtdK5y+VvI2n3CyYSzy4Qh34eq24A=="],
|
||||
@ -3371,6 +3378,8 @@
|
||||
|
||||
"@jest/core/@types/node": ["@types/node@18.19.96", "", { "dependencies": { "undici-types": "~5.26.4" } }, "sha512-PzBvgsZ7YdFs/Kng1BSW8IGv68/SPcOxYYhT7luxD7QyzIhFS1xPTpfK3K9eHBa7hVwlW+z8nN0mOd515yaduQ=="],
|
||||
|
||||
"@jest/create-cache-key-function/@jest/types": ["@jest/types@29.6.3", "", { "dependencies": { "@jest/schemas": "^29.6.3", "@types/istanbul-lib-coverage": "^2.0.0", "@types/istanbul-reports": "^3.0.0", "@types/node": "*", "@types/yargs": "^17.0.8", "chalk": "^4.0.0" } }, "sha512-u3UPsIilWKOM3F9CXtrG8LEJmNxwoCQC/XVj4IKYXvvpx7QIi/Kg1LI5uDmDpKlac62NUtX7eLjRh+jVZcLOzw=="],
|
||||
|
||||
"@jest/environment/@types/node": ["@types/node@18.19.96", "", { "dependencies": { "undici-types": "~5.26.4" } }, "sha512-PzBvgsZ7YdFs/Kng1BSW8IGv68/SPcOxYYhT7luxD7QyzIhFS1xPTpfK3K9eHBa7hVwlW+z8nN0mOd515yaduQ=="],
|
||||
|
||||
"@jest/fake-timers/@types/node": ["@types/node@18.19.96", "", { "dependencies": { "undici-types": "~5.26.4" } }, "sha512-PzBvgsZ7YdFs/Kng1BSW8IGv68/SPcOxYYhT7luxD7QyzIhFS1xPTpfK3K9eHBa7hVwlW+z8nN0mOd515yaduQ=="],
|
||||
@ -3921,6 +3930,10 @@
|
||||
|
||||
"@istanbuljs/load-nyc-config/js-yaml/argparse": ["argparse@1.0.10", "", { "dependencies": { "sprintf-js": "~1.0.2" } }, "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg=="],
|
||||
|
||||
"@jest/create-cache-key-function/@jest/types/@types/node": ["@types/node@18.19.96", "", { "dependencies": { "undici-types": "~5.26.4" } }, "sha512-PzBvgsZ7YdFs/Kng1BSW8IGv68/SPcOxYYhT7luxD7QyzIhFS1xPTpfK3K9eHBa7hVwlW+z8nN0mOd515yaduQ=="],
|
||||
|
||||
"@jest/create-cache-key-function/@jest/types/@types/yargs": ["@types/yargs@17.0.33", "", { "dependencies": { "@types/yargs-parser": "*" } }, "sha512-WpxBCKWPLr4xSsHgz511rFJAM+wS28w2zEO1QDNY5zM/S8ok70NNfztH0xwhqKyaK0OHCbN98LDAZuy1ctxDkA=="],
|
||||
|
||||
"@jest/reporters/jest-worker/supports-color": ["supports-color@8.1.1", "", { "dependencies": { "has-flag": "^4.0.0" } }, "sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q=="],
|
||||
|
||||
"@jest/transform/write-file-atomic/signal-exit": ["signal-exit@3.0.7", "", {}, "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ=="],
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
"vcs": { "enabled": false, "clientKind": "git", "useIgnoreFile": false },
|
||||
"files": {
|
||||
"ignoreUnknown": false,
|
||||
"ignore": ["build", "node_modules"],
|
||||
"ignore": ["build", "node_modules", "testSetup.ts"],
|
||||
"include": ["./src/**/*.js", "./src/**/*.ts"]
|
||||
},
|
||||
"formatter": {
|
||||
|
||||
59
config-schema/test/testSetup.ts
Normal file
59
config-schema/test/testSetup.ts
Normal file
@ -0,0 +1,59 @@
|
||||
jest.setTimeout(1000000)
|
||||
|
||||
const loggers: { [key: string]: any } = {}
|
||||
const logs: { level: string; message: string; logger: string; additional: string }[] = []
|
||||
|
||||
function addLog(level: string, message: string, logger: string, additional: any[]) {
|
||||
logs.push({ level, message, logger, additional: JSON.stringify(additional, null, 2) })
|
||||
}
|
||||
|
||||
export function printLogs() {
|
||||
for (const log of logs) {
|
||||
process.stdout.write(`${log.logger} [${log.level}] ${log.message} ${log.additional}\n`)
|
||||
}
|
||||
}
|
||||
|
||||
export function cleanLogs(): void {
|
||||
logs.length = 0
|
||||
}
|
||||
|
||||
jest.mock('log4js', () => {
|
||||
const originalModule = jest.requireActual('log4js')
|
||||
return {
|
||||
__esModule: true,
|
||||
...originalModule,
|
||||
getLogger: jest.fn().mockImplementation((param: any) => {
|
||||
// console.log('getLogger called with: ', param)
|
||||
const fakeLogger = {
|
||||
addContext: jest.fn(),
|
||||
trace: jest.fn((message: string, ...args: any[]) => {
|
||||
addLog('trace', message, param, args)
|
||||
}),
|
||||
debug: jest.fn((message: string, ...args: any[]) => {
|
||||
addLog('debug', message, param, args)
|
||||
}),
|
||||
warn: jest.fn((message: string, ...args: any[]) => {
|
||||
addLog('warn', message, param, args)
|
||||
}),
|
||||
info: jest.fn((message: string, ...args: any[]) => {
|
||||
addLog('info', message, param, args)
|
||||
}),
|
||||
error: jest.fn((message: string, ...args: any[]) => {
|
||||
addLog('error', message, param, args)
|
||||
}),
|
||||
fatal: jest.fn((message: string, ...args: any[]) => {
|
||||
addLog('fatal', message, param, args)
|
||||
}),
|
||||
}
|
||||
loggers[param] = fakeLogger
|
||||
return fakeLogger
|
||||
}),
|
||||
}
|
||||
})
|
||||
|
||||
export function getLogger(name: string) {
|
||||
if (!loggers[name]) {
|
||||
throw new Error(`No logger with name ${name} was requested from code`)
|
||||
}
|
||||
return loggers[name]
|
||||
}
|
||||
@ -10,5 +10,5 @@ build({
|
||||
// legalComments: 'inline',
|
||||
external: ['dht-rpc', 'sodium-universal'],
|
||||
minify: true,
|
||||
sourcemap: false,
|
||||
sourcemap: true,
|
||||
})
|
||||
|
||||
@ -1,19 +1,22 @@
|
||||
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
|
||||
module.exports = {
|
||||
verbose: true,
|
||||
verbose: false,
|
||||
preset: 'ts-jest',
|
||||
collectCoverage: true,
|
||||
collectCoverage: false,
|
||||
collectCoverageFrom: ['src/**/*.ts', '!**/node_modules/**', '!src/seeds/**', '!build/**'],
|
||||
coverageThreshold: {
|
||||
global: {
|
||||
lines: 82,
|
||||
},
|
||||
},
|
||||
setupFiles: ['<rootDir>/test/testSetup.ts'],
|
||||
setupFiles: ['config-schema/test/testSetup.ts'],
|
||||
setupFilesAfterEnv: [],
|
||||
modulePathIgnorePatterns: ['<rootDir>/build/'],
|
||||
moduleNameMapper: {
|
||||
'@/(.*)': '<rootDir>/src/$1',
|
||||
'@test/(.*)': '<rootDir>/test/$1',
|
||||
},
|
||||
transform: {
|
||||
'^.+\\.(t|j)sx?$': '@swc/jest',
|
||||
},
|
||||
}
|
||||
|
||||
@ -1,71 +0,0 @@
|
||||
{
|
||||
"appenders":
|
||||
{
|
||||
"dht":
|
||||
{
|
||||
"type": "dateFile",
|
||||
"filename": "../logs/dht-node/apiversion-%v.log",
|
||||
"pattern": "yyyy-MM-dd",
|
||||
"layout":
|
||||
{
|
||||
"type": "pattern", "pattern": "%d{ISO8601} %p %c [%X{user}] [%f : %l] - %m"
|
||||
},
|
||||
"compress": true,
|
||||
"keepFileExt" : true,
|
||||
"fileNameSep" : "_",
|
||||
"numBackups" : 30
|
||||
},
|
||||
"errorFile":
|
||||
{
|
||||
"type": "dateFile",
|
||||
"filename": "../logs/dht-node/errors.log",
|
||||
"pattern": "yyyy-MM-dd",
|
||||
"layout":
|
||||
{
|
||||
"type": "pattern", "pattern": "%d{ISO8601} %p %c [%X{user}] [%f : %l] - %m"
|
||||
},
|
||||
"compress": true,
|
||||
"keepFileExt" : true,
|
||||
"fileNameSep" : "_",
|
||||
"numBackups" : 30
|
||||
},
|
||||
"errors":
|
||||
{
|
||||
"type": "logLevelFilter",
|
||||
"level": "error",
|
||||
"appender": "errorFile"
|
||||
},
|
||||
"out":
|
||||
{
|
||||
"type": "stdout",
|
||||
"layout":
|
||||
{
|
||||
"type": "pattern", "pattern": "%d{ISO8601} %p %c [%X{user}] [%f : %l] - %m"
|
||||
}
|
||||
}
|
||||
},
|
||||
"categories":
|
||||
{
|
||||
"default":
|
||||
{
|
||||
"appenders":
|
||||
[
|
||||
"out",
|
||||
"errors"
|
||||
],
|
||||
"level": "debug",
|
||||
"enableCallStack": true
|
||||
},
|
||||
"dht":
|
||||
{
|
||||
"appenders":
|
||||
[
|
||||
"dht",
|
||||
"out",
|
||||
"errors"
|
||||
],
|
||||
"level": "debug",
|
||||
"enableCallStack": true
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -10,11 +10,14 @@
|
||||
"scripts": {
|
||||
"build": "tsx esbuild.config.ts",
|
||||
"start": "cross-env TZ=UTC NODE_ENV=production node build/index.js",
|
||||
"dev": "cross-env TZ=UTC tsx watch src/index.ts",
|
||||
"dev": "cross-env TZ=UTC nodemon -w src --ext ts,json -r tsconfig-paths/register src/index.ts",
|
||||
"devFast": "cross-env TZ=UTC tsx src/index.ts",
|
||||
"typecheck": "tsc --noEmit",
|
||||
"lint": "biome check --error-on-warnings .",
|
||||
"lint:fix": "biome check --error-on-warnings . --write",
|
||||
"test": "cross-env TZ=UTC NODE_ENV=development DB_DATABASE=gradido_test_dht jest --runInBand --forceExit --detectOpenHandles"
|
||||
"test": "cross-env TZ=UTC NODE_ENV=development DB_DATABASE=gradido_test_dht jest --verbose --runInBand --forceExit --detectOpenHandles",
|
||||
"test:debug": "cross-env TZ=UTC NODE_ENV=development DB_DATABASE=gradido_test_dht node --inspect-brk node_modules/.bin/jest --bail --runInBand --forceExit --detectOpenHandles",
|
||||
"test:coverage": "cross-env TZ=UTC NODE_ENV=development DB_DATABASE=gradido_test_dht jest --coverage --runInBand --forceExit --detectOpenHandles"
|
||||
},
|
||||
"dependencies": {
|
||||
"cross-env": "^7.0.3",
|
||||
@ -24,6 +27,10 @@
|
||||
"devDependencies": {
|
||||
"@biomejs/biome": "1.9.4",
|
||||
"@hyperswarm/dht": "6.5.1",
|
||||
"@swc/cli": "^0.7.3",
|
||||
"@swc/core": "^1.11.24",
|
||||
"@swc/helpers": "^0.5.17",
|
||||
"@swc/jest": "^0.2.38",
|
||||
"@types/dotenv": "^8.2.3",
|
||||
"@types/jest": "27.5.1",
|
||||
"@types/joi": "^17.2.3",
|
||||
@ -36,7 +43,9 @@
|
||||
"jest": "27.5.1",
|
||||
"joi": "^17.13.3",
|
||||
"log4js": "^6.9.1",
|
||||
"nodemon": "^2.0.7",
|
||||
"prettier": "^2.8.8",
|
||||
"source-map-support": "^0.5.21",
|
||||
"ts-jest": "27.1.4",
|
||||
"tsx": "^4.19.4",
|
||||
"typeorm": "^0.3.22",
|
||||
|
||||
1
dht-node/src/config/const.ts
Normal file
1
dht-node/src/config/const.ts
Normal file
@ -0,0 +1 @@
|
||||
export const LOG4JS_BASE_CATEGORY_NAME = 'dht'
|
||||
@ -1,14 +1,17 @@
|
||||
import { validate } from 'config-schema'
|
||||
import dotenv from 'dotenv'
|
||||
|
||||
import { LogLevel } from 'config-schema/src/log4js-config'
|
||||
import { schema } from './schema'
|
||||
|
||||
dotenv.config()
|
||||
|
||||
const constants = {
|
||||
LOG4JS_CONFIG: 'log4js-config.json',
|
||||
const logging = {
|
||||
LOG4JS_CONFIG: process.env.LOG4JS_CONFIG ?? 'log4js-config.json',
|
||||
// default log level on production should be info
|
||||
LOG_LEVEL: process.env.LOG_LEVEL ?? 'info',
|
||||
// log level for default log4js-config.json, don't change existing log4js-config.json
|
||||
LOG_LEVEL: (process.env.LOG_LEVEL ?? 'info') as LogLevel,
|
||||
LOG_FILES_BASE_PATH: process.env.LOG_FILES_BASE_PATH ?? '../logs/dht-node',
|
||||
}
|
||||
|
||||
const server = {
|
||||
@ -33,7 +36,7 @@ const federation = {
|
||||
}
|
||||
|
||||
export const CONFIG = {
|
||||
...constants,
|
||||
...logging,
|
||||
...server,
|
||||
...community,
|
||||
...federation,
|
||||
|
||||
@ -2,6 +2,7 @@ import {
|
||||
COMMUNITY_DESCRIPTION,
|
||||
COMMUNITY_NAME,
|
||||
LOG4JS_CONFIG,
|
||||
LOG_FILES_BASE_PATH,
|
||||
LOG_LEVEL,
|
||||
NODE_ENV,
|
||||
PRODUCTION,
|
||||
@ -12,6 +13,7 @@ export const schema = Joi.object({
|
||||
COMMUNITY_NAME,
|
||||
COMMUNITY_DESCRIPTION,
|
||||
LOG4JS_CONFIG,
|
||||
LOG_FILES_BASE_PATH,
|
||||
LOG_LEVEL,
|
||||
NODE_ENV,
|
||||
PRODUCTION,
|
||||
|
||||
@ -3,11 +3,11 @@ import { Community as DbCommunity, FederatedCommunity as DbFederatedCommunity }
|
||||
import { validate as validateUUID, version as versionUUID } from 'uuid'
|
||||
|
||||
import { cleanDB, testEnvironment } from '@test/helpers'
|
||||
import { logger } from '@test/testSetup'
|
||||
import { cleanLogs, getLogger, printLogs } from 'config-schema/test/testSetup'
|
||||
|
||||
import { CONFIG } from '@/config'
|
||||
|
||||
import { startDHT } from './index'
|
||||
import { LOG_CATEGORY_DHT_NODE, startDHT } from './index'
|
||||
|
||||
CONFIG.FEDERATION_DHT_SEED = '64ebcb0e3ad547848fef4197c6e2332f'
|
||||
CONFIG.FEDERATION_COMMUNITY_APIS = '1_0,1_1,2_0'
|
||||
@ -21,6 +21,8 @@ const keyPairMock = {
|
||||
secretKey: Buffer.from('secretKey'),
|
||||
}
|
||||
|
||||
const logger = getLogger(LOG_CATEGORY_DHT_NODE)
|
||||
|
||||
const serverListenSpy = jest.fn()
|
||||
|
||||
const serverEventMocks: { [key: string]: any } = {}
|
||||
@ -112,6 +114,13 @@ describe('federation', () => {
|
||||
jest.useFakeTimers()
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
// print logs which where captured during test
|
||||
// printLogs()
|
||||
// clean logs after, else they will be printed in next test again
|
||||
// cleanLogs()
|
||||
})
|
||||
|
||||
describe('call startDHT', () => {
|
||||
const hashSpy = jest.spyOn(DHT, 'hash')
|
||||
const keyPairSpy = jest.spyOn(DHT, 'keyPair')
|
||||
|
||||
@ -7,8 +7,9 @@ import {
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
|
||||
import { CONFIG } from '@/config'
|
||||
import { logger } from '@/server/logger'
|
||||
import { LOG4JS_BASE_CATEGORY_NAME } from '@/config/const'
|
||||
|
||||
import { getLogger } from 'log4js'
|
||||
import { ApiVersionType } from './ApiVersionType'
|
||||
|
||||
const KEY_SECRET_SEEDBYTES = 32
|
||||
@ -17,6 +18,8 @@ const POLLTIME = 20000
|
||||
const SUCCESSTIME = 120000
|
||||
const ERRORTIME = 240000
|
||||
const ANNOUNCETIME = 30000
|
||||
export const LOG_CATEGORY_DHT_NODE = `${LOG4JS_BASE_CATEGORY_NAME}.dht_node`
|
||||
const logger = getLogger(LOG_CATEGORY_DHT_NODE)
|
||||
|
||||
type CommunityApi = {
|
||||
api: string
|
||||
@ -56,6 +59,7 @@ export const startDHT = async (topic: string): Promise<void> => {
|
||||
const server = node.createServer()
|
||||
|
||||
server.on('connection', function (socket: any) {
|
||||
logger.addContext('pubkey', socket.remotePublicKey.toString('hex'))
|
||||
logger.info(`server on... with Remote public key: ${socket.remotePublicKey.toString('hex')}`)
|
||||
|
||||
socket.on('data', async (data: Buffer) => {
|
||||
@ -82,7 +86,6 @@ export const startDHT = async (topic: string): Promise<void> => {
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
for (const recApiVersion of recApiVersions) {
|
||||
if (
|
||||
!recApiVersion.api ||
|
||||
|
||||
@ -1,10 +1,20 @@
|
||||
import 'source-map-support/register'
|
||||
import { startDHT } from '@/dht_node/index'
|
||||
|
||||
import { CONFIG } from '@/config'
|
||||
import { logger } from '@/server/logger'
|
||||
import { LOG4JS_BASE_CATEGORY_NAME } from '@/config/const'
|
||||
import { defaultCategory, initLogger } from 'config-schema'
|
||||
import { AppDatabase } from 'database'
|
||||
import { getLogger } from 'log4js'
|
||||
|
||||
async function main() {
|
||||
// init logger
|
||||
initLogger(
|
||||
[defaultCategory(LOG4JS_BASE_CATEGORY_NAME, CONFIG.LOG_LEVEL)],
|
||||
CONFIG.LOG_FILES_BASE_PATH,
|
||||
CONFIG.LOG4JS_CONFIG,
|
||||
)
|
||||
const logger = getLogger(`${LOG4JS_BASE_CATEGORY_NAME}`)
|
||||
// open mysql connection
|
||||
await AppDatabase.getInstance().init()
|
||||
logger.debug(`dhtseed set by CONFIG.FEDERATION_DHT_SEED=${CONFIG.FEDERATION_DHT_SEED}`)
|
||||
|
||||
@ -1,21 +0,0 @@
|
||||
import { readFileSync } from 'fs'
|
||||
|
||||
import { configure, getLogger } from 'log4js'
|
||||
|
||||
import { CONFIG } from '@/config'
|
||||
|
||||
const options = JSON.parse(readFileSync(CONFIG.LOG4JS_CONFIG, 'utf-8'))
|
||||
|
||||
options.categories.dht.level = CONFIG.LOG_LEVEL
|
||||
let filename: string = options.appenders.dht.filename
|
||||
options.appenders.dht.filename = filename.replace(
|
||||
'apiversion-%v',
|
||||
'dht-' + CONFIG.FEDERATION_DHT_TOPIC,
|
||||
)
|
||||
filename = options.appenders.errorFile.filename
|
||||
|
||||
configure(options)
|
||||
|
||||
const logger = getLogger('dht')
|
||||
|
||||
export { logger }
|
||||
@ -1,5 +1,4 @@
|
||||
import { AppDatabase, entities } from 'database'
|
||||
import { CONFIG } from '@/config'
|
||||
|
||||
export const headerPushMock = jest.fn((t) => {
|
||||
context.token = t.value
|
||||
|
||||
@ -1,22 +0,0 @@
|
||||
import { logger } from '@/server/logger'
|
||||
|
||||
jest.setTimeout(1000000)
|
||||
|
||||
jest.mock('@/server/logger', () => {
|
||||
const originalModule = jest.requireActual('@/server/logger')
|
||||
return {
|
||||
__esModule: true,
|
||||
...originalModule,
|
||||
logger: {
|
||||
addContext: jest.fn(),
|
||||
trace: jest.fn(),
|
||||
debug: jest.fn(),
|
||||
warn: jest.fn(),
|
||||
info: jest.fn(),
|
||||
error: jest.fn(),
|
||||
fatal: jest.fn(),
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
export { logger }
|
||||
@ -12,7 +12,7 @@
|
||||
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */
|
||||
// "declaration": true, /* Generates corresponding '.d.ts' file. */
|
||||
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
||||
// "sourceMap": true, /* Generates corresponding '.map' file. */
|
||||
"sourceMap": true, /* Generates corresponding '.map' file. */
|
||||
// "outFile": "./", /* Concatenate and emit output to single file. */
|
||||
"outDir": "./build", /* Redirect output structure to the directory. */
|
||||
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
||||
@ -74,5 +74,8 @@
|
||||
/* Advanced Options */
|
||||
"skipLibCheck": true, /* Skip type checking of declaration files. */
|
||||
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
|
||||
},
|
||||
"ts-node": {
|
||||
"swc": true
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,10 +2,10 @@
|
||||
"extends": ["//"],
|
||||
"tasks": {
|
||||
"test": {
|
||||
"dependsOn": ["database#build", "config-schema#build", "database#up:dht_test"]
|
||||
"dependsOn": ["config-schema#build", "database#build", "database#up:dht_test"]
|
||||
},
|
||||
"dev": {
|
||||
"dependsOn": ["database#up"]
|
||||
"dependsOn": ["config-schema#build", "database#build", "database#up"]
|
||||
},
|
||||
"start": {
|
||||
"dependsOn": ["database#up", "build"]
|
||||
|
||||
21
yarn.lock
21
yarn.lock
@ -1185,6 +1185,13 @@
|
||||
slash "^3.0.0"
|
||||
strip-ansi "^6.0.0"
|
||||
|
||||
"@jest/create-cache-key-function@^29.7.0":
|
||||
version "29.7.0"
|
||||
resolved "https://registry.yarnpkg.com/@jest/create-cache-key-function/-/create-cache-key-function-29.7.0.tgz#793be38148fab78e65f40ae30c36785f4ad859f0"
|
||||
integrity sha512-4QqS3LY5PBmTRHj9sAg1HLoPzqAI0uOX6wI/TRqHIcOxlFidy6YEmCQJk6FSZjNLGCeubDMfmkWL+qaLKhSGQA==
|
||||
dependencies:
|
||||
"@jest/types" "^29.6.3"
|
||||
|
||||
"@jest/environment@^27.5.1":
|
||||
version "27.5.1"
|
||||
resolved "https://registry.yarnpkg.com/@jest/environment/-/environment-27.5.1.tgz#d7425820511fe7158abbecc010140c3fd3be9c74"
|
||||
@ -2069,6 +2076,15 @@
|
||||
dependencies:
|
||||
tslib "^2.8.0"
|
||||
|
||||
"@swc/jest@^0.2.38":
|
||||
version "0.2.38"
|
||||
resolved "https://registry.yarnpkg.com/@swc/jest/-/jest-0.2.38.tgz#8b137e344c6c021d4e49ee2bc62b0e5e564d2c7c"
|
||||
integrity sha512-HMoZgXWMqChJwffdDjvplH53g9G2ALQes3HKXDEdliB/b85OQ0CTSbxG8VSeCwiAn7cOaDVEt4mwmZvbHcS52w==
|
||||
dependencies:
|
||||
"@jest/create-cache-key-function" "^29.7.0"
|
||||
"@swc/counter" "^0.1.3"
|
||||
jsonc-parser "^3.2.0"
|
||||
|
||||
"@swc/types@^0.1.21":
|
||||
version "0.1.21"
|
||||
resolved "https://registry.yarnpkg.com/@swc/types/-/types-0.1.21.tgz#6fcadbeca1d8bc89e1ab3de4948cef12344a38c0"
|
||||
@ -8110,6 +8126,11 @@ jsonc-eslint-parser@^2.0.0, jsonc-eslint-parser@^2.3.0:
|
||||
espree "^9.0.0"
|
||||
semver "^7.3.5"
|
||||
|
||||
jsonc-parser@^3.2.0:
|
||||
version "3.3.1"
|
||||
resolved "https://registry.yarnpkg.com/jsonc-parser/-/jsonc-parser-3.3.1.tgz#f2a524b4f7fd11e3d791e559977ad60b98b798b4"
|
||||
integrity sha512-HUgH65KyejrUFPvHFPbqOY0rsFip3Bo5wb4ngvdi1EpCYWUQDC5V+Y7mZws+DLkr4M//zQJoanu1SP+87Dv1oQ==
|
||||
|
||||
jsonfile@^4.0.0:
|
||||
version "4.0.0"
|
||||
resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-4.0.0.tgz#8771aae0799b64076b76640fca058f9c10e33ecb"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user