Skip to content

Commit eb9b507

Browse files
committed
test: fix intermittent failures
Update assertions and assert message in ChangesFollowerTest testStart and testStop to validate 2 batches received.
1 parent ccd988f commit eb9b507

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

modules/cloudant/src/test/java/com/ibm/cloud/cloudant/features/ChangesFollowerTest.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* © Copyright IBM Corporation 2022, 2023. All Rights Reserved.
2+
* © Copyright IBM Corporation 2022, 2025. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
55
* the License. You may obtain a copy of the License at
@@ -366,8 +366,10 @@ void testStart() {
366366
try {
367367
// Run for 5 seconds against an infinite stream
368368
long count = testFollowerOnThread(testFollower, ChangesFollower.Mode.LISTEN, false, Duration.ofSeconds(5L));
369-
// Even on a slow test machine we should at least get into the third batch, but hard to predict total changes
370-
Assert.assertTrue(count > 2*ChangesFollower.BATCH_SIZE + 1, "There should be some changes.");
369+
// Even on a slow test machine we should at least get two batches, but hard to predict total changes
370+
long expectedMinChanges = 2 * ChangesFollower.BATCH_SIZE;
371+
Assert.assertTrue(count >= expectedMinChanges,
372+
String.format("Expected at least %d changes, but found only %d.", expectedMinChanges, count));
371373
} catch(Exception e) {
372374
Assert.fail("There should be no exception.", e);
373375
}
@@ -470,8 +472,10 @@ void testStop() {
470472
try {
471473
// Run for 5 seconds against an infinite stream
472474
long count = testFollowerOnThread(testFollower, ChangesFollower.Mode.FINITE, false, Duration.ofSeconds(5L));
473-
// Even on a slow test machine we should at least get into the third batch, but hard to predict total changes
474-
Assert.assertTrue(count > 2*ChangesFollower.BATCH_SIZE + 1, "There should be some changes.");
475+
// Even on a slow test machine we should at least get two batches, but hard to predict total changes
476+
long expectedMinChanges = 2 * ChangesFollower.BATCH_SIZE;
477+
Assert.assertTrue(count >= expectedMinChanges,
478+
String.format("Expected at least %d changes, but found only %d.", expectedMinChanges, count));
475479
} catch(Exception e) {
476480
Assert.fail("There should be no exception.", e);
477481
}

0 commit comments

Comments
 (0)