@@ -46,8 +46,8 @@ public void testLeaderElectingController() throws ApiException, InterruptedExcep
4646 AtomicReference <LeaderElectionRecord > record = new AtomicReference <>();
4747 record .set (new LeaderElectionRecord ());
4848
49- Semaphore latch = new Semaphore (2 );
50- Semaphore controllerLatch = new Semaphore (2 );
49+ Semaphore apiClientSem = new Semaphore (0 );
50+ Semaphore controllerSem = new Semaphore (0 );
5151
5252 when (mockLock .identity ()).thenReturn ("foo" );
5353 when (mockLock .get ())
@@ -58,31 +58,31 @@ public void testLeaderElectingController() throws ApiException, InterruptedExcep
5858 doAnswer (
5959 invocationOnMock -> {
6060 record .set (invocationOnMock .getArgument (0 ));
61- latch .release ();
61+ apiClientSem .release ();
6262 return true ;
6363 })
6464 .when (mockLock )
6565 .create (any ());
6666
6767 doAnswer (
6868 invocationOnMock -> {
69- latch .release ();
69+ apiClientSem .release ();
7070 return false ;
7171 })
7272 .when (mockLock )
7373 .update (any ());
7474
7575 doAnswer (
7676 invocationOnMock -> {
77- controllerLatch .release ();
77+ controllerSem .release ();
7878 return null ;
7979 })
8080 .when (mockController )
8181 .run ();
8282
8383 doAnswer (
8484 invocationOnMock -> {
85- controllerLatch .release ();
85+ controllerSem .release ();
8686 return null ;
8787 })
8888 .when (mockController )
@@ -98,18 +98,15 @@ public void testLeaderElectingController() throws ApiException, InterruptedExcep
9898 Duration .ofMillis (100 ))),
9999 mockController );
100100
101- latch .acquire (2 );
102- controllerLatch .acquire (2 );
103-
104101 Thread controllerThread = new Thread (leaderElectingController ::run );
105102 controllerThread .start ();
106- latch .acquire (2 );
103+ apiClientSem .acquire (2 );
107104 controllerThread .interrupt ();
108105
109106 verify (mockLock , times (1 )).create (any ());
110107 verify (mockLock , atLeastOnce ()).update (any ());
111108
112- controllerLatch .acquire (2 );
109+ controllerSem .acquire (2 );
113110 verify (mockController , times (1 )).run ();
114111 verify (mockController , times (1 )).shutdown ();
115112 }
0 commit comments