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

Condition does not get evaluated correctly with small intervals #224

Closed
Oliver-CI opened this issue Nov 17, 2021 · 1 comment
Closed

Condition does not get evaluated correctly with small intervals #224

Oliver-CI opened this issue Nov 17, 2021 · 1 comment

Comments

@Oliver-CI
Copy link

Oliver-CI commented Nov 17, 2021

Condition does not get evaluated correctly with small intervals

We have some issues when waiting till certain event are sent to a Kafka broker when they happen in rapid succession.

here under a small example which reproduces the issue inconsistently.

version used:

        <dependency>
            <groupId>org.awaitility</groupId>
            <artifactId>awaitility</artifactId>
             <version>4.0.3</version>
        </dependency>
import java.time.Duration;
import java.util.List;

import org.awaitility.Awaitility;

class Scratch {
    public static void main(String[] args) {
        Awaitility.await()
                .atMost(Duration.ofMillis(10))
                .pollInterval(Duration.ofMillis(5))
                .until(() -> getRandomList().size() >= 1);
    }

    public static List<Integer> getRandomList() {
        return List.of(1);
    }

}

image

@jwk-dev
Copy link

jwk-dev commented Dec 3, 2021

Using version 4.1.1 the same can be reproduced with a JUnit testwhich runs multiple times and happens more often with smaller "atMost" duration.
E.g. on my computer for "atMost" of1 milliseconds Exception comes in about 70% of all runs, for 2msec about 5%, for 5 msec about 0.2%.

My test code:

import java.util.concurrent.TimeUnit;
import org.awaitility.Awaitility;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

@RunWith(Parameterized.class)
public class AwaitilityTest {

@Parameterized.Parameters
public static Object[][] hundredTimes() {
	return new Object[1000][0];
}

@Test
public void awaitilityTest() {
	Awaitility.await().atMost(5, TimeUnit.MILLISECONDS).pollInterval(500, TimeUnit.NANOSECONDS).until(() -> true);
}

}

Stack trace:

org.awaitility.core.ConditionTimeoutException: Condition with AwaitilityTest was not fulfilled within 5 milliseconds.
at org.awaitility.core.ConditionAwaiter.await(ConditionAwaiter.java:164)
at org.awaitility.core.CallableCondition.await(CallableCondition.java:78)
at org.awaitility.core.CallableCondition.await(CallableCondition.java:26)
at org.awaitility.core.ConditionFactory.until(ConditionFactory.java:939)
at org.awaitility.core.ConditionFactory.until(ConditionFactory.java:908)
at AwaitilityTest.awaitilityTest(AwaitilityTest.java:17)
[...]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants