Skip to content

Commit

Permalink
[modbus] itests: Fix testRefreshOnData (openhab#9668)
Browse files Browse the repository at this point in the history
* [modbus] itests: Fix testRefreshOnData

Resolves openhab#9617

Signed-off-by: Sami Salonen <[email protected]>

* [modbus] using default timeouts for waitForAssert

Signed-off-by: Sami Salonen <[email protected]>

* [modbus] mvn spotless:apply

Signed-off-by: Sami Salonen <[email protected]>
  • Loading branch information
ssalonen authored and thinkingstone committed Nov 7, 2021
1 parent d73f577 commit 3a0401f
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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());
}

/**
Expand Down

0 comments on commit 3a0401f

Please sign in to comment.