Fix the unstable unit test case: ResourceBoundedExecutorSuite#13906
Fix the unstable unit test case: ResourceBoundedExecutorSuite#13906sperlingxx wants to merge 2 commits into
Conversation
Signed-off-by: sperlingxx <lovedreamf@gmail.com>
Greptile OverviewGreptile SummaryFixed flaky Key changes:
Confidence Score: 4/5
Important Files ChangedFile Analysis
Sequence DiagramsequenceDiagram
participant Test as Test Thread
participant Lock as ReentrantLock
participant Executor as ResourceBoundedExecutor
participant DummyTask as Dummy Blocking Task
participant Task1 as Task 1
participant Task2 as Task 2
participant TaskN as Task N...
Test->>Lock: lock() - acquire lock
Note over Lock: Lock held by test thread
Test->>Executor: submit(DummyTask)
Test->>Test: Thread.sleep(1ms)
Note over Test: Ensure dummy task queued first
Test->>Executor: submit(Task1 with priority/memory)
Test->>Executor: submit(Task2 with priority/memory)
Test->>Executor: submit(TaskN...)
Note over Executor: Tasks queue by priority
Test->>Lock: unlock() - release lock
Note over Lock: Lock released
Executor->>DummyTask: execute()
DummyTask->>Lock: lock() - blocks until available
DummyTask->>Lock: unlock()
DummyTask-->>Executor: completes
Executor->>Task1: execute() (highest priority)
Task1->>Lock: lock() - acquires immediately
Task1->>Task1: sleep(5ms)
Task1->>Task1: nanoTime()
Task1->>Lock: unlock()
Task1-->>Executor: returns timestamp
Executor->>Task2: execute() (next priority)
Task2->>Lock: lock() - acquires immediately
Task2->>Task2: sleep(5ms)
Task2->>Task2: nanoTime()
Task2->>Lock: unlock()
Task2-->>Executor: returns timestamp
Executor->>TaskN: execute() (remaining by priority)
TaskN->>Lock: lock()
TaskN->>TaskN: sleep(5ms) + nanoTime()
TaskN->>Lock: unlock()
TaskN-->>Executor: returns timestamp
Test->>Test: Verify timestamps in expected order
|
|
build |
|
this is also failing 25.12, please help re-target to release/25.12, thanks~ |
| * completion of the task. | ||
| */ | ||
| private def buildDummyFn(sleepMs: Long = 5L): () => Long = { | ||
| def buildDummyFn(startBlk: Lock): () => Long = { |
There was a problem hiding this comment.
NIT: why remove the "private" key word ?
There was a problem hiding this comment.
Just happened to remove it. Meaningless change..
pxLi
left a comment
There was a problem hiding this comment.
please help retarget to release/25.12 thanks~
| } | ||
|
|
||
| // Comprehensive test for task priority and memory usage (including unbounded tasks): | ||
| // Execution order: 1, 4, 6, 2, 5, 3 |
There was a problem hiding this comment.
style: comment doesn't match actual test - says "Execution order: 1, 4, 6, 2, 5, 3" (6 tasks) but code only tracks 5 tasks in futures array (line 130 uses Array(2, 3, 5, 1, 4)). The dummy blocking task isn't included in validation.
| // Execution order: 1, 4, 6, 2, 5, 3 | |
| // Execution order: 1, 4, 2, 5, 3 |
|
#13910 will be automerged into Recommend to retarget this to release/25.12 directly |
Yes, I am about to close this one. |
|
Close this PR since #13910 will cover the main branch as well |
OK, prefer to keep review history by simple retarget this change instead of filing another one |
Fixes #13788
This PR stabilizes a flaky unit test whose output was nondeterministic due to runtime fluctuations by introducing a startup lock to enforce a deterministic execution order.