fix(settings): correct connection and query timeout limits
This commit is contained in:
15 files changed
+180
-20
No files matched your search
@@ -0,0 +1,32 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { DEFAULT_CONNECT_TIMEOUT_SECS, normalizeConnectTimeoutSecs } from "@/lib/connection/timeoutLimits";
|
||||
|
||||
const dialogSource = readFileSync(new URL("../../../components/connection/ConnectionDialog.vue", import.meta.url), "utf8");
|
||||
|
||||
describe("ConnectionDialog timeout controls", () => {
|
||||
it("uses separate maximums for connection and query timeouts", () => {
|
||||
expect(dialogSource).toMatch(/v-model\.number="editGlobalConnectTimeoutSecs"[\s\S]*?min="1"[\s\S]*?:max="MAX_CONNECT_TIMEOUT_SECS"[\s\S]*?step="1"/);
|
||||
expect(dialogSource).toMatch(/v-model\.number="form\.connect_timeout_secs"[\s\S]*?min="1"[\s\S]*?:max="MAX_CONNECT_TIMEOUT_SECS"[\s\S]*?step="1"/);
|
||||
expect(dialogSource).toMatch(/v-model\.number="editGlobalQueryTimeoutSecs"[\s\S]*?min="0"[\s\S]*?:max="MAX_QUERY_TIMEOUT_SECS"[\s\S]*?step="1"/);
|
||||
expect(dialogSource).toMatch(/v-model\.number="form\.query_timeout_secs"[\s\S]*?min="0"[\s\S]*?:max="MAX_QUERY_TIMEOUT_SECS"[\s\S]*?step="1"/);
|
||||
expect(dialogSource).not.toContain('v-model.number="editGlobalQueryTimeoutSecs" type="number" min="0" max="300"');
|
||||
expect(dialogSource).not.toContain('v-model.number="form.query_timeout_secs" type="number" min="0" max="300"');
|
||||
expect(dialogSource).toContain("@input=\"clampQueryTimeoutInput($event, 'global')\"");
|
||||
expect(dialogSource).toContain("@input=\"clampQueryTimeoutInput($event, 'connection')\"");
|
||||
expect(dialogSource).toContain("@input=\"clampConnectTimeoutInput($event, 'global')\"");
|
||||
expect(dialogSource).toContain("@input=\"clampConnectTimeoutInput($event, 'connection')\"");
|
||||
expect(dialogSource).not.toContain('@blur="editGlobalQueryTimeoutSecs = normalizeGlobalQueryTimeoutSecs');
|
||||
});
|
||||
|
||||
it("restores the default when the connection timeout input is cleared", () => {
|
||||
expect(normalizeConnectTimeoutSecs("")).toBe(DEFAULT_CONNECT_TIMEOUT_SECS);
|
||||
expect(dialogSource).toContain("normalizeGlobalConnectTimeoutSecs(config.connect_timeout_secs)");
|
||||
expect(dialogSource).not.toContain("Number(config.connect_timeout_secs)");
|
||||
});
|
||||
|
||||
it("shows range help beside both global timeout labels", () => {
|
||||
expect(dialogSource).toContain('t("connection.globalConnectTimeoutHint")');
|
||||
expect(dialogSource).toContain('t("connection.globalQueryTimeoutHint")');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,37 @@
|
||||
import { beforeEach, describe, expect, it } from "vitest";
|
||||
import { loadTimeoutInheritanceBackup, TIMEOUT_INHERITANCE_BACKUP_STORAGE_KEY } from "@/lib/connection/timeoutInheritanceBackup";
|
||||
|
||||
const storage = new Map<string, string>();
|
||||
Object.defineProperty(globalThis, "localStorage", {
|
||||
configurable: true,
|
||||
value: {
|
||||
clear: () => storage.clear(),
|
||||
getItem: (key: string) => storage.get(key) ?? null,
|
||||
setItem: (key: string, value: string) => storage.set(key, value),
|
||||
},
|
||||
});
|
||||
|
||||
describe("timeout inheritance backup", () => {
|
||||
beforeEach(() => localStorage.clear());
|
||||
|
||||
it("preserves query timeouts up to one hour while connection timeouts remain capped at 300 seconds", () => {
|
||||
localStorage.setItem(
|
||||
TIMEOUT_INHERITANCE_BACKUP_STORAGE_KEY,
|
||||
JSON.stringify({
|
||||
version: 1,
|
||||
globalConnectTimeoutSecs: 301,
|
||||
globalQueryTimeoutSecs: 3600,
|
||||
connectSnapshots: { connection: 301 },
|
||||
querySnapshots: { longQuery: 3600, tooLong: 3601, unlimited: 0 },
|
||||
}),
|
||||
);
|
||||
|
||||
expect(loadTimeoutInheritanceBackup()).toEqual({
|
||||
version: 1,
|
||||
globalConnectTimeoutSecs: 300,
|
||||
globalQueryTimeoutSecs: 3600,
|
||||
connectSnapshots: { connection: 300 },
|
||||
querySnapshots: { longQuery: 3600, tooLong: 3600, unlimited: 0 },
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,3 +1,5 @@
|
||||
import { normalizeConnectTimeoutSecs, normalizeQueryTimeoutSecs } from "@/lib/connection/timeoutLimits";
|
||||
|
||||
export const TIMEOUT_INHERITANCE_BACKUP_STORAGE_KEY = "dbx-timeout-inheritance-backup-v1";
|
||||
|
||||
export interface TimeoutInheritanceBackup {
|
||||
@@ -8,12 +10,12 @@ export interface TimeoutInheritanceBackup {
|
||||
querySnapshots: Record<string, number>;
|
||||
}
|
||||
|
||||
function normalizeSnapshots(value: unknown, min: number): Record<string, number> {
|
||||
function normalizeSnapshots(value: unknown, normalize: (timeout: unknown) => number): Record<string, number> {
|
||||
if (!value || typeof value !== "object" || Array.isArray(value)) return {};
|
||||
const snapshots: Record<string, number> = {};
|
||||
for (const [id, timeout] of Object.entries(value)) {
|
||||
if (!id.trim() || typeof timeout !== "number" || !Number.isFinite(timeout)) continue;
|
||||
snapshots[id] = Math.min(300, Math.max(min, Math.round(timeout)));
|
||||
snapshots[id] = normalize(timeout);
|
||||
}
|
||||
return snapshots;
|
||||
}
|
||||
@@ -29,10 +31,10 @@ export function loadTimeoutInheritanceBackup(): TimeoutInheritanceBackup | null
|
||||
if (!Number.isFinite(globalConnectTimeoutSecs) || !Number.isFinite(globalQueryTimeoutSecs)) return null;
|
||||
return {
|
||||
version: 1,
|
||||
globalConnectTimeoutSecs: Math.min(300, Math.max(1, Math.round(globalConnectTimeoutSecs))),
|
||||
globalQueryTimeoutSecs: Math.min(300, Math.max(0, Math.round(globalQueryTimeoutSecs))),
|
||||
connectSnapshots: normalizeSnapshots(parsed.connectSnapshots, 1),
|
||||
querySnapshots: normalizeSnapshots(parsed.querySnapshots, 0),
|
||||
globalConnectTimeoutSecs: normalizeConnectTimeoutSecs(globalConnectTimeoutSecs),
|
||||
globalQueryTimeoutSecs: normalizeQueryTimeoutSecs(globalQueryTimeoutSecs),
|
||||
connectSnapshots: normalizeSnapshots(parsed.connectSnapshots, normalizeConnectTimeoutSecs),
|
||||
querySnapshots: normalizeSnapshots(parsed.querySnapshots, normalizeQueryTimeoutSecs),
|
||||
};
|
||||
} catch {
|
||||
return null;
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
export const DEFAULT_CONNECT_TIMEOUT_SECS = 10;
|
||||
export const MAX_CONNECT_TIMEOUT_SECS = 300;
|
||||
export const DEFAULT_QUERY_TIMEOUT_SECS = 30;
|
||||
export const MAX_QUERY_TIMEOUT_SECS = 3600;
|
||||
|
||||
export function normalizeConnectTimeoutSecs(value: unknown): number {
|
||||
if (typeof value !== "number" || !Number.isFinite(value)) return DEFAULT_CONNECT_TIMEOUT_SECS;
|
||||
return Math.min(MAX_CONNECT_TIMEOUT_SECS, Math.max(1, Math.round(value)));
|
||||
}
|
||||
|
||||
export function normalizeQueryTimeoutSecs(value: unknown): number {
|
||||
if (typeof value !== "number" || !Number.isFinite(value)) return DEFAULT_QUERY_TIMEOUT_SECS;
|
||||
return Math.min(MAX_QUERY_TIMEOUT_SECS, Math.max(0, Math.round(value)));
|
||||
}
|
||||
Reference in new issue
Block a user