more stuff
This commit is contained in:
parent
c3cb36c8d6
commit
7dec0be3b4
26 changed files with 1394 additions and 275 deletions
40
test/fixtures/backtest-crash-owner.ts
vendored
Normal file
40
test/fixtures/backtest-crash-owner.ts
vendored
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/** Dedicated fixture process: claim a real SQL run, heartbeat, then await a hard kill. */
|
||||
import { Pool } from 'pg';
|
||||
import { getLogger, setLoggerConfig } from '@stock-bot/logger';
|
||||
import { PostgreSQLClient } from '@stock-bot/postgres';
|
||||
import { BacktestRunner } from '../../apps/stock/orchestrator/src/backtest/BacktestRunner';
|
||||
import { PostgresBacktestRunRepository } from '../../apps/stock/orchestrator/src/backtest/PostgresBacktestRunRepository';
|
||||
import { RustBacktestAdapter } from '../../apps/stock/orchestrator/src/backtest/RustBacktestAdapter';
|
||||
|
||||
setLoggerConfig({ logLevel: 'fatal', logConsole: false });
|
||||
const url = process.env.PIPELINE_TEST_DATABASE_URL;
|
||||
const schema = process.env.BACKTEST_FIXTURE_SCHEMA;
|
||||
const runId = process.env.BACKTEST_FIXTURE_RUN_ID;
|
||||
if (
|
||||
!url ||
|
||||
!new URL(url).pathname.startsWith('/stock_bot_safety') ||
|
||||
!schema ||
|
||||
!/^stock_bot_safety_[a-f0-9]+$/.test(schema) ||
|
||||
!runId
|
||||
)
|
||||
throw new Error('Unsafe crash fixture target');
|
||||
const logger = getLogger('crash-owner');
|
||||
const pool = new Pool({ connectionString: url, options: `-c search_path=${schema}` });
|
||||
const postgres = new PostgreSQLClient(
|
||||
{ host: 'unused', port: 5432, database: 'unused', user: 'unused', password: 'unused' },
|
||||
logger
|
||||
);
|
||||
Object.defineProperty(postgres, 'connectionPool', { get: () => pool });
|
||||
const repository = new PostgresBacktestRunRepository(postgres, 500);
|
||||
const runner = new BacktestRunner({
|
||||
engine: new RustBacktestAdapter({ logger }),
|
||||
engineName: 'native',
|
||||
repository,
|
||||
logger,
|
||||
heartbeatMs: 50,
|
||||
prepare: async () => {
|
||||
process.send?.({ type: 'claimed' });
|
||||
await new Promise<void>(() => {});
|
||||
},
|
||||
});
|
||||
await runner.runQueued(runId);
|
||||
Loading…
Add table
Add a link
Reference in a new issue