Fix unstable MqttBrokerConnectionTests (#1191)

Using waitForAssert instead of sleeping 10ms makes the tests stable when the system has some load.

Fixes #1139

Signed-off-by: Wouter Born <github@maindrain.net>
pull/1193/head
Wouter Born 2019-11-08 10:53:13 +01:00 committed by Kai Kreuzer
parent b006232cc0
commit cd3f33738f
2 changed files with 9 additions and 3 deletions

View File

@ -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>

View File

@ -31,6 +31,7 @@ import org.eclipse.jdt.annotation.Nullable;
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;
@ -43,7 +44,7 @@ import com.hivemq.client.mqtt.mqtt3.message.publish.Mqtt3Publish;
* @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 {
@ -168,8 +169,7 @@ public class MqttBrokerConnectionTests {
// Check lostConnect
verify(mockPolicy).lostConnection();
Thread.sleep(10);
verify(connection).start();
waitForAssert(() -> verify(connection).start());
assertTrue(mockPolicy.isReconnecting());
// Fake connection established