From 4ce7b15591c577db1662179bc10fbe8aad017e05 Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Thu, 9 Jul 2026 20:10:02 +0000 Subject: [PATCH] test(spanner): fix flaky readUnmatchableTypesTest Rewrite the test to actually test unmatchable types by allowing missing columns and asserting on the conversion exception. This avoids the flakiness caused by non-deterministic field processing order when checking for missing columns. --- ...nverterAwareMappingSpannerEntityReaderTests.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/spring-cloud-gcp-data-spanner/src/test/java/com/google/cloud/spring/data/spanner/core/convert/ConverterAwareMappingSpannerEntityReaderTests.java b/spring-cloud-gcp-data-spanner/src/test/java/com/google/cloud/spring/data/spanner/core/convert/ConverterAwareMappingSpannerEntityReaderTests.java index 0d89ce7c0c1..53c56b72a19 100644 --- a/spring-cloud-gcp-data-spanner/src/test/java/com/google/cloud/spring/data/spanner/core/convert/ConverterAwareMappingSpannerEntityReaderTests.java +++ b/spring-cloud-gcp-data-spanner/src/test/java/com/google/cloud/spring/data/spanner/core/convert/ConverterAwareMappingSpannerEntityReaderTests.java @@ -47,6 +47,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.core.convert.ConversionFailedException; +import org.springframework.core.convert.ConverterNotFoundException; import org.springframework.core.convert.converter.Converter; import org.springframework.lang.Nullable; @@ -276,11 +277,15 @@ void readUnmatchableTypesTest() { assertThatThrownBy(() -> this.spannerEntityReader.read( FaultyTestEntity.class, struct, - java.util.Set.of("id"), - false + null, // includeColumns = null means read all columns + true // allowMissingColumns = true prevents failing early on the missing 'id' column )) - .isInstanceOf(SpannerDataException.class) - .hasMessageContaining("Unable to read column from Cloud Spanner results"); + // We expect ConverterNotFoundException because: + // 1. The missing 'id' column is allowed and does not cause a failure. + // 2. The reader proceeds to process 'fieldWithUnsupportedType'. + // 3. Since there is no converter from String to TestEntity, Spring throws ConverterNotFoundException. + .isInstanceOf(ConverterNotFoundException.class) + .hasMessageContaining("No converter found capable of converting from type"); } @Test