@@ -42,6 +42,54 @@ function isActorStoppingDbError(error: unknown): boolean {
4242 ) ;
4343}
4444
45+ async function runWithActorStoppingRetry (
46+ driverTestConfig : DriverTestConfig ,
47+ fn : ( ) => Promise < void > ,
48+ ) : Promise < void > {
49+ let lastError : unknown ;
50+
51+ for ( let attempt = 0 ; attempt < 3 ; attempt += 1 ) {
52+ try {
53+ await fn ( ) ;
54+ return ;
55+ } catch ( error ) {
56+ if ( ! isActorStoppingDbError ( error ) ) {
57+ throw error ;
58+ }
59+
60+ lastError = error ;
61+ }
62+
63+ await waitFor ( driverTestConfig , SLEEP_WAIT_MS + 100 ) ;
64+ }
65+
66+ throw lastError ;
67+ }
68+
69+ async function expectIntegrityCheckOk (
70+ driverTestConfig : DriverTestConfig ,
71+ integrityCheck : ( ) => Promise < string > ,
72+ ) : Promise < void > {
73+ let lastError : unknown ;
74+
75+ for ( let attempt = 0 ; attempt < 6 ; attempt += 1 ) {
76+ try {
77+ expect ( ( await integrityCheck ( ) ) . toLowerCase ( ) ) . toBe ( "ok" ) ;
78+ return ;
79+ } catch ( error ) {
80+ if ( ! isActorStoppingDbError ( error ) ) {
81+ throw error ;
82+ }
83+
84+ lastError = error ;
85+ }
86+
87+ await waitFor ( driverTestConfig , SLEEP_WAIT_MS + 100 ) ;
88+ }
89+
90+ throw lastError ;
91+ }
92+
4593function getDbActor (
4694 client : Awaited < ReturnType < typeof setupDriverTest > > [ "client" ] ,
4795 variant : DbVariant ,
@@ -59,7 +107,7 @@ export function runActorDbTests(driverTestConfig: DriverTestConfig) {
59107 : undefined ;
60108
61109 for ( const variant of variants ) {
62- describe ( `Actor Database (${ variant } ) Tests` , ( ) => {
110+ describe . sequential ( `Actor Database (${ variant } ) Tests` , ( ) => {
63111 test (
64112 "bootstraps schema on startup" ,
65113 async ( c ) => {
@@ -467,26 +515,37 @@ export function runActorDbTests(driverTestConfig: DriverTestConfig) {
467515 ] ) ;
468516
469517 await actor . reset ( ) ;
470- await actor . runMixedWorkload (
471- INTEGRITY_SEED_COUNT ,
472- INTEGRITY_CHURN_COUNT ,
518+ await runWithActorStoppingRetry (
519+ driverTestConfig ,
520+ async ( ) =>
521+ await actor . runMixedWorkload (
522+ INTEGRITY_SEED_COUNT ,
523+ INTEGRITY_CHURN_COUNT ,
524+ ) ,
473525 ) ;
474- expect ( ( await actor . integrityCheck ( ) ) . toLowerCase ( ) ) . toBe (
475- "ok" ,
526+ await expectIntegrityCheckOk (
527+ driverTestConfig ,
528+ async ( ) => await actor . integrityCheck ( ) ,
476529 ) ;
477530
478531 await actor . triggerSleep ( ) ;
479532 await waitFor ( driverTestConfig , SLEEP_WAIT_MS + 100 ) ;
480- expect ( ( await actor . integrityCheck ( ) ) . toLowerCase ( ) ) . toBe (
481- "ok" ,
533+ await expectIntegrityCheckOk (
534+ driverTestConfig ,
535+ async ( ) => await actor . integrityCheck ( ) ,
482536 ) ;
483537 } ,
484538 dbTestTimeout ,
485539 ) ;
486540 } ) ;
487541 }
488542
489- describe ( "Actor Database Lifecycle Cleanup Tests" , ( ) => {
543+ // These assertions rely on the fixture's module-global lifecycle counters.
544+ // Dynamic actors and the observer actor run in separate isolates, so those
545+ // globals are not shared across actors there.
546+ describe . skipIf ( driverTestConfig . isDynamic ) (
547+ "Actor Database Lifecycle Cleanup Tests" ,
548+ ( ) => {
490549 test (
491550 "runs db provider cleanup on sleep" ,
492551 async ( c ) => {
@@ -674,5 +733,6 @@ export function runActorDbTests(driverTestConfig: DriverTestConfig) {
674733 } ,
675734 lifecycleTestTimeout ,
676735 ) ;
677- } ) ;
736+ } ,
737+ ) ;
678738}
0 commit comments