Skip to content

fix: resolve nondeterministic Spanner tests by improving SQL assertions#4278

Open
mehdi0933 wants to merge 1 commit intoGoogleCloudPlatform:mainfrom
mehdi0933:fix/spanner-tests-nondeterministic-4235
Open

fix: resolve nondeterministic Spanner tests by improving SQL assertions#4278
mehdi0933 wants to merge 1 commit intoGoogleCloudPlatform:mainfrom
mehdi0933:fix/spanner-tests-nondeterministic-4235

Conversation

@mehdi0933
Copy link

This PR fixes the flaky behavior in SpannerSchemaUtilsTests.java. The getCreateDdlTest was failing intermittently because it relied on a strict string comparison of the generated SQL CREATE TABLE statement.

The Problem: Java's reflection API does not guarantee the order in which fields are retrieved from a class. Consequently, the columns in the generated DDL string would occasionally swap positions, causing the test to fail despite the SQL being functionally correct.

The Solution: I replaced the strict isEqualTo(String) assertion with a set of robust assertions using AssertJ:

Verified the CREATE TABLE header and table name using startsWith.

Verified the PRIMARY KEY clause using contains.

Verified the presence of every individual column and its specific type/options using individual contains assertions.

Why this approach?

CI Stability: It eliminates "false negative" build failures caused by environment-specific field ordering.

Accuracy: It focuses on the technical contract (schema completeness) rather than cosmetic details (column order), which Spanner does not require to be in a specific sequence for table creation.

Low Impact: It avoids adding unnecessary sorting logic to the production code (SpannerSchemaUtils.java), keeping the framework's core logic lean.
See
also CONTRIBUTING.md
.

@mehdi0933 mehdi0933 requested a review from a team as a code owner January 8, 2026 00:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments