mirror of
https://github.com/morluto/rea.git
synced 2026-11-22 06:25:44 +00:00
test(providers): consolidate composite child ownership checks (#12986)
This commit is contained in:
1 parent
efe2da79a8
commit
ddbfd07369
2 files changed
+38
-57
No files matched your search
@@ -102,7 +102,7 @@ it("does not create a previously unused child after the composite closes", async
|
||||
expect(child.close).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("retains every failed child resource across composite cleanup retries", async () => {
|
||||
it("retains child diagnostics across retries and returns the last typed failure unchanged", async () => {
|
||||
const left = failingProvider("provider-left", "address_name", "left-db");
|
||||
const right = failingProvider("provider-right", "procedure_info", "right-db");
|
||||
const client = new CompositeProvider([
|
||||
@@ -148,6 +148,15 @@ it("retains every failed child resource across composite cleanup retries", async
|
||||
|
||||
expect(left.close).toHaveBeenCalledTimes(2);
|
||||
expect(right.close).toHaveBeenCalledTimes(2);
|
||||
|
||||
left.close.mockResolvedValue(ok(null));
|
||||
const remaining = await client.close();
|
||||
if (remaining.ok) throw new Error("Expected remaining child cleanup failure");
|
||||
expect(remaining.error).toBe(right.cleanupError);
|
||||
right.close.mockResolvedValue(ok(null));
|
||||
expect(await client.close()).toEqual(ok(null));
|
||||
expect(left.close).toHaveBeenCalledTimes(3);
|
||||
expect(right.close).toHaveBeenCalledTimes(4);
|
||||
});
|
||||
|
||||
it.each(["live", "released", "unknown"] as const)(
|
||||
@@ -262,56 +271,29 @@ it.each(["opaque", "already released", "still owned"] as const)(
|
||||
},
|
||||
);
|
||||
|
||||
it("preserves one child's typed cleanup error unchanged", async () => {
|
||||
const child = failingProvider("provider-only", "address_name", "one-db");
|
||||
const client = new CompositeProvider([child.provider]).createClient(
|
||||
executableTarget,
|
||||
it("does not close an already released child again when retry options change", async () => {
|
||||
const first = failingProvider("provider-first", "address_name", "first-db");
|
||||
const second = failingProvider(
|
||||
"provider-second",
|
||||
"procedure_info",
|
||||
"second-db",
|
||||
);
|
||||
expect((await client.execute("address_name", {})).ok).toBe(true);
|
||||
|
||||
const closed = await client.close();
|
||||
|
||||
if (closed.ok) throw new Error("Expected child cleanup failure");
|
||||
expect(closed.error).toBe(child.cleanupError);
|
||||
});
|
||||
|
||||
it("does not close a child again after its cleanup succeeded", async () => {
|
||||
const firstIdentity = identity("provider-first");
|
||||
const secondIdentity = identity("provider-second");
|
||||
let secondCloseAttempts = 0;
|
||||
const firstClose = vi.fn(async () => ok(null));
|
||||
const secondClose = vi.fn(async () => {
|
||||
secondCloseAttempts += 1;
|
||||
return secondCloseAttempts === 1
|
||||
? err(new ProviderCleanupError("provider-second", ["second-db"], {}))
|
||||
: ok(null);
|
||||
});
|
||||
const makeProvider = (
|
||||
providerIdentity: ProviderIdentity,
|
||||
operation: Exclude<AnalysisOperation, "health">,
|
||||
close: AnalysisClient["close"],
|
||||
): AnalysisProvider => ({
|
||||
identity: () => providerIdentity,
|
||||
capabilities: () => [operationCapability(providerIdentity, operation)],
|
||||
createClient: () => ({
|
||||
execute: async () => ok(createAnalysisExecution(null, providerIdentity)),
|
||||
close,
|
||||
}),
|
||||
});
|
||||
first.close.mockResolvedValue(ok(null));
|
||||
second.close
|
||||
.mockResolvedValueOnce(err(second.cleanupError))
|
||||
.mockResolvedValue(ok(null));
|
||||
const client = new CompositeProvider([
|
||||
makeProvider(firstIdentity, "address_name", firstClose),
|
||||
makeProvider(secondIdentity, "procedure_info", secondClose),
|
||||
first.provider,
|
||||
second.provider,
|
||||
]).createClient(executableTarget);
|
||||
await client.execute("address_name", {});
|
||||
await client.execute("procedure_info", {});
|
||||
|
||||
expect((await client.close({ retainDocument: true })).ok).toBe(false);
|
||||
expect((await client.close()).ok).toBe(true);
|
||||
expect(firstClose).toHaveBeenCalledTimes(1);
|
||||
expect(secondClose).toHaveBeenCalledTimes(2);
|
||||
expect((await client.close({ retainDocument: true })).ok).toBe(true);
|
||||
expect(firstClose).toHaveBeenCalledTimes(1);
|
||||
expect(secondClose).toHaveBeenCalledTimes(2);
|
||||
expect(first.close).toHaveBeenCalledTimes(1);
|
||||
expect(second.close).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
it.each(["busy", "unknown", "idle", undefined] as const)(
|
||||
|
||||
@@ -28,10 +28,9 @@ const target: BinaryTarget = {
|
||||
|
||||
describe("composite analysis provider", () => {
|
||||
it("routes disjoint operations and does not start children during health", async () => {
|
||||
const hopperCalls: string[] = [];
|
||||
const nativeCalls: string[] = [];
|
||||
const hopper = provider("hopper", "address_name", hopperCalls);
|
||||
const native = provider("native", "analyze_function", nativeCalls);
|
||||
const starts: string[] = [];
|
||||
const hopper = provider("hopper", "address_name", starts);
|
||||
const native = provider("native", "analyze_function", starts);
|
||||
const composite = new CompositeProvider([hopper, native]);
|
||||
const client = composite.createClient(target);
|
||||
|
||||
@@ -39,12 +38,12 @@ describe("composite analysis provider", () => {
|
||||
ok: true,
|
||||
value: { result: null, provider: { id: "composite:hopper+native" } },
|
||||
});
|
||||
expect(hopperCalls).toEqual([]);
|
||||
expect(nativeCalls).toEqual([]);
|
||||
expect(starts).toEqual([]);
|
||||
expect(await client.execute("address_name", {})).toEqual({
|
||||
ok: true,
|
||||
value: createAnalysisExecution("hopper:address_name", hopper.identity()),
|
||||
});
|
||||
expect(starts).toEqual(["hopper"]);
|
||||
expect(await client.execute("analyze_function", {})).toEqual({
|
||||
ok: true,
|
||||
value: createAnalysisExecution(
|
||||
@@ -56,6 +55,7 @@ describe("composite analysis provider", () => {
|
||||
ok: false,
|
||||
error: { _tag: "AnalysisCapabilityUnavailableError" },
|
||||
});
|
||||
expect(starts).toEqual(["hopper", "native"]);
|
||||
});
|
||||
|
||||
it("rejects ambiguous provider routes", () => {
|
||||
@@ -256,21 +256,20 @@ const dynamicProvider = (
|
||||
const provider = (
|
||||
id: string,
|
||||
operation: Exclude<AnalysisOperation, "health">,
|
||||
calls: string[],
|
||||
starts: string[],
|
||||
): AnalysisProvider => {
|
||||
const identity: ProviderIdentity = { id, name: id, version: "1" };
|
||||
return {
|
||||
identity: () => identity,
|
||||
capabilities: () => [capability(identity, operation)],
|
||||
createClient: () => ({
|
||||
execute: (called) => {
|
||||
calls.push(called);
|
||||
return Promise.resolve(
|
||||
createClient: () => {
|
||||
starts.push(id);
|
||||
return {
|
||||
execute: async (called) =>
|
||||
ok(createAnalysisExecution(`${id}:${called}`, identity)),
|
||||
);
|
||||
},
|
||||
close: () => Promise.resolve(ok(null)),
|
||||
}),
|
||||
close: async () => ok(null),
|
||||
};
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user