Skip to content

Commit 589bbe0

Browse files
committed
test(rivetkit): stabilize actor db driver tests
1 parent 8ceea0a commit 589bbe0

1 file changed

Lines changed: 62 additions & 9 deletions

File tree

rivetkit-typescript/packages/rivetkit/tests/driver/actor-db.test.ts

Lines changed: 62 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,54 @@ function isActorStoppingDbError(error: unknown): boolean {
4545
);
4646
}
4747

48+
async function runWithActorStoppingRetry(
49+
driverTestConfig: DriverTestConfig,
50+
fn: () => Promise<void>,
51+
): Promise<void> {
52+
let lastError: unknown;
53+
54+
for (let attempt = 0; attempt < 3; attempt += 1) {
55+
try {
56+
await fn();
57+
return;
58+
} catch (error) {
59+
if (!isActorStoppingDbError(error)) {
60+
throw error;
61+
}
62+
63+
lastError = error;
64+
}
65+
66+
await waitFor(driverTestConfig, SLEEP_WAIT_MS + 100);
67+
}
68+
69+
throw lastError;
70+
}
71+
72+
async function expectIntegrityCheckOk(
73+
driverTestConfig: DriverTestConfig,
74+
integrityCheck: () => Promise<string>,
75+
): Promise<void> {
76+
let lastError: unknown;
77+
78+
for (let attempt = 0; attempt < 6; attempt += 1) {
79+
try {
80+
expect((await integrityCheck()).toLowerCase()).toBe("ok");
81+
return;
82+
} catch (error) {
83+
if (!isActorStoppingDbError(error)) {
84+
throw error;
85+
}
86+
87+
lastError = error;
88+
}
89+
90+
await waitFor(driverTestConfig, SLEEP_WAIT_MS + 100);
91+
}
92+
93+
throw lastError;
94+
}
95+
4896
function getDbActor(
4997
client: Awaited<ReturnType<typeof setupDriverTest>>["client"],
5098
_variant: DbVariant,
@@ -62,7 +110,7 @@ describeDriverMatrix("Actor Db", (driverTestConfig) => {
62110
: undefined;
63111

64112
for (const variant of variants) {
65-
describe(`Actor Database (${variant}) Tests`, () => {
113+
describe.sequential(`Actor Database (${variant}) Tests`, () => {
66114
test(
67115
"bootstraps schema on startup",
68116
async (c) => {
@@ -474,18 +522,23 @@ describeDriverMatrix("Actor Db", (driverTestConfig) => {
474522
]);
475523

476524
await actor.reset();
477-
await actor.runMixedWorkload(
478-
INTEGRITY_SEED_COUNT,
479-
INTEGRITY_CHURN_COUNT,
525+
await runWithActorStoppingRetry(
526+
driverTestConfig,
527+
async () =>
528+
await actor.runMixedWorkload(
529+
INTEGRITY_SEED_COUNT,
530+
INTEGRITY_CHURN_COUNT,
531+
),
480532
);
481-
expect((await actor.integrityCheck()).toLowerCase()).toBe(
482-
"ok",
533+
await expectIntegrityCheckOk(
534+
driverTestConfig,
535+
async () => await actor.integrityCheck(),
483536
);
484537

485538
await actor.triggerSleep();
486-
await waitFor(driverTestConfig, SLEEP_WAIT_MS + 100);
487-
expect((await actor.integrityCheck()).toLowerCase()).toBe(
488-
"ok",
539+
await expectIntegrityCheckOk(
540+
driverTestConfig,
541+
async () => await actor.integrityCheck(),
489542
);
490543
},
491544
dbTestTimeout,

0 commit comments

Comments
 (0)