Skip to content

Commit

Permalink
Fix unstable MqttBrokerConnectionTests (openhab#1191)
Browse files Browse the repository at this point in the history
Using waitForAssert instead of sleeping 10ms makes the tests stable when the system has some load.

Fixes openhab#1139

Signed-off-by: Wouter Born <github@maindrain.net>
  • Loading branch information
wborn authored and kaikreuzer committed Nov 8, 2019
1 parent b006232 commit cd3f337
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 6 additions & 0 deletions bundles/org.openhab.core.io.transport.mqtt/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
<artifactId>org.openhab.core.config.core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.openhab.core.bundles</groupId>
<artifactId>org.openhab.core.test</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.eclipse.smarthome.io.transport.mqtt.internal.client.MqttAsyncClientWrapper;
import org.eclipse.smarthome.io.transport.mqtt.reconnect.AbstractReconnectStrategy;
import org.eclipse.smarthome.io.transport.mqtt.reconnect.PeriodicReconnectStrategy;
import org.eclipse.smarthome.test.java.JavaTest;
import org.junit.Test;
import org.osgi.service.cm.ConfigurationException;

Expand All @@ -43,7 +44,7 @@
* @author David Graeff - Initial contribution
* @author Jan N. Klug - adjusted to HiveMQ client
*/
public class MqttBrokerConnectionTests {
public class MqttBrokerConnectionTests extends JavaTest {
@Test
public void subscribeBeforeOnlineThenConnect()
throws ConfigurationException, MqttException, InterruptedException, ExecutionException, TimeoutException {
Expand Down Expand Up @@ -168,8 +169,7 @@ public void reconnectPolicy()

// Check lostConnect
verify(mockPolicy).lostConnection();
Thread.sleep(10);
verify(connection).start();
waitForAssert(() -> verify(connection).start());
assertTrue(mockPolicy.isReconnecting());

// Fake connection established
Expand Down

0 comments on commit cd3f337

Please sign in to comment.