From aa1c9bbb78dccad5e067206f7de9be71b9296dc5 Mon Sep 17 00:00:00 2001 From: Sami Salonen Date: Wed, 6 Jan 2021 23:15:38 +0200 Subject: [PATCH] [modbus] itests: Fix testRefreshOnData (#9668) * [modbus] itests: Fix testRefreshOnData Resolves #9617 Signed-off-by: Sami Salonen * [modbus] using default timeouts for waitForAssert Signed-off-by: Sami Salonen * [modbus] mvn spotless:apply Signed-off-by: Sami Salonen --- .../binding/modbus/tests/ModbusDataHandlerTest.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/itests/org.openhab.binding.modbus.tests/src/main/java/org/openhab/binding/modbus/tests/ModbusDataHandlerTest.java b/itests/org.openhab.binding.modbus.tests/src/main/java/org/openhab/binding/modbus/tests/ModbusDataHandlerTest.java index e87ceb3aed134..ac2004311acff 100644 --- a/itests/org.openhab.binding.modbus.tests/src/main/java/org/openhab/binding/modbus/tests/ModbusDataHandlerTest.java +++ b/itests/org.openhab.binding.modbus.tests/src/main/java/org/openhab/binding/modbus/tests/ModbusDataHandlerTest.java @@ -34,7 +34,6 @@ import org.apache.commons.lang.StringUtils; import org.hamcrest.Matcher; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.openhab.binding.modbus.handler.EndpointNotInitializedException; @@ -767,7 +766,6 @@ public void testDiscreteInputAcceptsBitValueType() { } @Test - @Disabled("See: https://github.com/openhab/openhab-addons/issues/9617") public void testRefreshOnData() throws InterruptedException { ModbusReadFunctionCode functionCode = ModbusReadFunctionCode.READ_COILS; @@ -798,13 +796,20 @@ public void testRefreshOnData() throws InterruptedException { assertThat(dataHandler.getThing().getStatus(), is(equalTo(ThingStatus.ONLINE))); verify(comms, never()).submitOneTimePoll(eq(request), notNull(), notNull()); - // Reset initial REFRESH commands to data thing channels from the Core + ModbusPollerThingHandler handler = (ModbusPollerThingHandler) poller.getHandler(); + // Wait for all channels to receive the REFRESH command (initiated by the core) + waitForAssert( + () -> verify((ModbusPollerThingHandler) poller.getHandler(), times(CHANNEL_TO_ACCEPTED_TYPE.size())) + .refresh()); + // Reset the mock reset(poller.getHandler()); + + // Issue REFRESH command and verify the results dataHandler.handleCommand(Mockito.mock(ChannelUID.class), RefreshType.REFRESH); // data handler asynchronously calls the poller.refresh() -- it might take some time // We check that refresh is finally called - waitForAssert(() -> verify((ModbusPollerThingHandler) poller.getHandler()).refresh(), 2500, 50); + waitForAssert(() -> verify((ModbusPollerThingHandler) poller.getHandler()).refresh()); } /**