Repository navigation
fix: removing Thread.sleep() from KubernetesReconcilerCreatorTest - #4915
Conversation
|
/assign @brendandburns |
|
As with the other ones, please try to minimize the diff for easier reviewing. |
|
@brendandburns - Formatting changes in this are expected as I have enclosed the code in |
| @SpringBootTest(classes = {KubernetesReconcilerCreatorTest.App.class}) | ||
| class KubernetesReconcilerCreatorTest { | ||
|
|
||
| private static final Semaphore REQUEST_ENQUEUED = new Semaphore(0); |
There was a problem hiding this comment.
Please don't use globals that aren't constants in the test since it makes it impossible to run tests in parallel in the same JVM.
|
This change looks ok, except for the global Semaphore part, please switch that to be a test local semaphore instead. Also not sure why you added the shutdown (and thus the try/catch) it's not necessarily bad, but I'm not sure its needed. |
11235db to
669e4ae
Compare
669e4ae to
6990ce5
Compare
|
@brendandburns - Thanks for the feedback! You’re right, the static Semaphore was introducing shared global state, which isn't ideal for parallel test execution. |
|
I think that Awaitility just uses sleep under the hood (I'm not sure how it could do anything other than poll on that condition) so I'm not sure it really fixes this test. |
|
I was debating it with Gemini and here is the reasoning: |
|
Awaitlity is basically just while loop with a bunch of small sleeps. imho, using a semaphore or countdown latch is the right way to do this because it waits exactly the right amount of time.
Edited, we already have a dependency on that library, so I guess this is ok, I'd still prefer a synchronization primitive. |
|
/lgtm |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: brendandburns, sarveshkaushal The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
9d473c1
into
kubernetes-client:master
Notes
Replaces the fixed
Thread.sleep()inKubernetesReconcilerCreatorTestwith semaphore based synchronization.The custom work-queue key function releases a semaphore after adding the generated request to the controller work queue. The test waits for that signal before asserting on the queue.
This is related to issue #1223
Testing
Ran
mvn installon the project root.