Fix the unstable unit test case: ResourceBoundedExecutorSuite#13910
Conversation
Signed-off-by: sperlingxx <lovedreamf@gmail.com>
Greptile OverviewGreptile SummaryThis PR fixes a flaky unit test ( Key Changes:
Issues Found:
Confidence Score: 4/5
Important Files ChangedFile Analysis
Sequence DiagramsequenceDiagram
participant Test as Test Thread
participant Lock as ReentrantLock
participant Executor as ResourceBoundedExecutor
participant Queue as Task Queue
participant Worker as Worker Thread
Note over Test,Worker: Test Setup Phase
Test->>Lock: lock() - acquire startup lock
Test->>Executor: submit unbounded dummy task
Executor->>Queue: enqueue dummy task
Test->>Test: sleep(1ms) - ensure dummy task queued first
Note over Test,Worker: Task Submission Phase
loop For each priority task
Test->>Executor: submit task with priority
Executor->>Queue: enqueue task (sorted by priority)
end
Note over Queue: Tasks queued by priority<br/>but blocked by lock
Note over Test,Worker: Execution Phase
Test->>Lock: unlock() - release startup lock
Note over Worker: Worker can now start tasks
loop For each task in priority order
Worker->>Queue: dequeue highest priority task
Worker->>Lock: task attempts lock()
Lock->>Worker: grants lock
Worker->>Worker: sleep(5ms)
Worker->>Worker: capture System.nanoTime()
Worker->>Lock: unlock()
Worker->>Test: return timestamp via future
end
Note over Test: Verify timestamps are<br/>monotonically ordered<br/>per priority
|
| } | ||
|
|
||
| // 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.
syntax: Comment mentions task 6, but only 5 tasks are submitted (tasks 1-5). Should be "Execution order: 4, 1, 2, 5, 3"
| // Execution order: 1, 4, 6, 2, 5, 3 | |
| // Execution order: 4, 1, 2, 5, 3 |
| futures += executor.submit(AsyncRunner.newUnboundedTask(buildDummyFn())) | ||
| results = Array(1, 4, 6, 2, 5, 3).zip(futures).sortBy(_._1).map { | ||
| lck.unlock() // Allow tasks to start executing. | ||
| results = Array(2, 3, 5, 1, 4).zip(futures).sortBy(_._1).map { |
There was a problem hiding this comment.
NIT: missing 6 here compared to the original array.
There was a problem hiding this comment.
@firestarman , yes, since I changed the test sample as well. Currently, only 5 samples are included. Description was also updated.
Signed-off-by: sperlingxx <lovedreamf@gmail.com>
|
build |
|
LGTM, but we may improve this PR in a follow-up PR. I have the following concerns:
But the Maybe we can: |
Good idea! Thanks! |
Fixes #13788
Mirror PR of #13906, which enforces the fix on branch-25.12 as well.
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.