continuation
This commit is contained in:
parent
32e43c9243
commit
879e9b4228
42 changed files with 2607 additions and 1306 deletions
49
test/fixtures/native-backtest-worker.ts
vendored
Normal file
49
test/fixtures/native-backtest-worker.ts
vendored
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
import {
|
||||
nativeWorkerRequestSchema,
|
||||
type NativeWorkerMessage,
|
||||
} from '../../apps/stock/orchestrator/src/backtest/native-worker-protocol';
|
||||
|
||||
function send(message: NativeWorkerMessage | { invalid: boolean }): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
process.send!(message, (error: Error | null) => (error ? reject(error) : resolve()));
|
||||
});
|
||||
}
|
||||
|
||||
process.once('message', async (input: unknown) => {
|
||||
const { config } = nativeWorkerRequestSchema.parse(input);
|
||||
const behavior = config.config?.fixtureBehavior;
|
||||
if (!behavior) {
|
||||
// The same adapter can recover and run the actual Rust engine after a failed worker.
|
||||
await import('../../apps/stock/orchestrator/src/backtest/native-worker');
|
||||
process.emit('message', input);
|
||||
return;
|
||||
}
|
||||
await send({ type: 'progress', progress: 0, message: `Fixture worker ready:${process.pid}` });
|
||||
switch (behavior) {
|
||||
case 'block':
|
||||
// Intentionally block this process. Messages, timers, and cooperative stop cannot run.
|
||||
while (true) {
|
||||
Math.sqrt(Math.random());
|
||||
}
|
||||
case 'crash':
|
||||
process.kill(process.pid, 'SIGKILL');
|
||||
break;
|
||||
case 'malformed':
|
||||
await send({ invalid: true });
|
||||
break;
|
||||
case 'invalid-result':
|
||||
await send({ type: 'result', result: '{"not":"a backtest result"}' });
|
||||
process.disconnect?.();
|
||||
break;
|
||||
case 'reported-error':
|
||||
await send({ type: 'error', message: 'Fixture native failure' });
|
||||
break;
|
||||
case 'no-result':
|
||||
process.exit(0);
|
||||
case 'result-then-block':
|
||||
await send({ type: 'result', result: '{}' });
|
||||
while (true) {
|
||||
Math.sqrt(Math.random());
|
||||
}
|
||||
}
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue