diff --git a/db/build.gradle b/db/build.gradle index 22f83229c..3e96133a5 100644 --- a/db/build.gradle +++ b/db/build.gradle @@ -179,6 +179,14 @@ dependencies { testImplementation project(path: ':common', configuration: 'testing') } +test { + // When set, run FlywayDeadlockTest#validNewScript. + def deadlock_check = 'do_flyway_deadlock_check' + if (findProperty(deadlock_check)) { + systemProperty deadlock_check, findProperty(deadlock_check) + } +} + task generateFlywayIndex { def flywayBase = "$projectDir/src/main/resources/sql/flyway" def filenamePattern = /V(\d+)__.*\.sql/ diff --git a/db/src/test/java/google/registry/sql/flyway/FlywayDeadlockTest.java b/db/src/test/java/google/registry/sql/flyway/FlywayDeadlockTest.java index 1d29504f5..0be611e29 100644 --- a/db/src/test/java/google/registry/sql/flyway/FlywayDeadlockTest.java +++ b/db/src/test/java/google/registry/sql/flyway/FlywayDeadlockTest.java @@ -36,8 +36,8 @@ import java.util.Map; import java.util.Optional; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.EnabledIfSystemProperty; /** * Checks if new Flyway scripts may cause Database deadlock. @@ -53,7 +53,6 @@ import org.junit.jupiter.api.Test; * Therefore, we focus on 'alter' statements. However, 'create index' is a special case: if the * 'concurrently' modifier is not present, the indexed table is locked. */ -@Disabled() // TODO(b/223669973): breaks cloudbuild. public class FlywayDeadlockTest { private static final FluentLogger logger = FluentLogger.forEnclosingClass(); @@ -104,7 +103,18 @@ public class FlywayDeadlockTest { CASE_INSENSITIVE), 3); + /** + * Validates that new flyway scripts (if exist) do not have deadlock-inducing patterns. + * + *
This test may break if not invoked in a cloned Nomulus repository, therefore it is disabled
+ * by default. User can enable it by setting the {@code do_flyway_deadlock_check} system property
+ * with arbitrary non-empty value.
+ */
@Test
+ @EnabledIfSystemProperty(
+ named = "do_flyway_deadlock_check",
+ matches = ".+",
+ disabledReason = "Not compatible with the release process on Cloud Build.")
public void validateNewFlywayScripts() {
ImmutableList