Skip to content

Commit

Permalink
Increased timeout to fix build failure on slow GitHub build systems (#…
Browse files Browse the repository at this point in the history
…843)

Increase the timeout value in test client operations. Extracts it in a Duration type constant.
  • Loading branch information
hylkevds authored Jun 20, 2024
1 parent f222721 commit 718b4fa
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions broker/src/test/java/io/moquette/testclient/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@
*
* You may elect to redistribute this code under either of these licenses.
*/

package io.moquette.testclient;

import io.moquette.BrokerConstants;
import io.netty.bootstrap.Bootstrap;
import io.netty.buffer.ByteBuf;
import io.netty.channel.*;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
Expand Down Expand Up @@ -52,6 +50,9 @@ public interface ICallback {
}

private static final Logger LOG = LoggerFactory.getLogger(Client.class);

private static final Duration TIMEOUT_DURATION = Duration.ofMillis(300);

final ClientNettyMQTTHandler handler = new ClientNettyMQTTHandler();
EventLoopGroup workerGroup;
Channel m_channel;
Expand Down Expand Up @@ -195,7 +196,7 @@ public MqttSubAckMessage subscribe(String topic1, MqttQoS qos1, String topic2, M
.addSubscription(qos2, topic2)
.build();

return doSubscribeWithAckCasting(subscribeMessage, 200, TimeUnit.MILLISECONDS);
return doSubscribeWithAckCasting(subscribeMessage, TIMEOUT_DURATION.toMillis(), TimeUnit.MILLISECONDS);
}

public MqttSubAckMessage subscribe(String topic, MqttQoS qos) {
Expand All @@ -204,16 +205,16 @@ public MqttSubAckMessage subscribe(String topic, MqttQoS qos) {
.addSubscription(qos, topic)
.build();

return doSubscribeWithAckCasting(subscribeMessage, 200, TimeUnit.MILLISECONDS);
return doSubscribeWithAckCasting(subscribeMessage, TIMEOUT_DURATION.toMillis(), TimeUnit.MILLISECONDS);
}

public MqttSubAckMessage subscribeWithIdentifier(String topic, MqttQoS qos, int subscriptionIdentifier) {
return subscribeWithIdentifier(topic, qos, subscriptionIdentifier, 200, TimeUnit.MILLISECONDS);
return subscribeWithIdentifier(topic, qos, subscriptionIdentifier, TIMEOUT_DURATION.toMillis(), TimeUnit.MILLISECONDS);
}

@NotNull
public MqttSubAckMessage subscribeWithIdentifier(String topic, MqttQoS qos, int subscriptionIdentifier,
int timeout, TimeUnit timeUnit) {
long timeout, TimeUnit timeUnit) {
MqttProperties subProps = new MqttProperties();
subProps.add(new MqttProperties.IntegerProperty(
MqttProperties.MqttPropertyType.SUBSCRIPTION_IDENTIFIER.value(),
Expand All @@ -229,7 +230,7 @@ public MqttSubAckMessage subscribeWithIdentifier(String topic, MqttQoS qos, int
}

@NotNull
private MqttSubAckMessage doSubscribeWithAckCasting(MqttSubscribeMessage subscribeMessage, int timeout, TimeUnit timeUnit) {
private MqttSubAckMessage doSubscribeWithAckCasting(MqttSubscribeMessage subscribeMessage, long timeout, TimeUnit timeUnit) {
doSubscribe(subscribeMessage, timeout, timeUnit);

final MqttMessage subAckMessage = this.receivedMsg.get();
Expand All @@ -240,7 +241,7 @@ private MqttSubAckMessage doSubscribeWithAckCasting(MqttSubscribeMessage subscri
return (MqttSubAckMessage) subAckMessage;
}

private void doSubscribe(MqttSubscribeMessage subscribeMessage, int timeout, TimeUnit timeUnit) {
private void doSubscribe(MqttSubscribeMessage subscribeMessage, long timeout, TimeUnit timeUnit) {
final CountDownLatch subscribeAckLatch = new CountDownLatch(1);
this.setCallback(msg -> {
receivedMsg.getAndSet(msg);
Expand Down Expand Up @@ -300,7 +301,7 @@ public MqttMessage subscribeWithError(String topic, MqttQoS qos) {
.addSubscription(qos, topic)
.build();

doSubscribe(subscribeMessage, 200, TimeUnit.MILLISECONDS);
doSubscribe(subscribeMessage, TIMEOUT_DURATION.toMillis(), TimeUnit.MILLISECONDS);
return this.receivedMsg.get();
}

Expand Down

0 comments on commit 718b4fa

Please sign in to comment.