@@ -26,6 +26,10 @@ interface ForkOptions {
2626 chaosEnabled : boolean ; // Enable network chaos
2727 chaosLevel : ChaosLevel ; // Chaos level (low, medium, high)
2828 streams : boolean ; // Enable message streams on all workers
29+ dbChaosEnabled : boolean ; // Enable database chaos
30+ dbLockTimeMin : number ; // Minimum DB lock duration in ms
31+ dbLockTimeMax : number ; // Maximum DB lock duration in ms
32+ dbLockInterval : number ; // How often to apply DB locks in ms
2933}
3034
3135function showHelp ( ) {
@@ -44,6 +48,10 @@ OPTIONS:
4448 --chaos-enabled Enable network chaos testing (requires --env local)
4549 --chaos-level <level> Chaos level: low, medium, high [default: medium]
4650 --streams Enable message streams on all workers [default: false]
51+ --db-chaos-enabled Enable database locking chaos [default: false]
52+ --db-lock-time-min <ms> Minimum DB lock duration in ms [default: 100]
53+ --db-lock-time-max <ms> Maximum DB lock duration in ms [default: 2000]
54+ --db-lock-interval <ms> How often to apply DB locks in ms [default: 15000]
4755 -h, --help Show this help message
4856
4957CHAOS LEVELS:
@@ -59,6 +67,8 @@ EXAMPLES:
5967 yarn fork --env local --chaos-enabled # Run with medium network chaos
6068 yarn fork --env local --chaos-enabled --chaos-level high # Run with high chaos
6169 yarn fork --streams # Run with message streams enabled
70+ yarn fork --db-chaos-enabled # Run with database locking chaos
71+ yarn fork --db-chaos-enabled --db-lock-time-min 500 --db-lock-time-max 3000 # Custom DB chaos timing
6272
6373For more information, see: forks/README.md
6474` ) ;
@@ -90,6 +100,10 @@ function runForkTest(options: ForkOptions): boolean {
90100 CHAOS_ENABLED : options . chaosEnabled ? "true" : "false" ,
91101 CHAOS_LEVEL : options . chaosLevel ,
92102 STREAMS_ENABLED : options . streams ? "true" : "false" ,
103+ DB_CHAOS_ENABLED : options . dbChaosEnabled ? "true" : "false" ,
104+ DB_LOCK_TIME_MIN : options . dbLockTimeMin . toString ( ) ,
105+ DB_LOCK_TIME_MAX : options . dbLockTimeMax . toString ( ) ,
106+ DB_LOCK_INTERVAL : options . dbLockInterval . toString ( ) ,
93107 } ,
94108 } ) ;
95109
@@ -134,6 +148,15 @@ function logForkMatrixParameters(options: ForkOptions): void {
134148 console . info ( ` interval: ${ preset . interval } ms` ) ;
135149 }
136150
151+ if ( options . dbChaosEnabled ) {
152+ console . info ( "\nDATABASE CHAOS PARAMETERS" ) ;
153+ console . info ( `dbChaosEnabled: true` ) ;
154+ console . info (
155+ ` lockDuration: ${ options . dbLockTimeMin } -${ options . dbLockTimeMax } ms` ,
156+ ) ;
157+ console . info ( ` interval: ${ options . dbLockInterval } ms` ) ;
158+ }
159+
137160 console . info ( "-" . repeat ( 60 ) + "\n" ) ;
138161}
139162
@@ -257,6 +280,10 @@ async function main() {
257280 chaosEnabled : false ,
258281 chaosLevel : "medium" ,
259282 streams : false ,
283+ dbChaosEnabled : false ,
284+ dbLockTimeMin : 100 ,
285+ dbLockTimeMax : 6000 ,
286+ dbLockInterval : 5000 ,
260287 } ;
261288
262289 // Parse arguments
@@ -328,6 +355,57 @@ async function main() {
328355 case "--streams" :
329356 options . streams = true ;
330357 break ;
358+ case "--db-chaos-enabled" :
359+ options . dbChaosEnabled = true ;
360+ break ;
361+ case "--db-lock-time-min" :
362+ if ( i + 1 < args . length ) {
363+ const value = parseInt ( args [ i + 1 ] , 10 ) ;
364+ if ( isNaN ( value ) || value < 0 ) {
365+ console . error ( "--db-lock-time-min must be a positive number" ) ;
366+ process . exit ( 1 ) ;
367+ }
368+ options . dbLockTimeMin = value ;
369+ i ++ ; // Skip next argument
370+ } else {
371+ console . error (
372+ "--db-lock-time-min flag requires a value (e.g., --db-lock-time-min 100)" ,
373+ ) ;
374+ process . exit ( 1 ) ;
375+ }
376+ break ;
377+ case "--db-lock-time-max" :
378+ if ( i + 1 < args . length ) {
379+ const value = parseInt ( args [ i + 1 ] , 10 ) ;
380+ if ( isNaN ( value ) || value < 0 ) {
381+ console . error ( "--db-lock-time-max must be a positive number" ) ;
382+ process . exit ( 1 ) ;
383+ }
384+ options . dbLockTimeMax = value ;
385+ i ++ ; // Skip next argument
386+ } else {
387+ console . error (
388+ "--db-lock-time-max flag requires a value (e.g., --db-lock-time-max 2000)" ,
389+ ) ;
390+ process . exit ( 1 ) ;
391+ }
392+ break ;
393+ case "--db-lock-interval" :
394+ if ( i + 1 < args . length ) {
395+ const value = parseInt ( args [ i + 1 ] , 10 ) ;
396+ if ( isNaN ( value ) || value < 0 ) {
397+ console . error ( "--db-lock-interval must be a positive number" ) ;
398+ process . exit ( 1 ) ;
399+ }
400+ options . dbLockInterval = value ;
401+ i ++ ; // Skip next argument
402+ } else {
403+ console . error (
404+ "--db-lock-interval flag requires a value (e.g., --db-lock-interval 15000)" ,
405+ ) ;
406+ process . exit ( 1 ) ;
407+ }
408+ break ;
331409 default :
332410 console . error ( `Unknown option: ${ arg } ` ) ;
333411 console . error ( "Use --help for usage information" ) ;
0 commit comments