fix: pr feedbacks
This commit is contained in:
parent
d5eea2fb97
commit
4a73184a5a
6 changed files with 53 additions and 5 deletions
|
|
@ -1,3 +1,4 @@
|
||||||
ZEROBYTE_DATABASE_URL=:memory:
|
ZEROBYTE_DATABASE_URL=:memory:
|
||||||
APP_SECRET=8b9acd4456dd5db0a4a3c4f4e1240b2c3ae08bb59690167197425e4a25dd9a69
|
APP_SECRET=8b9acd4456dd5db0a4a3c4f4e1240b2c3ae08bb59690167197425e4a25dd9a69
|
||||||
BASE_URL=http://localhost:4096
|
BASE_URL=http://localhost:4096
|
||||||
|
ENABLE_LOCAL_AGENT=true
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import { EventEmitter } from "node:events";
|
import { EventEmitter } from "node:events";
|
||||||
import { PassThrough } from "node:stream";
|
import { PassThrough } from "node:stream";
|
||||||
import { afterEach, expect, test, vi } from "vitest";
|
import { afterEach, beforeEach, expect, test, vi } from "vitest";
|
||||||
|
import type { ProcessWithAgentRuntime } from "../helpers/runtime-state.dev";
|
||||||
|
|
||||||
const spawnMock = vi.fn();
|
const spawnMock = vi.fn();
|
||||||
|
|
||||||
|
|
@ -8,7 +9,19 @@ vi.mock("node:child_process", async () => {
|
||||||
return { spawn: spawnMock };
|
return { spawn: spawnMock };
|
||||||
});
|
});
|
||||||
|
|
||||||
const { spawnLocalAgent, stopLocalAgent } = await import("../agents-manager");
|
let spawnLocalAgent: (typeof import("../agents-manager"))["spawnLocalAgent"];
|
||||||
|
let stopLocalAgent: (typeof import("../agents-manager"))["stopLocalAgent"];
|
||||||
|
|
||||||
|
const processWithAgentRuntime = process as ProcessWithAgentRuntime;
|
||||||
|
|
||||||
|
const setAgentRuntime = () => {
|
||||||
|
processWithAgentRuntime.__zerobyteAgentRuntime = {
|
||||||
|
agentManager: null,
|
||||||
|
localAgent: null,
|
||||||
|
isStoppingLocalAgent: false,
|
||||||
|
localAgentRestartTimeout: null,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
type FakeChildProcess = EventEmitter & {
|
type FakeChildProcess = EventEmitter & {
|
||||||
stdout: PassThrough;
|
stdout: PassThrough;
|
||||||
|
|
@ -34,8 +47,15 @@ const createFakeChild = () => {
|
||||||
return child;
|
return child;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
vi.resetModules();
|
||||||
|
setAgentRuntime();
|
||||||
|
({ spawnLocalAgent, stopLocalAgent } = await import("../agents-manager"));
|
||||||
|
});
|
||||||
|
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
await stopLocalAgent();
|
await stopLocalAgent();
|
||||||
|
delete processWithAgentRuntime.__zerobyteAgentRuntime;
|
||||||
spawnMock.mockReset();
|
spawnMock.mockReset();
|
||||||
vi.restoreAllMocks();
|
vi.restoreAllMocks();
|
||||||
vi.useRealTimers();
|
vi.useRealTimers();
|
||||||
|
|
|
||||||
|
|
@ -152,6 +152,7 @@ export const startAgentRuntime = async () => {
|
||||||
|
|
||||||
if (runtime.agentManager) {
|
if (runtime.agentManager) {
|
||||||
await runtime.agentManager.stop();
|
await runtime.agentManager.stop();
|
||||||
|
runtime.agentManager = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { createAgentManagerRuntime } = await import("./controller/server");
|
const { createAgentManagerRuntime } = await import("./controller/server");
|
||||||
|
|
|
||||||
|
|
@ -147,8 +147,8 @@ export const createControllerAgentSession = (
|
||||||
yield* Effect.sync(() => {
|
yield* Effect.sync(() => {
|
||||||
try {
|
try {
|
||||||
const sendResult = socket.send(message);
|
const sendResult = socket.send(message);
|
||||||
if (sendResult <= 0) {
|
if (sendResult === 0) {
|
||||||
handleSendFailure(sendResult === 0 ? "connection issue" : "backpressure");
|
handleSendFailure("connection issue");
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
handleSendFailure(toMessage(error));
|
handleSendFailure(toMessage(error));
|
||||||
|
|
|
||||||
|
|
@ -283,6 +283,29 @@ describe("stop backup", () => {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("should settle and mark the backup as failed when the backup process throws", async () => {
|
||||||
|
const { resticBackupMock } = setup();
|
||||||
|
const volume = await createTestVolume();
|
||||||
|
const repository = await createTestRepository();
|
||||||
|
const schedule = await createTestBackupSchedule({
|
||||||
|
volumeId: volume.id,
|
||||||
|
repositoryId: repository.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
resticBackupMock.mockImplementationOnce(() => Promise.reject(new Error("restic crashed")));
|
||||||
|
|
||||||
|
const result = await Promise.race([
|
||||||
|
backupsService.executeBackup(schedule.id).then(() => "settled"),
|
||||||
|
new Promise<string>((resolve) => setTimeout(() => resolve("timed-out"), 100)),
|
||||||
|
]);
|
||||||
|
|
||||||
|
expect(result).toBe("settled");
|
||||||
|
|
||||||
|
const updatedSchedule = await getScheduleByIdOrShortId(schedule.id);
|
||||||
|
expect(updatedSchedule.lastBackupStatus).toBe("error");
|
||||||
|
expect(updatedSchedule.lastBackupError).toBe("Error: restic crashed");
|
||||||
|
});
|
||||||
|
|
||||||
test("should block forget on the same repository until the active backup completes", async () => {
|
test("should block forget on the same repository until the active backup completes", async () => {
|
||||||
const { resticBackupMock, resticForgetMock, runBackupMock } = setup();
|
const { resticBackupMock, resticForgetMock, runBackupMock } = setup();
|
||||||
const volume = await createTestVolume();
|
const volume = await createTestVolume();
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,10 @@ export const createAgentBackupMocks = (
|
||||||
status: "failed",
|
status: "failed",
|
||||||
error: stderrLines.join("\n") || resultWithStderr.stderr || result.error,
|
error: stderrLines.join("\n") || resultWithStderr.stderr || result.error,
|
||||||
});
|
});
|
||||||
})().catch(() => {});
|
})().catch((err) => {
|
||||||
|
runningBackups.delete(request.scheduleId);
|
||||||
|
resolve({ status: "failed", error: String(err) });
|
||||||
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue