fix(GOV-009): 完成脚手架审查整改
This commit is contained in:
@@ -1,10 +1,15 @@
|
||||
import { spawn } from 'node:child_process';
|
||||
import { type AddressInfo } from 'node:net';
|
||||
import path from 'node:path';
|
||||
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { bootstrapApi } from '../apps/api/src/main';
|
||||
import { API_RUNTIME_CONFIG } from '../apps/api/src/api.module';
|
||||
import { bootstrapScheduler } from '../apps/scheduler/src/main';
|
||||
import { SCHEDULER_RUNTIME_CONFIG } from '../apps/scheduler/src/scheduler.module';
|
||||
import { bootstrapWorker } from '../apps/worker/src/main';
|
||||
import { WORKER_RUNTIME_CONFIG } from '../apps/worker/src/worker.module';
|
||||
import type {
|
||||
ApiRuntimeConfig,
|
||||
SchedulerRuntimeConfig,
|
||||
@@ -64,6 +69,7 @@ describe('NestJS 三进程入口', () => {
|
||||
|
||||
expect(address.address).toBe('127.0.0.1');
|
||||
expect(address.port).toBeGreaterThan(0);
|
||||
expect(app.get(API_RUNTIME_CONFIG)).toBe(config);
|
||||
|
||||
await app.close();
|
||||
expect(app.getHttpServer().listening).toBe(false);
|
||||
@@ -82,6 +88,7 @@ describe('NestJS 三进程入口', () => {
|
||||
const app = await bootstrapScheduler({ config, logger: false });
|
||||
|
||||
expect('getHttpServer' in app).toBe(false);
|
||||
expect(app.get(SCHEDULER_RUNTIME_CONFIG)).toBe(config);
|
||||
await expect(app.close()).resolves.toBeUndefined();
|
||||
});
|
||||
|
||||
@@ -109,6 +116,76 @@ describe('NestJS 三进程入口', () => {
|
||||
const app = await bootstrapWorker({ config, logger: false });
|
||||
|
||||
expect('getHttpServer' in app).toBe(false);
|
||||
expect(app.get(WORKER_RUNTIME_CONFIG)).toBe(config);
|
||||
await expect(app.close()).resolves.toBeUndefined();
|
||||
});
|
||||
|
||||
it.each([
|
||||
['scheduler', 'apps/scheduler/src/main.ts'],
|
||||
['worker', 'apps/worker/src/main.ts'],
|
||||
])('%s 命令入口持续运行并在 SIGTERM 后正常退出', async (processName, entry) => {
|
||||
const output: string[] = [];
|
||||
const errors: string[] = [];
|
||||
const launcher = path.resolve(__dirname, '../node_modules/tsx/dist/cli.mjs');
|
||||
const child = spawn(process.execPath, [launcher, entry], {
|
||||
cwd: path.resolve(__dirname, '..'),
|
||||
env: {
|
||||
...process.env,
|
||||
APP_ENV: 'development',
|
||||
LOG_LEVEL: 'error',
|
||||
REDIS_HOST: '127.0.0.1',
|
||||
REDIS_PORT: '6379',
|
||||
REDIS_USERNAME: '',
|
||||
REDIS_PASSWORD: '',
|
||||
REDIS_DATABASE: processName === 'scheduler' ? '1' : '2',
|
||||
REDIS_TLS: 'false',
|
||||
MYSQL_ENABLED: 'false',
|
||||
MYSQL_HOST: '127.0.0.1',
|
||||
MYSQL_PORT: '3306',
|
||||
MYSQL_DATABASE: 'a_share_analysis_dev',
|
||||
MYSQL_USERNAME: '',
|
||||
MYSQL_PASSWORD: '',
|
||||
MYSQL_CHARSET: 'utf8mb4',
|
||||
MYSQL_COLLATION: 'utf8mb4_general_ci',
|
||||
MYSQL_TIMEZONE: '+08:00',
|
||||
AI_ENABLED: 'false',
|
||||
AI_BASE_URL: '',
|
||||
AI_API_KEY: '',
|
||||
AI_MODEL: '',
|
||||
AI_TIMEOUT_MS: '30000',
|
||||
ROCKETMQ_ENABLED: 'false',
|
||||
ROCKETMQ_NAMESRV_ADDR: '127.0.0.1:9876',
|
||||
ROCKETMQ_ENDPOINT: '127.0.0.1:8081',
|
||||
ROCKETMQ_TOPIC_PREFIX: 'a-share-analysis',
|
||||
ROCKETMQ_SEND_TIMEOUT_MS: '3000',
|
||||
ROCKETMQ_CONSUMER_GROUP: 'a-share-analysis-worker',
|
||||
ROCKETMQ_CONSUMER_CONCURRENCY: '4',
|
||||
SCHEDULER_ENABLED: 'true',
|
||||
SCHEDULER_TIMEZONE: 'Asia/Shanghai',
|
||||
MARKET_DATA_MODE: 'mock',
|
||||
MARKET_DATA_PROVIDER: 'deterministic-fixture',
|
||||
MARKET_DATA_BASE_URL: '',
|
||||
MARKET_DATA_API_KEY: '',
|
||||
},
|
||||
stdio: ['ignore', 'pipe', 'pipe'],
|
||||
});
|
||||
child.stdout.on('data', (chunk) => output.push(String(chunk)));
|
||||
child.stderr.on('data', (chunk) => errors.push(String(chunk)));
|
||||
|
||||
try {
|
||||
await new Promise((resolve) => setTimeout(resolve, 600));
|
||||
expect(
|
||||
child.exitCode,
|
||||
`${processName} 不应在启动后自行退出\nlauncher=${launcher}\nstdout=${output.join('')}\nstderr=${errors.join('')}`,
|
||||
).toBeNull();
|
||||
|
||||
child.kill('SIGTERM');
|
||||
const exitCode = await new Promise<number | null>((resolve) =>
|
||||
child.once('exit', (code) => resolve(code)),
|
||||
);
|
||||
expect(exitCode).toBe(0);
|
||||
} finally {
|
||||
if (child.exitCode === null) child.kill('SIGKILL');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user