From 4e1efc02f6329e48c2ac87e5f4c6857e8feda8b8 Mon Sep 17 00:00:00 2001 From: Lai Jiang Date: Thu, 10 Jun 2021 14:06:05 -0400 Subject: [PATCH] Fix a flaky test (#1204) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In testSuccess_expandSingleEvent_notIdempotentforDifferentRecurring(), two Recurring entities are created with the only difference being their IDs. If we don't order the Recurrings by ID when loading them there is no guarantee which one is expanded first. In this test the expected OneTime entities are created with the assumption that the first loaded DomainHistory (parent of a OneTime) corresponds to the expanding the Recurring with the smaller ID (2L). Since the DomainHistory entities are loaded in order of IDs, and the IDs are created monotonically in time in tests, we need to load the Recurrings in order of their IDs to ensure that the first DomainHistory is the result of expanding the Recurring with ID of 2L. This should impose minimum performance penalty as we are ordering by the primary key. --- This change is [Reviewable](https://reviewable.io/reviews/google/nomulus/1204) --- .../registry/batch/ExpandRecurringBillingEventsAction.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/google/registry/batch/ExpandRecurringBillingEventsAction.java b/core/src/main/java/google/registry/batch/ExpandRecurringBillingEventsAction.java index 70d57b37e..d7af2f345 100644 --- a/core/src/main/java/google/registry/batch/ExpandRecurringBillingEventsAction.java +++ b/core/src/main/java/google/registry/batch/ExpandRecurringBillingEventsAction.java @@ -127,10 +127,11 @@ public class ExpandRecurringBillingEventsAction implements Runnable { jpaTm() .query( "FROM BillingRecurrence " - + "WHERE event_time <= :executeTime " - + "AND event_time < recurrence_end_time", + + "WHERE eventTime <= :executeTime " + + "AND eventTime < recurrenceEndTime " + + "ORDER BY id ASC", Recurring.class) - .setParameter("executeTime", executeTime.toDate()) + .setParameter("executeTime", executeTime) // Need to get a list from the transaction and then convert it to a stream // for further processing. If we get a stream directly, each elements gets // processed downstream eagerly but Hibernate returns a