mirror of
https://github.com/RSSNext/Folo.git
synced 2026-10-17 05:08:13 +08:00
fix(release): extend OTA sync trigger timeout
This commit is contained in:
@@ -11,7 +11,21 @@ import { pathToFileURL } from "node:url"
|
||||
* }} TriggerOtaSyncOptions
|
||||
*/
|
||||
|
||||
const DEFAULT_TIMEOUT_MS = 10_000
|
||||
const DEFAULT_TIMEOUT_MS = 120_000
|
||||
|
||||
export function readOtaSyncTimeoutMs(value) {
|
||||
if (!value) {
|
||||
return DEFAULT_TIMEOUT_MS
|
||||
}
|
||||
|
||||
const timeoutMs = Number(value)
|
||||
|
||||
if (!Number.isInteger(timeoutMs) || timeoutMs <= 0) {
|
||||
throw new TypeError("OTA sync timeout must be a positive integer")
|
||||
}
|
||||
|
||||
return timeoutMs
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {TriggerOtaSyncOptions} options
|
||||
@@ -81,6 +95,7 @@ async function main() {
|
||||
baseUrl: process.env.OTA_BASE_URL ?? "",
|
||||
token: process.env.OTA_SYNC_TOKEN ?? "",
|
||||
headerName: process.env.OTA_SYNC_TOKEN_HEADER ?? "",
|
||||
timeoutMs: readOtaSyncTimeoutMs(process.env.OTA_SYNC_TIMEOUT_MS),
|
||||
})
|
||||
|
||||
console.info("Triggered OTA sync successfully")
|
||||
|
||||
@@ -25,6 +25,14 @@ afterEach(async () => {
|
||||
})
|
||||
|
||||
describe("triggerOtaSync", () => {
|
||||
it("reads a configurable OTA sync timeout", async () => {
|
||||
const { readOtaSyncTimeoutMs } = await import("./trigger-ota-sync.mjs")
|
||||
|
||||
expect(readOtaSyncTimeoutMs()).toBe(120_000)
|
||||
expect(readOtaSyncTimeoutMs("30000")).toBe(30_000)
|
||||
expect(() => readOtaSyncTimeoutMs("0")).toThrow("OTA sync timeout must be a positive integer")
|
||||
})
|
||||
|
||||
it("POSTs to /internal/sync with the configured auth header", async () => {
|
||||
const requests: Array<{ method?: string; url?: string; headerValue?: string }> = []
|
||||
const headerName = "x-ota-sync-token"
|
||||
|
||||
Reference in New Issue
Block a user