@@ -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 testLeaderElectionLatch = 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,22 +233,19 @@ 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 ();
233237 leaderElectionWorker .submit (
234238 () -> {
235239 leaderElector .run (
236240 () -> {
237241 leadershipHistory .add ("start leading" );
238- testLeaderElectionLatch .countDown ();
239242 },
240243 () -> {
241244 leadershipHistory .add ("stop leading" );
242- testLeaderElectionLatch .countDown ();
243245 });
244246 });
245247
246- testLeaderElectionLatch .await (10 , SECONDS );
248+ testLeaderElectionLatch .await ();
247249
248250 assertHistory (
249251 electionHistory ,
@@ -274,7 +276,7 @@ private void assertHistory(List<String> history, String... expected) {
274276 }
275277 }
276278
277- @ Test
279+ @ Test ( timeout = 90 * 1000 )
278280 public void testLeaderElectionCaptureException () throws ApiException , InterruptedException {
279281 RuntimeException expectedException = new RuntimeException ("noxu" );
280282 AtomicReference <Throwable > actualException = new AtomicReference <>();
@@ -303,7 +305,7 @@ public void testLeaderElectionCaptureException() throws ApiException, Interrupte
303305 assertEquals (expectedException , actualException .get ().getCause ());
304306 }
305307
306- @ Test
308+ @ Test ( timeout = 90 * 1000 )
307309 public void testLeaderElectionReportLeaderOnStart () throws ApiException , InterruptedException {
308310 when (lock .identity ()).thenReturn ("foo1" );
309311 when (lock .get ())
@@ -356,7 +358,7 @@ public void testLeaderElectionReportLeaderOnStart() throws ApiException, Interru
356358 assertEquals ("foo3" , notifications .get (1 ));
357359 }
358360
359- @ Test
361+ @ Test ( timeout = 90 * 1000 )
360362 public void testLeaderElectionShouldReportLeaderItAcquiresOnStart ()
361363 throws ApiException , InterruptedException {
362364 when (lock .identity ()).thenReturn ("foo1" );
0 commit comments