Skip to content

Commit 0ec6449

Browse files
committed
Use wiater until instead of Thread.sleep
1 parent ccaa156 commit 0ec6449

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

services/cloudfront/src/test/java/software/amazon/awssdk/services/cloudfront/CloudFrontUtilitiesIntegrationTest.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -617,15 +617,16 @@ private static String getOrCreateKeyGroup() {
617617
.ifMatch(keyGroupResp.eTag())
618618
.keyGroupConfig(KeyGroupConfig.builder().name(keyGroupName).items(rsaKeyPairId, ecKeyPairId).build());
619619
});
620-
// there is no waiter for keyGroup updates, but it may take up to 1 minute for the updates to propagate
621-
try {
622-
System.out.println("Waiting 1 minute for keygroup updates to propagate in distribution...");
623-
Thread.sleep(Duration.ofMinutes(1).toMillis());
624-
} catch (InterruptedException e) {
625-
throw new RuntimeException(e);
626-
}
627-
}
628620

621+
// KeyGroups update quickly, but it takes up to 1 minute to propagate to the cache
622+
System.out.println("Waiting for key group update to propagate.");
623+
Instant expectedPropagationTime = Instant.now().plusSeconds(60);
624+
Waiter.run(Instant::now)
625+
.until((t) -> t.isAfter(expectedPropagationTime))
626+
.orFailAfter(Duration.ofMinutes(1));
627+
628+
System.out.println("Waited for: " + expectedPropagationTime.compareTo(Instant.now()) + " seconds");
629+
}
629630
return keyGroupSummary.get().keyGroup().id();
630631
}
631632

0 commit comments

Comments
 (0)