mirror of
https://gitee.com/zhangsken/opencode.git
synced 2026-10-16 10:30:01 +08:00
app: refactor server management backend (#13813)
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
import { describe, expect, test } from "bun:test"
|
||||
import type { ServerConnection } from "@/context/server"
|
||||
import { checkServerHealth } from "./server-health"
|
||||
|
||||
const server: ServerConnection.HttpBase = {
|
||||
url: "http://localhost:4096",
|
||||
}
|
||||
|
||||
function abortFromInput(input: RequestInfo | URL, init?: RequestInit) {
|
||||
if (init?.signal) return init.signal
|
||||
if (input instanceof Request) return input.signal
|
||||
@@ -15,7 +20,7 @@ describe("checkServerHealth", () => {
|
||||
headers: { "content-type": "application/json" },
|
||||
})) as unknown as typeof globalThis.fetch
|
||||
|
||||
const result = await checkServerHealth("http://localhost:4096", fetch)
|
||||
const result = await checkServerHealth(server, fetch)
|
||||
|
||||
expect(result).toEqual({ healthy: true, version: "1.2.3" })
|
||||
})
|
||||
@@ -25,7 +30,7 @@ describe("checkServerHealth", () => {
|
||||
throw new Error("network")
|
||||
}) as unknown as typeof globalThis.fetch
|
||||
|
||||
const result = await checkServerHealth("http://localhost:4096", fetch)
|
||||
const result = await checkServerHealth(server, fetch)
|
||||
|
||||
expect(result).toEqual({ healthy: false })
|
||||
})
|
||||
@@ -51,7 +56,9 @@ describe("checkServerHealth", () => {
|
||||
)
|
||||
})) as unknown as typeof globalThis.fetch
|
||||
|
||||
const result = await checkServerHealth("http://localhost:4096", fetch, { timeoutMs: 10 }).finally(() => {
|
||||
const result = await checkServerHealth(server, fetch, {
|
||||
timeoutMs: 10,
|
||||
}).finally(() => {
|
||||
if (timeout) Object.defineProperty(AbortSignal, "timeout", timeout)
|
||||
if (!timeout) Reflect.deleteProperty(AbortSignal, "timeout")
|
||||
})
|
||||
@@ -71,7 +78,9 @@ describe("checkServerHealth", () => {
|
||||
}) as unknown as typeof globalThis.fetch
|
||||
|
||||
const abort = new AbortController()
|
||||
await checkServerHealth("http://localhost:4096", fetch, { signal: abort.signal })
|
||||
await checkServerHealth(server, fetch, {
|
||||
signal: abort.signal,
|
||||
})
|
||||
|
||||
expect(signal).toBe(abort.signal)
|
||||
})
|
||||
@@ -87,7 +96,7 @@ describe("checkServerHealth", () => {
|
||||
})
|
||||
}) as unknown as typeof globalThis.fetch
|
||||
|
||||
const result = await checkServerHealth("http://localhost:4096", fetch, {
|
||||
const result = await checkServerHealth(server, fetch, {
|
||||
retryCount: 2,
|
||||
retryDelayMs: 1,
|
||||
})
|
||||
@@ -103,7 +112,7 @@ describe("checkServerHealth", () => {
|
||||
throw new TypeError("network")
|
||||
}) as unknown as typeof globalThis.fetch
|
||||
|
||||
const result = await checkServerHealth("http://localhost:4096", fetch, {
|
||||
const result = await checkServerHealth(server, fetch, {
|
||||
retryCount: 2,
|
||||
retryDelayMs: 1,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user