From c11f7151571ad76d7e0f4635bfdfb097b5cf9f11 Mon Sep 17 00:00:00 2001 From: Weimin Yu Date: Wed, 12 May 2021 16:03:42 -0400 Subject: [PATCH] Restore a fix for flaky test (#1154) * Restore a fix for flaky test Restore a speculative fix for the flakiness in DeleteExpiredDomainsActionTest. Although we identified a bug and fixed it in a previous commit, it may not be the only bug. The removed fix may still be necessary. --- .../batch/DeleteExpiredDomainsActionTest.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/core/src/test/java/google/registry/batch/DeleteExpiredDomainsActionTest.java b/core/src/test/java/google/registry/batch/DeleteExpiredDomainsActionTest.java index bc5935645..06c823d05 100644 --- a/core/src/test/java/google/registry/batch/DeleteExpiredDomainsActionTest.java +++ b/core/src/test/java/google/registry/batch/DeleteExpiredDomainsActionTest.java @@ -16,6 +16,7 @@ package google.registry.batch; import static com.google.common.truth.Truth.assertThat; import static google.registry.model.eppcommon.StatusValue.PENDING_DELETE; +import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.reporting.HistoryEntry.Type.DOMAIN_CREATE; import static google.registry.persistence.transaction.TransactionManagerFactory.tm; import static google.registry.testing.DatabaseHelper.createTld; @@ -127,6 +128,29 @@ class DeleteExpiredDomainsActionTest { DomainBase domain2 = persistNonAutorenewingDomain("veee2.tld"); DomainBase domain3 = persistNonAutorenewingDomain("tarm3.tld"); + // action.run() executes an ancestor-less query which is subject to eventual consistency (it + // uses an index that is updated asynchronously). For a deterministic test outcome, we busy + // wait here to give the data time to converge. + int maxRetries = 5; + while (true) { + ImmutableSet matchingDomains = + ofy() + .load() + .type(DomainBase.class) + .filter("autorenewEndTime <=", clock.nowUtc()) + .list() + .stream() + .map(DomainBase::getDomainName) + .collect(ImmutableSet.toImmutableSet()); + if (matchingDomains.containsAll(ImmutableSet.of("ecck1.tld", "veee2.tld", "tarm3.tld"))) { + break; + } + if (maxRetries-- <= 0) { + throw new RuntimeException("Eventual consistency does not converge in time for this test."); + } + Thread.sleep(200); + } + // action.run does multiple write transactions. We cannot emulate the behavior by manually // advancing the clock. Auto-increment to avoid timestamp inversion. clock.setAutoIncrementByOneMilli();