Skip to content

Commit

Permalink
Increase timeout to account for slower machines. (openhab#7287)
Browse files Browse the repository at this point in the history
Signed-off-by: Connor Petty <[email protected]>
  • Loading branch information
cpmeister authored and markus7017 committed Sep 18, 2020
1 parent 04b24e5 commit b10c46b
Showing 1 changed file with 24 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
@RunWith(MockitoJUnitRunner.class)
public class BluetoothDiscoveryServiceTest {

private static final int TIMEOUT = 2000;

private final Logger logger = LoggerFactory.getLogger(BluetoothDiscoveryServiceTest.class);

private @NonNullByDefault({}) BluetoothDiscoveryService discoveryService;
Expand All @@ -86,7 +88,7 @@ public void ignoreDuplicateTest() {
// this second call should not produce another result
discoveryService.deviceDiscovered(device);

Mockito.verify(mockDiscoveryListener, Mockito.timeout(1000).times(1)).thingDiscovered(
Mockito.verify(mockDiscoveryListener, Mockito.timeout(TIMEOUT).times(1)).thingDiscovered(
ArgumentMatchers.same(discoveryService),
ArgumentMatchers.argThat(arg -> arg.getThingTypeUID().equals(participant1.typeUID)));
}
Expand All @@ -103,7 +105,7 @@ public void ignoreOtherDuplicateTest() {
// this should not produce another result
discoveryService.deviceDiscovered(device1);

Mockito.verify(mockDiscoveryListener, Mockito.timeout(1000).times(2)).thingDiscovered(
Mockito.verify(mockDiscoveryListener, Mockito.timeout(TIMEOUT).times(2)).thingDiscovered(
ArgumentMatchers.same(discoveryService),
ArgumentMatchers.argThat(arg -> arg.getThingTypeUID().equals(participant1.typeUID)));
}
Expand All @@ -117,7 +119,7 @@ public void ignoreRssiDuplicateTest() {
device.setRssi(100);
discoveryService.deviceDiscovered(device);

Mockito.verify(mockDiscoveryListener, Mockito.timeout(1000).times(1)).thingDiscovered(
Mockito.verify(mockDiscoveryListener, Mockito.timeout(TIMEOUT).times(1)).thingDiscovered(
ArgumentMatchers.same(discoveryService),
ArgumentMatchers.argThat(arg -> arg.getThingTypeUID().equals(participant1.typeUID)));
}
Expand All @@ -131,7 +133,7 @@ public void nonDuplicateNameTest() throws InterruptedException {
device.setName("sdfad");
discoveryService.deviceDiscovered(device);

Mockito.verify(mockDiscoveryListener, Mockito.timeout(1000).times(2)).thingDiscovered(
Mockito.verify(mockDiscoveryListener, Mockito.timeout(TIMEOUT).times(2)).thingDiscovered(
ArgumentMatchers.same(discoveryService),
ArgumentMatchers.argThat(arg -> arg.getThingTypeUID().equals(participant1.typeUID)));
}
Expand All @@ -145,7 +147,7 @@ public void nonDuplicateTxPowerTest() {
device.setTxPower(10);
discoveryService.deviceDiscovered(device);

Mockito.verify(mockDiscoveryListener, Mockito.timeout(1000).times(2)).thingDiscovered(
Mockito.verify(mockDiscoveryListener, Mockito.timeout(TIMEOUT).times(2)).thingDiscovered(
ArgumentMatchers.same(discoveryService),
ArgumentMatchers.argThat(arg -> arg.getThingTypeUID().equals(participant1.typeUID)));
}
Expand All @@ -159,7 +161,7 @@ public void nonDuplicateManufacturerIdTest() {
device.setManufacturerId(100);
discoveryService.deviceDiscovered(device);

Mockito.verify(mockDiscoveryListener, Mockito.timeout(1000).times(2)).thingDiscovered(
Mockito.verify(mockDiscoveryListener, Mockito.timeout(TIMEOUT).times(2)).thingDiscovered(
ArgumentMatchers.same(discoveryService),
ArgumentMatchers.argThat(arg -> arg.getThingTypeUID().equals(participant1.typeUID)));
}
Expand All @@ -174,7 +176,7 @@ public void useResultFromAnotherAdapterTest() {
discoveryService.deviceDiscovered(mockAdapter2.getDevice(address));

ArgumentCaptor<DiscoveryResult> resultCaptor = ArgumentCaptor.forClass(DiscoveryResult.class);
Mockito.verify(mockDiscoveryListener, Mockito.timeout(1000).times(2))
Mockito.verify(mockDiscoveryListener, Mockito.timeout(TIMEOUT).times(2))
.thingDiscovered(ArgumentMatchers.same(discoveryService), resultCaptor.capture());

List<DiscoveryResult> results = resultCaptor.getAllValues();
Expand Down Expand Up @@ -203,12 +205,12 @@ public void connectionParticipantTest() {

discoveryService.deviceDiscovered(device);

Mockito.verify(device, Mockito.timeout(1000).times(1)).connect();
Mockito.verify(device, Mockito.timeout(1000).times(1)).readCharacteristic(
Mockito.verify(device, Mockito.timeout(TIMEOUT).times(1)).connect();
Mockito.verify(device, Mockito.timeout(TIMEOUT).times(1)).readCharacteristic(
ArgumentMatchers.argThat(ch -> ch.getGattCharacteristic() == GattCharacteristic.DEVICE_NAME));
Mockito.verify(device, Mockito.timeout(1000).times(1)).disconnect();
Mockito.verify(device, Mockito.timeout(TIMEOUT).times(1)).disconnect();

Mockito.verify(mockDiscoveryListener, Mockito.timeout(1000).times(1)).thingDiscovered(
Mockito.verify(mockDiscoveryListener, Mockito.timeout(TIMEOUT).times(1)).thingDiscovered(
ArgumentMatchers.same(discoveryService),
ArgumentMatchers.argThat(arg -> arg.getThingTypeUID().equals(participant1.typeUID)
&& arg.getThingUID().getId().equals(deviceName)));
Expand All @@ -232,7 +234,7 @@ public void multiDiscoverySingleConnectionTest() {

discoveryService.deviceDiscovered(device1);

Mockito.verify(mockDiscoveryListener, Mockito.timeout(1000).times(1)).thingDiscovered(
Mockito.verify(mockDiscoveryListener, Mockito.timeout(TIMEOUT).times(1)).thingDiscovered(
ArgumentMatchers.same(discoveryService),
ArgumentMatchers.argThat(arg -> arg.getThingTypeUID().equals(participant1.typeUID)
&& mockAdapter1.getUID().equals(arg.getBridgeUID())
Expand All @@ -245,7 +247,7 @@ public void multiDiscoverySingleConnectionTest() {

discoveryService.deviceDiscovered(device2);

Mockito.verify(mockDiscoveryListener, Mockito.timeout(1000).times(1)).thingDiscovered(
Mockito.verify(mockDiscoveryListener, Mockito.timeout(TIMEOUT).times(1)).thingDiscovered(
ArgumentMatchers.same(discoveryService),
ArgumentMatchers.argThat(arg -> arg.getThingTypeUID().equals(participant1.typeUID)
&& mockAdapter2.getUID().equals(arg.getBridgeUID())
Expand All @@ -268,7 +270,7 @@ public void nonConnectionParticipantTest() {

discoveryService.deviceDiscovered(device);

Mockito.verify(mockDiscoveryListener, Mockito.timeout(1000).times(1)).thingDiscovered(
Mockito.verify(mockDiscoveryListener, Mockito.timeout(TIMEOUT).times(1)).thingDiscovered(
ArgumentMatchers.same(discoveryService),
ArgumentMatchers.argThat(arg -> arg.getThingTypeUID().equals(participant1.typeUID)
&& !arg.getThingUID().getId().equals(deviceName)));
Expand All @@ -285,7 +287,7 @@ public void defaultResultTest() {
BluetoothDevice device = mockAdapter1.getDevice(TestUtils.randomAddress());
discoveryService.deviceDiscovered(device);

Mockito.verify(mockDiscoveryListener, Mockito.timeout(1000).times(1))
Mockito.verify(mockDiscoveryListener, Mockito.timeout(TIMEOUT).times(1))
.thingDiscovered(ArgumentMatchers.same(discoveryService), ArgumentMatchers
.argThat(arg -> arg.getThingTypeUID().equals(BluetoothBindingConstants.THING_TYPE_BEACON)));
}
Expand All @@ -298,7 +300,7 @@ public void removeDefaultDeviceTest() {
discoveryService.deviceDiscovered(device);
discoveryService.deviceRemoved(device);

Mockito.verify(mockDiscoveryListener, Mockito.timeout(1000).times(1))
Mockito.verify(mockDiscoveryListener, Mockito.timeout(TIMEOUT).times(1))
.thingRemoved(ArgumentMatchers.same(discoveryService), ArgumentMatchers
.argThat(arg -> arg.getThingTypeUID().equals(BluetoothBindingConstants.THING_TYPE_BEACON)));
}
Expand All @@ -313,7 +315,7 @@ public void removeUpdatedDefaultDeviceTest() {
discoveryService.deviceDiscovered(device);

discoveryService.deviceRemoved(device);
Mockito.verify(mockDiscoveryListener, Mockito.timeout(1000).times(1))
Mockito.verify(mockDiscoveryListener, Mockito.timeout(TIMEOUT).times(1))
.thingRemoved(ArgumentMatchers.same(discoveryService), ArgumentMatchers
.argThat(arg -> arg.getThingTypeUID().equals(BluetoothBindingConstants.THING_TYPE_BEACON)));
}
Expand All @@ -326,7 +328,7 @@ public void bluezConnectionTimeoutTest() {
BadConnectionDevice device = new BadConnectionDevice(mockAdapter1, TestUtils.randomAddress(), 100);
discoveryService.deviceDiscovered(device);

Mockito.verify(mockDiscoveryListener, Mockito.timeout(1000).times(1))
Mockito.verify(mockDiscoveryListener, Mockito.timeout(TIMEOUT).times(1))
.thingDiscovered(ArgumentMatchers.same(discoveryService), ArgumentMatchers
.argThat(arg -> arg.getThingTypeUID().equals(BluetoothBindingConstants.THING_TYPE_BEACON)));
}
Expand Down Expand Up @@ -355,7 +357,7 @@ public void replaceOlderDiscoveryTest() {
// lets start with producing a default result
discoveryService.deviceDiscovered(device);

Mockito.verify(mockDiscoveryListener, Mockito.timeout(1000).times(1))
Mockito.verify(mockDiscoveryListener, Mockito.timeout(TIMEOUT).times(1))
.thingDiscovered(ArgumentMatchers.same(discoveryService), ArgumentMatchers
.argThat(arg -> arg.getThingTypeUID().equals(BluetoothBindingConstants.THING_TYPE_BEACON)));

Expand All @@ -364,11 +366,11 @@ public void replaceOlderDiscoveryTest() {
// lets start with producing a default result
discoveryService.deviceDiscovered(device);

Mockito.verify(mockDiscoveryListener, Mockito.timeout(1000).times(1))
Mockito.verify(mockDiscoveryListener, Mockito.timeout(TIMEOUT).times(1))
.thingRemoved(ArgumentMatchers.same(discoveryService), ArgumentMatchers
.argThat(arg -> arg.getThingTypeUID().equals(BluetoothBindingConstants.THING_TYPE_BEACON)));

Mockito.verify(mockDiscoveryListener, Mockito.timeout(1000).times(1)).thingDiscovered(
Mockito.verify(mockDiscoveryListener, Mockito.timeout(TIMEOUT).times(1)).thingDiscovered(
ArgumentMatchers.same(discoveryService),
ArgumentMatchers.argThat(arg -> arg.getThingTypeUID().equals(participant2.typeUID)));
}
Expand Down Expand Up @@ -421,7 +423,7 @@ public void recursiveFutureTest() throws InterruptedException {

pauseLatch.countDown();

Mockito.verify(mockDiscoveryListener, Mockito.timeout(1000).times(2)).thingDiscovered(
Mockito.verify(mockDiscoveryListener, Mockito.timeout(TIMEOUT).times(2)).thingDiscovered(
ArgumentMatchers.same(discoveryService),
ArgumentMatchers.argThat(arg -> arg.getThingTypeUID().equals(participant2.typeUID)));

Expand Down

0 comments on commit b10c46b

Please sign in to comment.