GoogleCloudPlatform / GoogleCloudPlatform/spring-cloud-gcp
Additional potential nondeterministic unit tests in SpannerSchemaUtilsTests due to SQL column ordering
- Dominant language
- Java
- Stars
- 551
- Forks
- 349
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 14
Description
### 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`](https://github.com/GoogleCloudPlatform/spring-cloud-gcp/blob/fb932b760623db5bfef0b3afad4fe7a7467bafb3/spring-cloud-gcp-data-spanner/src/main/java/com/google/cloud/spring/data/spanner/core/admin/SpannerSchemaUtils.java#L239), 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](https://github.com/TestingResearchIllinois/NonDex), 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!
Contributor guide
Research direction
Start in spring-cloud-gcp-data-spanner/src/main/java/com/google/cloud/spring/data/spanner/core/admin/SpannerSchemaUtils.java, at addColumnDdlStrings(), and inspect how reflection determines column order. Run the listed SpannerSchemaUtilsTests or the provided NonDex Maven command. Done means getCreateDdlTest and getCreateDdlHierarchyTest no longer depend on nondeterministic ordering and pass consistently.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- databases, testing
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 50/100