Skip to content

Additional potential nondeterministic unit tests in SpannerSchemaUtilsTests due to SQL column ordering #4235

@anthonyx24

Description

@anthonyx24

Issue

Hello, this is a similar issue to #4184 in which some unit tests rely on nondeterministic column ordering in the expected SQL statement. This is due to the reflection-based property iteration in the addColumnDdlStrings() method of SpannerSchemaUtils, which is used to generate the statements.

These are the tests:

com.google.cloud.spring.data.spanner.core.admin.SpannerSchemaUtilsTests.getCreateDdlTest
com.google.cloud.spring.data.spanner.core.admin.SpannerSchemaUtilsTests.getCreateDdlHierarchyTest

This time, there are only 2 unit tests, but I decided to open a separate issue since the statements are generated in a different class than the other 15 tests in the first issue I opened. Again, I found these tests via the Nondex tool, which flags Java tests that are potentially nondeterministic due to underlying assumptions regarding the Java API. To see the Nondex output for this test class, you can run:


mvn -pl spring-cloud-gcp-data-spanner edu.illinois:nondex-maven-plugin:2.1.7:nondex -Dtest="com.google.cloud.spring.data.spanner.core.admin.SpannerSchemaUtilsTests"

Potential Fix

The fix I suggest is similar to the fix for the other issue as well, which is simply to sort the columns alphabetically when generating the statement. This is assuming column ordering is not important, please let me know if it is. I'll attach the PR link in the conversation below, and would appreciate any feedback. Thanks!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions