Skip to content

test: replace Thread.sleep with sync primitives in tests#4639

Open
emmaeng700 wants to merge 3 commits intokubernetes-client:masterfrom
emmaeng700:fix/replace-thread-sleep-with-sync-primitives
Open

test: replace Thread.sleep with sync primitives in tests#4639
emmaeng700 wants to merge 3 commits intokubernetes-client:masterfrom
emmaeng700:fix/replace-thread-sleep-with-sync-primitives

Conversation

@emmaeng700
Copy link
Contributor

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.

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: emmaeng700
Once this PR has been reviewed and has the lgtm label, please assign yue9944882 for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Mar 6, 2026

CLA Signed

The committers listed above are authorized under a signed CLA.

@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Mar 6, 2026
emmaeng700 and others added 2 commits March 6, 2026 12:04
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>
@emmaeng700 emmaeng700 force-pushed the fix/replace-thread-sleep-with-sync-primitives branch from 54f8b58 to ebe9ea9 Compare March 6, 2026 18:04
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Mar 6, 2026
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>
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Mar 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants