From 5aed2e84320733a2d2109caf9654d8011a494630 Mon Sep 17 00:00:00 2001 From: Priamo Germosen <6233424+pgermosen@users.noreply.github.com> Date: Tue, 22 Sep 2026 21:00:57 -0400 Subject: [PATCH] test(acm): elapse the validation wait instead of sleeping through it (#4164) The ACM validation tests slept through the wait rather than driving it, so the class paid the full delay on every run. Elapse the wait from the test instead, which keeps the same assertions and removes the wall-clock cost. --- .../services/acm/AcmIssuanceServiceTest.java | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) 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 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 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 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 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 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 store(Path dir) { PersistentStorage store = new PersistentStorage<>( dir.resolve("acm-certificates.json"), new TypeReference>() {});