@@ -46,7 +46,7 @@ public void setUp() {
4646
4747 @ Mock private Lock lock ;
4848
49- @ Test
49+ @ Test ( timeout = 90 * 1000 )
5050 public void testSimpleLeaderElection () throws InterruptedException {
5151 List <String > electionHistory = new ArrayList <>();
5252 List <String > leadershipHistory = new ArrayList <>();
@@ -89,13 +89,13 @@ record -> {
8989 });
9090 });
9191
92- testLeaderElectionLatch .await (10 , SECONDS );
92+ testLeaderElectionLatch .await ();
9393
9494 assertHistory (electionHistory , "create record" , "update record" , "update record" );
9595 assertHistory (leadershipHistory , "get leadership" , "start leading" , "stop leading" );
9696 }
9797
98- @ Test
98+ @ Test ( timeout = 90 * 1000 )
9999 public void testLeaderElection () throws InterruptedException {
100100 List <String > electionHistory = new ArrayList <>();
101101 List <String > leadershipHistory = new ArrayList <>();
@@ -161,7 +161,7 @@ record -> {
161161 });
162162 });
163163
164- lockAStopLeading .await (3 , SECONDS );
164+ lockAStopLeading .await ();
165165 leaderElectionWorker .submit (
166166 () -> {
167167 leaderElectorB .run (
@@ -196,29 +196,34 @@ record -> {
196196 "B stops leading" );
197197 }
198198
199- @ Test
199+ @ Test ( timeout = 90 * 1000 )
200200 public void testLeaderElectionWithRenewDeadline () throws InterruptedException {
201201 List <String > electionHistory = new ArrayList <>();
202202 List <String > leadershipHistory = new ArrayList <>();
203203
204+ CountDownLatch testElectionLatch = new CountDownLatch (9 );
204205 MockResourceLock mockLock = new MockResourceLock ("mock" );
205206 mockLock .renewCountMax = 3 ;
206207 mockLock .onCreate =
207208 record -> {
208209 electionHistory .add ("create record" );
209210 leadershipHistory .add ("get leadership" );
211+ testLeaderElectionLatch .countDown ();
210212 };
211213 mockLock .onUpdate =
212214 record -> {
213215 electionHistory .add ("update record" );
216+ testLeaderElectionLatch .countDown ();
214217 };
215218 mockLock .onChange =
216219 record -> {
217220 electionHistory .add ("change record" );
221+ testLeaderElectionLatch .countDown ();
218222 };
219223 mockLock .onTryUpdate =
220224 record -> {
221225 electionHistory .add ("try update record" );
226+ testLeaderElectionLatch .countDown ();
222227 };
223228
224229 LeaderElectionConfig leaderElectionConfig = new LeaderElectionConfig ();
@@ -228,23 +233,22 @@ record -> {
228233 leaderElectionConfig .setRenewDeadline (Duration .ofMillis (700 ));
229234 LeaderElector leaderElector = new LeaderElector (leaderElectionConfig );
230235
231- CountDownLatch testLeaderElectionLatch = new CountDownLatch (2 );
232236 ExecutorService leaderElectionWorker = Executors .newSingleThreadExecutor ();
237+ CountDownLatch testLeaderElectionLatch = new CountDownLatch (3 );
233238 leaderElectionWorker .submit (
234239 () -> {
235240 leaderElector .run (
236241 () -> {
237242 leadershipHistory .add ("start leading" );
238- testLeaderElectionLatch .countDown ();
243+ testElectionLatch .countDown ();
239244 },
240245 () -> {
241246 leadershipHistory .add ("stop leading" );
242- testLeaderElectionLatch .countDown ();
247+ testElectionLatch .countDown ();
243248 });
244249 });
245250
246- testLeaderElectionLatch .await (10 , SECONDS );
247-
251+ testElectionLatch .await ();
248252 assertHistory (
249253 electionHistory ,
250254 "create record" ,
@@ -256,6 +260,8 @@ record -> {
256260 "try update record" ,
257261 "try update record" ,
258262 "try update record" );
263+
264+ testLeaderElectionLatch .await ();
259265 assertHistory (leadershipHistory , "get leadership" , "start leading" , "stop leading" );
260266 }
261267
@@ -274,7 +280,7 @@ private void assertHistory(List<String> history, String... expected) {
274280 }
275281 }
276282
277- @ Test
283+ @ Test ( timeout = 90 * 1000 )
278284 public void testLeaderElectionCaptureException () throws ApiException , InterruptedException {
279285 RuntimeException expectedException = new RuntimeException ("noxu" );
280286 AtomicReference <Throwable > actualException = new AtomicReference <>();
@@ -303,7 +309,7 @@ public void testLeaderElectionCaptureException() throws ApiException, Interrupte
303309 assertEquals (expectedException , actualException .get ().getCause ());
304310 }
305311
306- @ Test
312+ @ Test ( timeout = 90 * 1000 )
307313 public void testLeaderElectionReportLeaderOnStart () throws ApiException , InterruptedException {
308314 when (lock .identity ()).thenReturn ("foo1" );
309315 when (lock .get ())
@@ -356,7 +362,7 @@ public void testLeaderElectionReportLeaderOnStart() throws ApiException, Interru
356362 assertEquals ("foo3" , notifications .get (1 ));
357363 }
358364
359- @ Test
365+ @ Test ( timeout = 90 * 1000 )
360366 public void testLeaderElectionShouldReportLeaderItAcquiresOnStart ()
361367 throws ApiException , InterruptedException {
362368 when (lock .identity ()).thenReturn ("foo1" );
0 commit comments