@@ -645,35 +645,6 @@ describe('PyodideWorkerManager', () => {
645645 } ) ;
646646
647647 describe ( 'retry logic' , ( ) => {
648- test ( 'should not retry when maxRetries is 0' , async ( ) => {
649- // Create a worker manager with retries disabled
650- const noRetryWorkerManager = new PyodideWorkerManager (
651- {
652- maxRetries : 0 ,
653- initialDelayMs : 10 ,
654- maxDelayMs : 100 ,
655- backoffMultiplier : 2 ,
656- totalTimeoutMs : 5000 ,
657- } ,
658- createDefaultCfnLintSettings ( ) ,
659-
660- mockLogging ,
661- ) ;
662-
663- // Mock worker creation to fail
664- workerConstructor . mockImplementation ( ( ) => {
665- throw new Error ( 'Worker creation failed' ) ;
666- } ) ;
667-
668- // Expect initialization to fail immediately without retries
669- await expect ( noRetryWorkerManager . initialize ( ) ) . rejects . toThrow (
670- 'Pyodide initialization failed after 1 attempts. Last error: Worker creation failed' ,
671- ) ;
672-
673- // Verify no retry attempts were logged
674- expect ( mockLogging . warn . callCount ) . toBe ( 0 ) ; // No retry warnings
675- } ) ;
676-
677648 test ( 'should retry initialization on failure and eventually succeed' , async ( ) => {
678649 // Create a worker manager with retry enabled
679650 const retryWorkerManager = new PyodideWorkerManager (
@@ -954,9 +925,7 @@ describe('PyodideWorkerManager', () => {
954925 } ) ;
955926
956927 // Expect initialization to fail with timeout error
957- await expect ( retryWorkerManager . initialize ( ) ) . rejects . toThrow (
958- 'Pyodide initialization timed out after 300ms' ,
959- ) ;
928+ await expect ( retryWorkerManager . initialize ( ) ) . rejects . toThrow ( / P y o d i d e i n i t i a l i z a t i o n t i m e d o u t a f t e r 3 / ) ;
960929
961930 const totalTime = Date . now ( ) - startTime ;
962931
@@ -968,162 +937,6 @@ describe('PyodideWorkerManager', () => {
968937 expect ( attemptCount ) . toBeGreaterThan ( 1 ) ;
969938 expect ( attemptCount ) . toBeLessThan ( 11 ) ; // Should timeout before reaching max retries
970939 } ) ;
971-
972- test ( 'should work without totalTimeoutMs (backward compatibility)' , async ( ) => {
973- // Create a worker manager without totalTimeoutMs (uses default from DefaultSettings)
974- const retryWorkerManager = new PyodideWorkerManager (
975- {
976- maxRetries : 2 ,
977- initialDelayMs : 10 ,
978- maxDelayMs : 50 ,
979- backoffMultiplier : 2 ,
980- totalTimeoutMs : 120_000 , // Uses default value from DefaultSettings
981- } ,
982- createDefaultCfnLintSettings ( ) ,
983-
984- mockLogging ,
985- ) ;
986-
987- let attemptCount = 0 ;
988-
989- workerConstructor . mockImplementation ( ( ) => {
990- attemptCount ++ ;
991- throw new Error ( 'Worker creation failed' ) ;
992- } ) ;
993-
994- // Should fail after max retries, not timeout (since timeout is very large)
995- await expect ( retryWorkerManager . initialize ( ) ) . rejects . toThrow (
996- 'Pyodide initialization failed after 3 attempts. Last error: Worker creation failed' ,
997- ) ;
998-
999- // Should have made all retry attempts (initial + 2 retries = 3 total)
1000- expect ( attemptCount ) . toBe ( 3 ) ;
1001- } ) ;
1002-
1003- test ( 'should prefer explicit totalTimeoutMs over calculated timeout' , async ( ) => {
1004- // Create a worker manager where explicit totalTimeoutMs is much shorter than calculated timeout
1005- const retryWorkerManager = new PyodideWorkerManager (
1006- {
1007- maxRetries : 5 , // Would normally allow 6 attempts
1008- initialDelayMs : 100 ,
1009- maxDelayMs : 1000 , // Calculated timeout would be 1000 * 6 = 6000ms
1010- backoffMultiplier : 2 ,
1011- totalTimeoutMs : 200 , // But explicit timeout is only 200ms
1012- } ,
1013- createDefaultCfnLintSettings ( ) ,
1014-
1015- mockLogging ,
1016- ) ;
1017-
1018- const startTime = Date . now ( ) ;
1019- let attemptCount = 0 ;
1020-
1021- workerConstructor . mockImplementation ( ( ) => {
1022- attemptCount ++ ;
1023- throw new Error ( 'Worker creation failed' ) ;
1024- } ) ;
1025-
1026- // Should timeout quickly due to explicit totalTimeoutMs
1027- await expect ( retryWorkerManager . initialize ( ) ) . rejects . toThrow (
1028- 'Pyodide initialization timed out after 200ms' ,
1029- ) ;
1030-
1031- const totalTime = Date . now ( ) - startTime ;
1032-
1033- // Should respect the explicit 200ms timeout, not the calculated 6000ms
1034- // Allow more variance for CI environments
1035- expect ( totalTime ) . toBeGreaterThanOrEqual ( 180 ) ;
1036- expect ( totalTime ) . toBeLessThan ( 350 ) ;
1037-
1038- // Should have made fewer attempts due to quick timeout
1039- expect ( attemptCount ) . toBeLessThan ( 6 ) ; // Should not reach max retries
1040- } ) ;
1041-
1042- test ( 'should handle zero totalTimeoutMs (immediate timeout)' , async ( ) => {
1043- // Create a worker manager with zero totalTimeoutMs
1044- const retryWorkerManager = new PyodideWorkerManager (
1045- {
1046- maxRetries : 3 ,
1047- initialDelayMs : 100 ,
1048- maxDelayMs : 500 ,
1049- backoffMultiplier : 2 ,
1050- totalTimeoutMs : 0 , // Immediate timeout
1051- } ,
1052- createDefaultCfnLintSettings ( ) ,
1053-
1054- mockLogging ,
1055- ) ;
1056-
1057- let attemptCount = 0 ;
1058-
1059- workerConstructor . mockImplementation ( ( ) => {
1060- attemptCount ++ ;
1061- throw new Error ( 'Worker creation failed' ) ;
1062- } ) ;
1063-
1064- // Should timeout immediately after first attempt
1065- await expect ( retryWorkerManager . initialize ( ) ) . rejects . toThrow ( 'Pyodide initialization timed out after 0ms' ) ;
1066-
1067- // Should have made at least one attempt before timing out
1068- expect ( attemptCount ) . toBe ( 1 ) ;
1069- } ) ;
1070-
1071- test ( 'should handle very large totalTimeoutMs' , async ( ) => {
1072- // Create a worker manager with very large totalTimeoutMs
1073- const retryWorkerManager = new PyodideWorkerManager (
1074- {
1075- maxRetries : 2 ,
1076- initialDelayMs : 10 ,
1077- maxDelayMs : 50 ,
1078- backoffMultiplier : 2 ,
1079- totalTimeoutMs : 10000 , // Very large timeout (10 seconds)
1080- } ,
1081- createDefaultCfnLintSettings ( ) ,
1082-
1083- mockLogging ,
1084- ) ;
1085-
1086- let attemptCount = 0 ;
1087-
1088- workerConstructor . mockImplementation ( ( ) => {
1089- attemptCount ++ ;
1090- throw new Error ( 'Worker creation failed' ) ;
1091- } ) ;
1092-
1093- // Should fail due to max retries, not timeout
1094- await expect ( retryWorkerManager . initialize ( ) ) . rejects . toThrow (
1095- 'Pyodide initialization failed after 3 attempts. Last error: Worker creation failed' ,
1096- ) ;
1097-
1098- // Should have made all retry attempts
1099- expect ( attemptCount ) . toBe ( 3 ) ;
1100- } ) ;
1101-
1102- test ( 'should use default operation name in error messages' , async ( ) => {
1103- // Create a worker manager without specifying operation name
1104- const retryWorkerManager = new PyodideWorkerManager (
1105- {
1106- maxRetries : 1 ,
1107- initialDelayMs : 10 ,
1108- maxDelayMs : 100 ,
1109- backoffMultiplier : 2 ,
1110- totalTimeoutMs : 5000 ,
1111- } ,
1112- createDefaultCfnLintSettings ( ) ,
1113-
1114- mockLogging ,
1115- ) ;
1116-
1117- // Always fail worker creation
1118- workerConstructor . mockImplementation ( ( ) => {
1119- throw new Error ( 'Worker creation failed' ) ;
1120- } ) ;
1121-
1122- // Expect initialization to fail with default operation name
1123- await expect ( retryWorkerManager . initialize ( ) ) . rejects . toThrow (
1124- 'Pyodide initialization failed after 2 attempts. Last error: Worker creation failed' ,
1125- ) ;
1126- } ) ;
1127940 } ) ;
1128941
1129942 describe ( 'race conditions and edge cases' , ( ) => {
0 commit comments