Improve failover startup handling and status UI
This commit is contained in:
@@ -364,7 +364,9 @@ test('selector activation failure rolls runtime and config back before applied t
|
||||
},
|
||||
});
|
||||
const before = harness.snapshot();
|
||||
await assert.rejects(harness.service.restart(), /selector failed/);
|
||||
await assert.rejects(harness.service.restart(), (error) => (
|
||||
error.code === 'PROCESS_START_FAILED' && error.cause?.message === 'selector failed'
|
||||
));
|
||||
assert.deepEqual(domain(harness.snapshot()), domain(before));
|
||||
assert.equal(harness.events.includes('state.update'), false);
|
||||
assert.deepEqual(harness.events.filter((event) => event.startsWith('selector.')), ['selector.primary', 'selector.primary']);
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
|
||||
import { createSingboxSelectorService } from '../../dist/server/services/singboxSelectorService.js';
|
||||
|
||||
test('selector waits for the sing-box API after a fresh process start', async () => {
|
||||
let attempts = 0;
|
||||
const service = createSingboxSelectorService({
|
||||
port: 0,
|
||||
send: async (method) => {
|
||||
attempts += 1;
|
||||
if (attempts < 3) throw Object.assign(new Error('not ready'), { code: 'ECONNREFUSED' });
|
||||
return method === 'GET' ? { now: 'channel-primary' } : {};
|
||||
},
|
||||
});
|
||||
|
||||
assert.deepEqual(await service.select('primary'), { role: 'primary' });
|
||||
assert.equal(attempts, 4);
|
||||
});
|
||||
Reference in New Issue
Block a user