This is an automated email from the ASF dual-hosted git repository.

chrisdutz pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git


The following commit(s) were added to refs/heads/develop by this push:
     new 2e2900a648 fix: Hopefully made the new test less flaky.
2e2900a648 is described below

commit 2e2900a64857fec66772a3bd4d4662f18486dfa9
Author: Christofer Dutz <[email protected]>
AuthorDate: Thu Aug 13 20:12:30 2026 +0200

    fix: Hopefully made the new test less flaky.
---
 .../java/org/apache/plc4x/java/tools/eventpump/TagBatch.java | 12 ++++++++++++
 .../org/apache/plc4x/java/tools/eventpump/TagBatchTest.java  |  8 +++++++-
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git 
a/plc4j/tools/event-pump/src/main/java/org/apache/plc4x/java/tools/eventpump/TagBatch.java
 
b/plc4j/tools/event-pump/src/main/java/org/apache/plc4x/java/tools/eventpump/TagBatch.java
index fec1e70dc3..f359511e74 100644
--- 
a/plc4j/tools/event-pump/src/main/java/org/apache/plc4x/java/tools/eventpump/TagBatch.java
+++ 
b/plc4j/tools/event-pump/src/main/java/org/apache/plc4x/java/tools/eventpump/TagBatch.java
@@ -950,6 +950,18 @@ public class TagBatch implements AutoCloseable {
         return consecutiveFailures;
     }
 
+    /**
+     * Get the length of the current backoff window in milliseconds (for 
testing).
+     * <p>
+     * Unlike {@link #getNextAllowedFetchTimeMs()} this doesn't decay as time 
passes, so a test
+     * can assert on the window that was computed rather than on whatever is 
left of it.
+     *
+     * @return The current backoff window, or 0 if the batch isn't in backoff
+     */
+    long getCurrentBackoffMs() {
+        return currentBackoffMs;
+    }
+
     /**
      * Get the next allowed fetch time in millis (for testing).
      *
diff --git 
a/plc4j/tools/event-pump/src/test/java/org/apache/plc4x/java/tools/eventpump/TagBatchTest.java
 
b/plc4j/tools/event-pump/src/test/java/org/apache/plc4x/java/tools/eventpump/TagBatchTest.java
index b7be49686f..c791079732 100644
--- 
a/plc4j/tools/event-pump/src/test/java/org/apache/plc4x/java/tools/eventpump/TagBatchTest.java
+++ 
b/plc4j/tools/event-pump/src/test/java/org/apache/plc4x/java/tools/eventpump/TagBatchTest.java
@@ -95,8 +95,12 @@ class TagBatchTest {
 
         // Drive well past both failure counts where the old arithmetic broke 
(55 and 65).
         for (int failure = 1; failure <= 70; failure++) {
+            long beforeFetch = System.currentTimeMillis();
             batch.fetchTags();
-            long windowMs = batch.getNextAllowedFetchTimeMs() - 
System.currentTimeMillis();
+
+            // Assert on the window that was computed, not on what is left of 
it: with a window
+            // of a few milliseconds, the time spent logging the failure is 
enough to consume it.
+            long windowMs = batch.getCurrentBackoffMs();
 
             assertEquals(failure, batch.getConsecutiveFailures(),
                 "every attempt must be counted — a collapsed window would let 
extra ones through");
@@ -104,6 +108,8 @@ class TagBatchTest {
                 "backoff window must stay positive at failure " + failure + " 
(was " + windowMs + "ms)");
             assertTrue(windowMs <= maxBackoffMs,
                 "backoff window must stay capped at failure " + failure + " 
(was " + windowMs + "ms)");
+            assertTrue(batch.getNextAllowedFetchTimeMs() > beforeFetch,
+                "backoff must push the next attempt into the future at failure 
" + failure);
 
             // Wait out the window so the next attempt is actually made.
             Thread.sleep(maxBackoffMs + 1);

Reply via email to