mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2026-08-26 21:37:05 +00:00
fix: close finite remote database connections
This commit is contained in:
@@ -8,7 +8,7 @@ export type CouchDBConnectionProbeResult = { ok: true } | { ok: false; reason: s
|
||||
type CouchDBConnectionResult =
|
||||
| string
|
||||
| {
|
||||
db: unknown;
|
||||
db: { close(): Promise<void> };
|
||||
info: unknown;
|
||||
};
|
||||
|
||||
@@ -50,7 +50,11 @@ export async function probeCouchDBConnection(
|
||||
if (typeof result === "string") {
|
||||
return { ok: false, reason: result };
|
||||
}
|
||||
return { ok: true };
|
||||
try {
|
||||
return { ok: true };
|
||||
} finally {
|
||||
await result.db.close();
|
||||
}
|
||||
}
|
||||
|
||||
export function isValidCouchDBServerURL(value: string): boolean {
|
||||
|
||||
@@ -14,8 +14,9 @@ describe("CouchDB setup connection policy", () => {
|
||||
] as const)(
|
||||
"%s can %s without changing the Commonlib connection contract",
|
||||
async (createIfMissing, _description) => {
|
||||
const close = vi.fn(async () => undefined);
|
||||
const connectRemoteCouchDBWithSetting = vi.fn(async () => ({
|
||||
db: {},
|
||||
db: { close },
|
||||
info: { db_name: "notes" },
|
||||
}));
|
||||
const replicator = {
|
||||
@@ -27,6 +28,7 @@ describe("CouchDB setup connection policy", () => {
|
||||
await expect(probeCouchDBConnection(replicator, settings, createIfMissing)).resolves.toEqual({ ok: true });
|
||||
expect(connectRemoteCouchDBWithSetting).toHaveBeenCalledWith(settings, false, createIfMissing, false);
|
||||
expect(replicator.tryConnectRemote).not.toHaveBeenCalled();
|
||||
expect(close).toHaveBeenCalledOnce();
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user