refactor(cli): simplify service restart recovery
This commit is contained in:
parent
f0724bf2d9
commit
eae5eaff5d
5 changed files with 108 additions and 20 deletions
|
|
@ -56,6 +56,7 @@ function update(version: string): OpenCodeEvent {
|
|||
async function mount(
|
||||
reconnect?: (onStatus: (status: Service.Status) => void, signal: AbortSignal) => Promise<{ api: OpenCodeClient }>,
|
||||
log?: LogSink,
|
||||
reload?: (signal?: AbortSignal) => Promise<void>,
|
||||
) {
|
||||
const events = createEventStream()
|
||||
const calls = createFetch(undefined, events)
|
||||
|
|
@ -70,7 +71,7 @@ async function mount(
|
|||
|
||||
const app = await testRender(() => (
|
||||
<TestTuiContexts log={log}>
|
||||
<ClientProvider api={createApi(calls.fetch)} reconnect={reconnect}>
|
||||
<ClientProvider api={createApi(calls.fetch)} reconnect={reconnect} reload={reload}>
|
||||
<ProjectProvider>
|
||||
<Probe
|
||||
onReady={async (ctx) => {
|
||||
|
|
@ -349,4 +350,38 @@ describe("useEvent", () => {
|
|||
app.renderer.destroy()
|
||||
await wait(() => aborted)
|
||||
})
|
||||
|
||||
test("cancels pending endpoint resolution before explicit restart", async () => {
|
||||
let aborted = false
|
||||
let restarts = 0
|
||||
const { app, events, client } = await mount(
|
||||
(_onStatus, signal) =>
|
||||
new Promise((_, reject) => {
|
||||
signal.addEventListener(
|
||||
"abort",
|
||||
() => {
|
||||
aborted = true
|
||||
reject(signal.reason)
|
||||
},
|
||||
{ once: true },
|
||||
)
|
||||
}),
|
||||
undefined,
|
||||
async () => {
|
||||
restarts += 1
|
||||
},
|
||||
)
|
||||
|
||||
try {
|
||||
await wait(() => client.connection.status() === "connected")
|
||||
events.disconnect()
|
||||
await wait(() => client.connection.status() === "reconnecting")
|
||||
await client.reload?.()
|
||||
await wait(() => aborted && client.connection.status() === "connected")
|
||||
|
||||
expect(restarts).toBe(1)
|
||||
} finally {
|
||||
app.renderer.destroy()
|
||||
}
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue