feat(backtests): separate saving from retry-safe run submission
This commit is contained in:
parent
5eb0985057
commit
9b9403e36b
18 changed files with 1200 additions and 226 deletions
|
|
@ -17,6 +17,7 @@ const migrations = [
|
|||
'11-simulation-execution-ledger.sql',
|
||||
'12-historical-datasets.sql',
|
||||
'13-strategy-recovery.sql',
|
||||
'14-backtest-submission.sql',
|
||||
];
|
||||
const cleanup: (() => Promise<void>)[] = [];
|
||||
afterEach(async () => {
|
||||
|
|
@ -130,6 +131,40 @@ async function fixture() {
|
|||
}
|
||||
|
||||
describe.skipIf(!url)('startup migrations on real PostgreSQL', () => {
|
||||
test('submission migration preserves legacy NULL-key runs and enforces complete key records', async () => {
|
||||
const f = await fixture();
|
||||
for (const filename of migrations.filter(name => name !== '14-backtest-submission.sql')) {
|
||||
await f.pool.query(
|
||||
readFileSync(new URL(`../../database/postgres/init/${filename}`, import.meta.url), 'utf8')
|
||||
);
|
||||
}
|
||||
const backtestId = randomUUID();
|
||||
const runId = randomUUID();
|
||||
await f.pool.query(
|
||||
`INSERT INTO backtests (id,name,strategy,symbols,start_date,end_date,initial_capital)
|
||||
VALUES ($1,'Legacy','sma-crossover','["A.US"]','2024-01-01','2024-02-01',10000)`,
|
||||
[backtestId]
|
||||
);
|
||||
await f.pool.query(
|
||||
"INSERT INTO runs (id,backtest_id,run_number,status,request_snapshot) VALUES ($1,$2,1,'completed','{\"legacy\":true}')",
|
||||
[runId, backtestId]
|
||||
);
|
||||
await f.startup().run();
|
||||
const row = (await f.pool.query('SELECT * FROM runs WHERE id = $1', [runId])).rows[0];
|
||||
expect(row.request_snapshot).toEqual({ legacy: true });
|
||||
expect(row.status).toBe('completed');
|
||||
expect([row.submission_principal, row.submission_key, row.submission_hash]).toEqual([
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
]);
|
||||
await expect(
|
||||
f.pool.query("UPDATE runs SET submission_key = 'incomplete' WHERE id = $1", [runId])
|
||||
).rejects.toThrow('runs_submission_complete');
|
||||
await f.startup().run();
|
||||
expect((await f.pool.query('SELECT * FROM runs')).rows).toHaveLength(1);
|
||||
});
|
||||
|
||||
test('two_concurrent_startups_same_client_lock and precheck_inside_lock', async () => {
|
||||
const f = await fixture();
|
||||
const firstAtPrecheck = gate();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue