mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-13 08:55:44 +01:00
try to fix flappy unit tests, by using awaitility instead of Thread.sleep
This commit is contained in:
7
pom.xml
7
pom.xml
@@ -362,6 +362,13 @@
|
|||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.awaitility</groupId>
|
||||||
|
<artifactId>awaitility</artifactId>
|
||||||
|
<version>4.0.2</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- http -->
|
<!-- http -->
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
@@ -353,6 +353,12 @@
|
|||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.awaitility</groupId>
|
||||||
|
<artifactId>awaitility</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>sonia.scm.plugins</groupId>
|
<groupId>sonia.scm.plugins</groupId>
|
||||||
<artifactId>scm-git-plugin</artifactId>
|
<artifactId>scm-git-plugin</artifactId>
|
||||||
|
|||||||
@@ -9,7 +9,10 @@ import org.mockito.junit.jupiter.MockitoExtension;
|
|||||||
import sonia.scm.event.RecreateEventBusEvent;
|
import sonia.scm.event.RecreateEventBusEvent;
|
||||||
import sonia.scm.event.ScmEventBus;
|
import sonia.scm.event.ScmEventBus;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.awaitility.Awaitility.await;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
@ExtendWith(MockitoExtension.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
@@ -28,12 +31,11 @@ class InjectionContextRestartStrategyTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void shouldCallDestroyAndInitialize() throws InterruptedException {
|
void shouldCallDestroyAndInitialize() {
|
||||||
strategy.restart(context);
|
TestingInjectionContext ctx = new TestingInjectionContext();
|
||||||
|
strategy.restart(ctx);
|
||||||
verify(context).destroy();
|
await().atMost(1, TimeUnit.SECONDS).untilAsserted(() -> assertThat(ctx.destroyed).isTrue());
|
||||||
Thread.sleep(50L);
|
await().atMost(1, TimeUnit.SECONDS).untilAsserted(() -> assertThat(ctx.initialized).isTrue());
|
||||||
verify(context).initialize();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -51,6 +53,7 @@ class InjectionContextRestartStrategyTest {
|
|||||||
TestingInjectionContext ctx = new TestingInjectionContext();
|
TestingInjectionContext ctx = new TestingInjectionContext();
|
||||||
strategy.restart(ctx);
|
strategy.restart(ctx);
|
||||||
|
|
||||||
|
await().atMost(1, TimeUnit.SECONDS).until(() -> ctx.initialized);
|
||||||
Thread.sleep(50L);
|
Thread.sleep(50L);
|
||||||
ScmEventBus.getInstance().post("hello event");
|
ScmEventBus.getInstance().post("hello event");
|
||||||
|
|
||||||
@@ -70,6 +73,8 @@ class InjectionContextRestartStrategyTest {
|
|||||||
public static class TestingInjectionContext implements RestartStrategy.InjectionContext {
|
public static class TestingInjectionContext implements RestartStrategy.InjectionContext {
|
||||||
|
|
||||||
private volatile String event;
|
private volatile String event;
|
||||||
|
private boolean initialized = false;
|
||||||
|
private boolean destroyed = false;
|
||||||
|
|
||||||
@Subscribe(async = false)
|
@Subscribe(async = false)
|
||||||
public void setEvent(String event) {
|
public void setEvent(String event) {
|
||||||
@@ -78,12 +83,12 @@ class InjectionContextRestartStrategyTest {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
|
this.initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void destroy() {
|
public void destroy() {
|
||||||
|
this.destroyed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user