Skip to content

Commit 450ec89

Browse files
bretambroseBret Ambrosesfod
authored
Why didn't the submodule check catch this? (#900)
Co-authored-by: Bret Ambrose <bambrose@amazon.com> Co-authored-by: Igor Abdrakhimov <octosyllabic@gmail.com>
1 parent 99afdde commit 450ec89

4 files changed

Lines changed: 24 additions & 9 deletions

File tree

src/test/java/software/amazon/awssdk/crt/test/Mqtt5ClientTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,7 +1207,7 @@ private void doConnNegativeID_UC7Test() {
12071207
clientOne.start();
12081208
eventsOne.connectedFuture.get(OPERATION_TIMEOUT_TIME, TimeUnit.SECONDS);
12091209

1210-
Thread.sleep(2000); // Sleep for 2 seconds to not hit IoT Core limits
1210+
TestUtils.sleepForAtLeastMilliseconds(2000); // Sleep for 2 seconds to not hit IoT Core limits
12111211

12121212
clientTwo.start();
12131213
eventsTwo.connectedFuture.get(OPERATION_TIMEOUT_TIME, TimeUnit.SECONDS);
@@ -1732,7 +1732,7 @@ private void doNegotiated_Rejoin_AlwaysTest() {
17321732
}
17331733

17341734
/* Avoid accidentally triggering re-connect throttle */
1735-
Thread.sleep(2000);
1735+
TestUtils.sleepForAtLeastMilliseconds(2000);
17361736

17371737
builder.withSessionBehavior(ClientSessionBehavior.REJOIN_ALWAYS);
17381738
LifecycleEvents_Futured rejoinEvents = new LifecycleEvents_Futured();
@@ -1990,7 +1990,7 @@ private void doOp_UC4Test() {
19901990
subscriber.subscribe(subscribePacketBuilder.build()).get(OPERATION_TIMEOUT_TIME, TimeUnit.SECONDS);
19911991

19921992
// Paranoid about service-side eventual consistency. Add a wait to reduce chances of a missed will publish.
1993-
Thread.sleep(2000);
1993+
TestUtils.sleepForAtLeastMilliseconds(2000);
19941994

19951995
publisher.stop(disconnectPacketBuilder.build());
19961996

@@ -2069,7 +2069,7 @@ private void doOp_SharedSubscriptionTest() {
20692069
subscriberOneClient.subscribe(subscribePacketBuilder.build()).get(OPERATION_TIMEOUT_TIME, TimeUnit.SECONDS);
20702070
subscriberTwoClient.subscribe(subscribePacketBuilder.build()).get(OPERATION_TIMEOUT_TIME, TimeUnit.SECONDS);
20712071

2072-
Thread.sleep(4000);
2072+
TestUtils.sleepForAtLeastMilliseconds(4000);
20732073

20742074
for (int i = 0; i < messageCount; ++i) {
20752075
publishPacketBuilder.withPayload(String.valueOf(i).getBytes());
@@ -2457,7 +2457,7 @@ private void doRetain_UC1Test() {
24572457
publisher.publish(publishPacketBuilder.build()).get(OPERATION_TIMEOUT_TIME, TimeUnit.SECONDS);
24582458

24592459
// Wait 15 seconds to give the server time to clear everything out
2460-
Thread.sleep(15000);
2460+
TestUtils.sleepForAtLeastMilliseconds(15000);
24612461

24622462
// Connect the unsuccessful subscriber
24632463
unsuccessfulSubscriber.start();

src/test/java/software/amazon/awssdk/crt/test/Mqtt5ClientTestFixture.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ public void onConnectionSuccess(Mqtt5Client client, OnConnectionSuccessReturn on
134134
public void onConnectionFailure(Mqtt5Client client, OnConnectionFailureReturn onConnectionFailureReturn) {
135135
connectFailureCode = onConnectionFailureReturn.getErrorCode();
136136
connectFailurePacket = onConnectionFailureReturn.getConnAckPacket();
137-
connectedFuture.completeExceptionally(new Exception("Could not connect! Error name: " + CRT.awsErrorName(connectFailureCode)));
137+
connectedFuture.completeExceptionally(new Exception("Could not connect! Error name: "
138+
+ CRT.awsErrorName(connectFailureCode) + " (" + CRT.awsErrorString(connectFailureCode) + ")"));
138139
}
139140

140141
@Override

src/test/java/software/amazon/awssdk/crt/test/MqttRequestResponseClientTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ static private MqttClientConnection createMqtt311Client() {
203203
}
204204

205205
try {
206-
Thread.sleep(RETRY_DELAY_MILLIS);
206+
TestUtils.sleepForAtLeastMilliseconds(RETRY_DELAY_MILLIS);
207207
} catch (Exception e) {
208208
; // don't care
209209
}

src/test/java/software/amazon/awssdk/crt/test/TestUtils.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,28 @@ static public void doRetryableTest(Runnable testFunction, Function<Exception, Bo
2424
}
2525
}
2626

27-
Thread.sleep(sleepTimeMillis);
27+
sleepForAtLeastMilliseconds(sleepTimeMillis);
2828
}
2929

3030
throw new Exception("Retryable network test exceeded the maximum allowed attempts without succeeding");
3131
}
3232

3333
static public Boolean isRetryableTimeout(Exception ex) {
3434
String exceptionMsg = ex.toString();
35-
return exceptionMsg.contains("socket operation timed out") || exceptionMsg.contains("tls negotiation timeout");
35+
return exceptionMsg.contains("socket operation timed out") ||
36+
exceptionMsg.contains("tls negotiation timeout") ||
37+
exceptionMsg.contains("socket connection refused");
38+
}
39+
40+
static public void sleepForAtLeastMilliseconds(long sleepMilliseconds) throws InterruptedException {
41+
long startTimeNanoseconds = System.nanoTime();
42+
long sleepNanoseconds = sleepMilliseconds * 1_000_000L;
43+
long remainingMilliseconds = sleepMilliseconds;
44+
45+
while (remainingMilliseconds > 0) {
46+
Thread.sleep(remainingMilliseconds);
47+
long elapsedNanoseconds = System.nanoTime() - startTimeNanoseconds;
48+
remainingMilliseconds = (sleepNanoseconds - elapsedNanoseconds + 1) / 1_000_000L;
49+
}
3650
}
3751
}

0 commit comments

Comments
 (0)