Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt to fix backoff testing issue #389

Merged
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@

class AbstractSourceTaskTest {

/**
* The amount of extra time that we will allow for timing errors.
*/
private static final long TIMING_DELTA = 250;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it is seconds, but can you may be rename the var TIMING_DELTA_MS or _SECS , and also javadocs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@muralibasani changed to TIMING_DELTA_MS


@Test
void timerTest() {
final AbstractSourceTask.Timer timer = new AbstractSourceTask.Timer(Duration.ofSeconds(1));
Expand Down Expand Up @@ -92,7 +97,8 @@ void backoffTest() throws InterruptedException {
backoff.delay();
stopWatch.stop();
assertThat(stopWatch.getTime()).as("Result without timer running")
.isBetween(estimatedDelay - backoff.getMaxJitter(), estimatedDelay + backoff.getMaxJitter());
.isBetween(estimatedDelay - backoff.getMaxJitter() - TIMING_DELTA,
estimatedDelay + backoff.getMaxJitter() + TIMING_DELTA);

timer.start();
for (int i = 0; i < 9; i++) {
Expand All @@ -109,8 +115,8 @@ void backoffTest() throws InterruptedException {
final int step = i;
if (!timer.isExpired()) {
assertThat(stopWatch.getTime()).as(() -> String.format("Result with timer running at step %s", step))
.isBetween(Duration.ofSeconds(1).toMillis() - backoff.getMaxJitter(),
Duration.ofSeconds(1).toMillis() + backoff.getMaxJitter());
.isBetween(Duration.ofSeconds(1).toMillis() - backoff.getMaxJitter() - TIMING_DELTA,
Duration.ofSeconds(1).toMillis() + backoff.getMaxJitter() + TIMING_DELTA);
}
}
}
Expand Down
Loading