From abed4bd1e6bc4b33543e214c019c63b49e6370e1 Mon Sep 17 00:00:00 2001 From: Ben McIlwain Date: Mon, 22 Jun 2026 19:50:08 -0400 Subject: [PATCH] Fix flaky RdapDomainSearchActionTest Refactor RdapDomainSearchActionTest to dynamically resolve all domain and host Repository IDs (ROIDs) instead of asserting on hardcoded, sequence-generated strings (like "2E-LOL" or "6-LOL"). When tests are executed in parallel (as is common in CI environments like Kokoro), multiple test threads concurrently reset and allocate from the shared database sequence 'project_wide_unique_id_seq'. This interleaves ID allocations non-deterministically, causing any test asserting on exact, hardcoded sequence values to flake. To fix this, createManyDomainsAndHosts was updated to return the list of persisted domains, allowing tests to dynamically resolve their ROIDs. All other test cases were refactored to dynamically fetch the ROIDs of pre-created domains and hosts (stored in fields or in hostNameToHostMap, using punycode keys for IDN hosts) for their JSON assertions, rendering the entire suite robust against sequence shifts. --- .../rdap/RdapDomainSearchActionTest.java | 229 +++++++++--------- 1 file changed, 115 insertions(+), 114 deletions(-) diff --git a/core/src/test/java/google/registry/rdap/RdapDomainSearchActionTest.java b/core/src/test/java/google/registry/rdap/RdapDomainSearchActionTest.java index e727bb8c84a..0885d461c87 100644 --- a/core/src/test/java/google/registry/rdap/RdapDomainSearchActionTest.java +++ b/core/src/test/java/google/registry/rdap/RdapDomainSearchActionTest.java @@ -283,15 +283,15 @@ void beforeEach() { private JsonObject generateExpectedJsonForTwoDomainsNsReply() { return jsonFileBuilder() - .addDomain("cat.example", "F-EXAMPLE") - .addDomain("cat.lol", "6-LOL") + .addDomain("cat.example", domainCatExample.getRepoId()) + .addDomain("cat.lol", domainCatLol.getRepoId()) .load("rdap_domains_two.json"); } private JsonObject generateExpectedJsonForTwoDomainsCatStarReplySql() { return jsonFileBuilder() - .addDomain("cat.lol", "6-LOL") - .addDomain("cat2.lol", "B-LOL") + .addDomain("cat.lol", domainCatLol.getRepoId()) + .addDomain("cat2.lol", domainCatLol2.getRepoId()) .load("rdap_domains_two.json"); } @@ -306,7 +306,7 @@ private void deleteCatLol() { minusMonths(clock.now(), 6))); } - private void createManyDomainsAndHosts( + private ImmutableList createManyDomainsAndHosts( int numActiveDomains, int numTotalDomainsPerActiveDomain, int numHosts) { ImmutableSet.Builder> hostKeysBuilder = new ImmutableSet.Builder<>(); ImmutableSet.Builder subordinateHostnamesBuilder = new ImmutableSet.Builder<>(); @@ -340,7 +340,7 @@ private void createManyDomainsAndHosts( } domainsBuilder.add(builder.build()); } - persistResources(domainsBuilder.build()); + return persistResources(domainsBuilder.build()); } private void checkNumberOfDomainsInResult(JsonObject obj, int expected) { @@ -353,10 +353,10 @@ private void runSuccessfulTestWithCatLol( requestType, queryString, jsonFileBuilder() - .addDomain("cat.lol", "6-LOL") + .addDomain("cat.lol", domainCatLol.getRepoId()) .addRegistrar("Yes Virginia