Skip to content

[BUG] HeapBasedRateTrackerTest are unreliable #2193

@peternied

Description

@peternied

What is the bug?
The tests in HeapBasedRateTrackerTest [1] expect behavior based on elapsed time vs System.currentTimeMillis() [2]. During test execution there is no guarantee that Thread.Sleep(...) times are anywhere near expected. This tests are unreliable as has been seen when attempting to onboard MacOS and Windows platforms.

How can one reproduce the bug?
Running the following command on a resource constrained machine many times until the tests fail
./gradlew test --tests org.opensearch.security.auth.limiting.HeapBasedRateTrackerTest

How should this be fixed?
The way time is calculated show be supplied by a TimeProvider that can be mocked during unit tests for reliability

[1] https://github.com/opensearch-project/security/blob/main/src/test/java/org/opensearch/security/auth/limiting/HeapBasedRateTrackerTest.java#L27
[2] https://github.com/opensearch-project/security/blob/main/src/main/java/org/opensearch/security/util/ratetracking/HeapBasedRateTracker.java#L88

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingflaky-testFlaky Test issuegood first issueThese are recommended starting points for newcomers looking to make their first contributions.triagedIssues labeled as 'Triaged' have been reviewed and are deemed actionable.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions