@@ -44,6 +44,54 @@ function isActorStoppingDbError(error: unknown): boolean {
4444 ) ;
4545}
4646
47+ async function runWithActorStoppingRetry (
48+ driverTestConfig : DriverTestConfig ,
49+ fn : ( ) => Promise < void > ,
50+ ) : Promise < void > {
51+ let lastError : unknown ;
52+
53+ for ( let attempt = 0 ; attempt < 3 ; attempt += 1 ) {
54+ try {
55+ await fn ( ) ;
56+ return ;
57+ } catch ( error ) {
58+ if ( ! isActorStoppingDbError ( error ) ) {
59+ throw error ;
60+ }
61+
62+ lastError = error ;
63+ }
64+
65+ await waitFor ( driverTestConfig , SLEEP_WAIT_MS + 100 ) ;
66+ }
67+
68+ throw lastError ;
69+ }
70+
71+ async function expectIntegrityCheckOk (
72+ driverTestConfig : DriverTestConfig ,
73+ integrityCheck : ( ) => Promise < string > ,
74+ ) : Promise < void > {
75+ let lastError : unknown ;
76+
77+ for ( let attempt = 0 ; attempt < 6 ; attempt += 1 ) {
78+ try {
79+ expect ( ( await integrityCheck ( ) ) . toLowerCase ( ) ) . toBe ( "ok" ) ;
80+ return ;
81+ } catch ( error ) {
82+ if ( ! isActorStoppingDbError ( error ) ) {
83+ throw error ;
84+ }
85+
86+ lastError = error ;
87+ }
88+
89+ await waitFor ( driverTestConfig , SLEEP_WAIT_MS + 100 ) ;
90+ }
91+
92+ throw lastError ;
93+ }
94+
4795function getDbActor (
4896 client : Awaited < ReturnType < typeof setupDriverTest > > [ "client" ] ,
4997 variant : DbVariant ,
@@ -61,7 +109,7 @@ export function runActorDbTests(driverTestConfig: DriverTestConfig) {
61109 : undefined ;
62110
63111 for ( const variant of variants ) {
64- describe ( `Actor Database (${ variant } ) Tests` , ( ) => {
112+ describe . sequential ( `Actor Database (${ variant } ) Tests` , ( ) => {
65113 test (
66114 "bootstraps schema on startup" ,
67115 async ( c ) => {
@@ -468,25 +516,36 @@ export function runActorDbTests(driverTestConfig: DriverTestConfig) {
468516 ] ) ;
469517
470518 await actor . reset ( ) ;
471- await actor . runMixedWorkload (
472- INTEGRITY_SEED_COUNT ,
473- INTEGRITY_CHURN_COUNT ,
519+ await runWithActorStoppingRetry (
520+ driverTestConfig ,
521+ async ( ) =>
522+ await actor . runMixedWorkload (
523+ INTEGRITY_SEED_COUNT ,
524+ INTEGRITY_CHURN_COUNT ,
525+ ) ,
474526 ) ;
475- expect ( ( await actor . integrityCheck ( ) ) . toLowerCase ( ) ) . toBe (
476- "ok" ,
527+ await expectIntegrityCheckOk (
528+ driverTestConfig ,
529+ async ( ) => await actor . integrityCheck ( ) ,
477530 ) ;
478531
479532 await actor . triggerSleep ( ) ;
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