test: replace Thread.sleep with sync primitives in tests#4639
Open
emmaeng700 wants to merge 3 commits intokubernetes-client:masterfrom
Open
test: replace Thread.sleep with sync primitives in tests#4639emmaeng700 wants to merge 3 commits intokubernetes-client:masterfrom
emmaeng700 wants to merge 3 commits intokubernetes-client:masterfrom
Conversation
Contributor
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: emmaeng700 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Replace flaky Thread.sleep calls with proper synchronization: - SharedProcessorTest: use Semaphore(0).acquire() instead of Thread.sleep(10s) so the worker blocks until interrupted by shutdownNow(), making the test deterministic and instant. - KubernetesReconcilerCreatorTest: use Wait.poll() instead of Thread.sleep(500ms) to actively poll until the work queue is populated, making the test faster and non-flaky. Addresses part of kubernetes-client#1223. Co-Authored-By: Oz <oz-agent@warp.dev>
Co-Authored-By: Oz <oz-agent@warp.dev>
54f8b58 to
ebe9ea9
Compare
Address the remaining Thread.sleep usages from kubernetes-client#1223: - ExecCallbacksTest: replace Thread.sleep(30s) with Semaphore(0).acquire() so the simulated remote process blocks until the exec timeout fires, making the test instant and non-flaky. - CopyTest: replace Thread.sleep(2000) with Awaitility.await() polling WireMock's serve events, so we proceed as soon as the HTTP request is received rather than waiting a fixed 2 seconds. - PortForwardTest: remove Thread.sleep(2000) entirely; handler.close() is called while the main thread holds the monitor lock, so there is no race condition and no need for a timed wait. - DefaultDelayingQueueTest: remove Thread.sleep(10s) after queue.done(); the queue uses an injected (static) time source, so no items will be spontaneously enqueued and the assertion can be made immediately. - DefaultWorkQueueTest: remove Thread.sleep calls used to simulate producer/consumer work; the test correctness is governed by CountDownLatches, not by sleep timing. - EventCorrelatorTest: replace Thread.sleep(100) with an explicit timestamp offset (plusMillis(100)) so event timestamps are guaranteed to differ without any real-time wait. Co-Authored-By: Oz <oz-agent@warp.dev>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Replace flaky Thread.sleep calls with proper synchronization:
SharedProcessorTest: use Semaphore(0).acquire() instead of Thread.sleep(10s) so the worker blocks until interrupted by shutdownNow(), making the test deterministic and instant.
KubernetesReconcilerCreatorTest: use Wait.poll() instead of Thread.sleep(500ms) to actively poll until the work queue is populated, making the test faster and non-flaky.
Addresses part of #1223.