Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

test(acm): elapse the validation wait instead of sleeping through it (#4164)

Priamo Germosen5aed2e843207
diff --git a/src/test/java/io/github/hectorvent/floci/services/acm/AcmIssuanceServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/acm/AcmIssuanceServiceTest.java
index 36b3414f0e..2e34de1a54 100644
--- a/src/test/java/io/github/hectorvent/floci/services/acm/AcmIssuanceServiceTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/acm/AcmIssuanceServiceTest.java
@@ -76,7 +76,8 @@ class AcmIssuanceServiceTest {
@Test
void pendingCertificateReportsPendingValidationUntilTheWaitHasPassed(@TempDir Path dir) throws Exception {
- AcmService service = newService(dir, 1);
+ PersistentStorage<String, Certificate> store = store(dir);
+ AcmService service = newService(dir, store, 1);
Certificate requested = request(service, null);
String arn = requested.getArn();
@@ -88,7 +89,7 @@ class AcmIssuanceServiceTest {
assertTrue(stillPending.getDomainValidationOptions().stream()
.allMatch(validation -> "PENDING_VALIDATION".equals(validation.validationStatus())));
- Thread.sleep(1200);
+ elapseValidationWait(store, arn, 1);
Certificate issued = service.describeCertificate(arn, REGION);
assertEquals(CertificateStatus.ISSUED, issued.getStatus());
@@ -99,9 +100,10 @@ class AcmIssuanceServiceTest {
@Test
void settledCertificateIsPersistedNotRecomputed(@TempDir Path dir) throws Exception {
- AcmService service = newService(dir, 1);
+ PersistentStorage<String, Certificate> store = store(dir);
+ AcmService service = newService(dir, store, 1);
String arn = request(service, null).getArn();
- Thread.sleep(1200);
+ elapseValidationWait(store, arn, 1);
service.getCertificate(arn, REGION);
// A restarted service with a wait that has not passed yet would leave a pending certificate
@@ -115,12 +117,13 @@ class AcmIssuanceServiceTest {
@Test
void listCertificatesSettlesPendingCertificatesBeforeFilteringByStatus(@TempDir Path dir) throws Exception {
- AcmService service = newService(dir, 1);
+ PersistentStorage<String, Certificate> store = store(dir);
+ AcmService service = newService(dir, store, 1);
String arn = request(service, null).getArn();
assertTrue(service.listCertificates(List.of(CertificateStatus.ISSUED), null, REGION, 100, null)
.certificates().isEmpty(), "still pending");
- Thread.sleep(1200);
+ elapseValidationWait(store, arn, 1);
List<Certificate> issued = service.listCertificates(List.of(CertificateStatus.ISSUED), null, REGION, 100, null)
.certificates();
@@ -207,6 +210,19 @@ class AcmIssuanceServiceTest {
regionResolver, validationWaitSeconds);
}
+ /**
+ * Moves the certificate's creation back past the validation wait, so the next read settles it.
+ * The service reads this same store, so this is the wait having elapsed rather than a wait for
+ * it to elapse.
+ */
+ private static void elapseValidationWait(StorageBackend<String, Certificate> store, String arn,
+ int validationWaitSeconds) {
+ String key = REGION + "::" + arn.substring(arn.lastIndexOf('/') + 1);
+ Certificate cert = store.get(key).orElseThrow();
+ cert.setCreatedAt(cert.getCreatedAt().minusSeconds(validationWaitSeconds + 1L));
+ store.put(key, cert);
+ }
+
private static PersistentStorage<String, Certificate> store(Path dir) {
PersistentStorage<String, Certificate> store = new PersistentStorage<>(
dir.resolve("acm-certificates.json"), new TypeReference<Map<String, Certificate>>() {});