Skip to content

Commit

Permalink
Remove sleep() from LightyModuleTest
Browse files Browse the repository at this point in the history
Remove sleeps() call from LightyModuleTest. Use blocking get() instead.

JIRA: LIGHTY-299
Signed-off-by: Ivan Hrasko <ivan.hrasko@pantheon.tech>
  • Loading branch information
ihrasko committed Oct 29, 2024
1 parent 0133223 commit 3d0ff81
Showing 1 changed file with 3 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void shutdownExecutor() {
@Test
public void testStartShutdown() throws Exception {
this.moduleUnderTest = getModuleUnderTest(getExecutorService());
startLightyModuleAndFailIfTimedOut();
this.moduleUnderTest.start().get(MAX_INIT_TIMEOUT, TimeUnit.MILLISECONDS);
Mockito.verify(executorService, Mockito.times(1)).execute(Mockito.any());
this.moduleUnderTest.shutdown(MAX_SHUTDOWN_TIMEOUT, TimeUnit.MILLISECONDS);
Mockito.verify(executorService, Mockito.times(2)).execute(Mockito.any());
Expand All @@ -71,18 +71,16 @@ public void testStartStop_whenAlreadyStartedStopped() throws Exception {
Assert.fail("Init timed out.", e);
}
Mockito.verify(executorService, Mockito.times(1)).execute(Mockito.any());
this.moduleUnderTest.shutdown();
this.moduleUnderTest.shutdown(MAX_SHUTDOWN_TIMEOUT, TimeUnit.MILLISECONDS);
Mockito.verify(executorService, Mockito.times(2)).execute(Mockito.any());
Thread.sleep(SLEEP_AFTER_SHUTDOWN_TIMEOUT);
this.moduleUnderTest.shutdown();
this.moduleUnderTest.shutdown(MAX_SHUTDOWN_TIMEOUT, TimeUnit.MILLISECONDS);
Mockito.verify(executorService, Mockito.times(2)).execute(Mockito.any());
}

@Test
public void testShutdown_before_start() throws Exception {
this.moduleUnderTest = getModuleUnderTest(getExecutorService());
this.moduleUnderTest.shutdown(MAX_SHUTDOWN_TIMEOUT, TimeUnit.MILLISECONDS);

Mockito.verify(executorService, Mockito.times(0)).execute(Mockito.any());
}

Expand Down Expand Up @@ -143,12 +141,4 @@ private Future<Boolean> startBlockingOnLightyModuleInterface() throws Interrupte
Thread.sleep(MAX_INIT_TIMEOUT);
return startFuture;
}

private void startLightyModuleAndFailIfTimedOut() throws ExecutionException, InterruptedException {
try {
this.moduleUnderTest.start().get(MAX_INIT_TIMEOUT, TimeUnit.MILLISECONDS);
} catch (TimeoutException e) {
Assert.fail("Init timed out.", e);
}
}
}

0 comments on commit 3d0ff81

Please sign in to comment.