Fix flaky test in TestMemoryRevokingScheduler #24766
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR fix flaky test: TestMemoryRevokingScheduler.testTaskRevokingOrderForRevocableBytes.
The operation
LocalMemoryContext.setBytes(bytes)will triggerMemoryRevokingScheduler.onMemoryReserved(...), which will then try to request memory revoking asynchronously in thread poolmemoryRevocationExecutor.Considering this, the following code in this flaky test:
May have different sequences of actions:
Or:
Although the first scenario may occur in most cases because asynchronous calls take much longer than sequential execution, but we cannot rely on it. When the second scenario occur, the test will fail. To make it more apparent, we can simply add a
Thread.sleep(10)between the two lines.This PR figure out a way to ensure that there will definitely no memory revoking between the two memory reserving actions.
Motivation and Context
Fix: #24691
Impact
N/A
Test Plan
Thread.sleep(10)toThread.sleep(10000)between the two memory revoking lines intestTaskRevokingOrderForRevocableBytes, manually make sure that it works well.Contributor checklist
Release Notes
If release note is NOT required, use: