Re-enable flyway deadlock check (#2092)

Use a system property to specify whether this check should be executed.

We will update the presubmit test script to run this check only during
foss-pr.
This commit is contained in:
Weimin Yu 2023-08-03 15:34:30 -04:00 committed by GitHub
parent 6ea548a35d
commit aab89fb816
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 2 deletions

View file

@ -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/

View file

@ -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.
*
* <p>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<Path> newScriptPaths = findChangedFlywayScripts();
ImmutableList<String> scriptAndLockedElements =