Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,54 @@ function isActorStoppingDbError(error: unknown): boolean {
);
}

async function runWithActorStoppingRetry(
driverTestConfig: DriverTestConfig,
fn: () => Promise<void>,
): Promise<void> {
let lastError: unknown;

for (let attempt = 0; attempt < 3; attempt += 1) {
try {
await fn();
return;
} catch (error) {
if (!isActorStoppingDbError(error)) {
throw error;
}

lastError = error;
}

await waitFor(driverTestConfig, SLEEP_WAIT_MS + 100);
}

throw lastError;
}

async function expectIntegrityCheckOk(
driverTestConfig: DriverTestConfig,
integrityCheck: () => Promise<string>,
): Promise<void> {
let lastError: unknown;

for (let attempt = 0; attempt < 6; attempt += 1) {
try {
expect((await integrityCheck()).toLowerCase()).toBe("ok");
return;
} catch (error) {
if (!isActorStoppingDbError(error)) {
throw error;
}

lastError = error;
}

await waitFor(driverTestConfig, SLEEP_WAIT_MS + 100);
}

throw lastError;
}

function getDbActor(
client: Awaited<ReturnType<typeof setupDriverTest>>["client"],
variant: DbVariant,
Expand All @@ -61,7 +109,7 @@ export function runActorDbTests(driverTestConfig: DriverTestConfig) {
: undefined;

for (const variant of variants) {
describe(`Actor Database (${variant}) Tests`, () => {
describe.sequential(`Actor Database (${variant}) Tests`, () => {
test(
"bootstraps schema on startup",
async (c) => {
Expand Down Expand Up @@ -468,25 +516,36 @@ export function runActorDbTests(driverTestConfig: DriverTestConfig) {
]);

await actor.reset();
await actor.runMixedWorkload(
INTEGRITY_SEED_COUNT,
INTEGRITY_CHURN_COUNT,
await runWithActorStoppingRetry(
driverTestConfig,
async () =>
await actor.runMixedWorkload(
INTEGRITY_SEED_COUNT,
INTEGRITY_CHURN_COUNT,
),
);
expect((await actor.integrityCheck()).toLowerCase()).toBe(
"ok",
await expectIntegrityCheckOk(
driverTestConfig,
async () => await actor.integrityCheck(),
);

await actor.triggerSleep();
expect((await actor.integrityCheck()).toLowerCase()).toBe(
"ok",
await expectIntegrityCheckOk(
driverTestConfig,
async () => await actor.integrityCheck(),
);
},
dbTestTimeout,
);
});
}

describe("Actor Database Lifecycle Cleanup Tests", () => {
// These assertions rely on the fixture's module-global lifecycle counters.
// Dynamic actors and the observer actor run in separate isolates, so those
// globals are not shared across actors there.
describe.skipIf(driverTestConfig.isDynamic)(
"Actor Database Lifecycle Cleanup Tests",
() => {
test(
"runs db provider cleanup on sleep",
async (c) => {
Expand Down Expand Up @@ -674,5 +733,6 @@ export function runActorDbTests(driverTestConfig: DriverTestConfig) {
},
lifecycleTestTimeout,
);
});
},
);
}
Loading