File tree Expand file tree Collapse file tree
main/java/io/dapr/durabletask
test/java/io/dapr/durabletask Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1525,6 +1525,7 @@ private Duration getNextDelay() {
15251525 long seed = this .firstAttempt .toEpochMilli () + this .attemptNumber ;
15261526 double reduction = new Random (seed ).nextDouble () * jitterFactor ;
15271527 nextDelayInMillis = (long ) (nextDelayInMillis * (1.0 - reduction ));
1528+ nextDelayInMillis = Math .max (nextDelayInMillis , 1 );
15281529 }
15291530
15301531 return Duration .ofMillis (nextDelayInMillis );
Original file line number Diff line number Diff line change @@ -96,4 +96,24 @@ void zeroJitterLeavesDelayUnchanged() {
9696
9797 assertEquals (baseDelayMillis , reduced );
9898 }
99+
100+ /**
101+ * With jitterFactor=1.0 the delay must never drop below 1ms,
102+ * even when nextDouble() approaches 1.0.
103+ */
104+ @ Test
105+ void jitterWithMaxFactorNeverProducesZeroDelay () {
106+ long baseDelayMillis = 1L ; // smallest meaningful delay
107+ double jitterFactor = 1.0 ;
108+
109+ for (int seedOffset = 0 ; seedOffset < 1000 ; seedOffset ++) {
110+ long seed = seedOffset ;
111+ double reduction = new Random (seed ).nextDouble () * jitterFactor ;
112+ long reduced = (long ) (baseDelayMillis * (1.0 - reduction ));
113+ reduced = Math .max (reduced , 1 );
114+
115+ assertTrue (reduced >= 1 ,
116+ "Delay must be at least 1ms, but was " + reduced + " for seed " + seed );
117+ }
118+ }
99119}
You can’t perform that action at this time.
0 commit comments