Skip to content

Commit d086ba7

Browse files
test(spanner): unflake BuiltInMetricsCustomOpenTelemetryTest and BuiltInMetricsBothSinksTest (#14282)
In `executeSelect1()`, `resultSet.next()` was called only once for `SELECT 1`. Closing the `ResultSet` before consuming the stream to EOF invokes `iterator.close()`, which sends `call.cancel("ResultSet closed", null)` to the underlying gRPC stream. If client cancellation races ahead of the mock server's `onCompleted()`, the stream terminates with `Status.CANCELLED`. As a result, `SpannerTracer.operationSucceeded()` is never invoked, omitting `Spanner.ExecuteStreamingSql` (status `OK`) from `spanner.googleapis.com/internal/client/operation_count` and causing the test assertion to fail. Consume the `ResultSet` to EOF (`assertFalse(resultSet.next())`) in both `BuiltInMetricsCustomOpenTelemetryTest` and `BuiltInMetricsBothSinksTest` to guarantee that the stream finishes normally before closing.
1 parent 89a8268 commit d086ba7

2 files changed

Lines changed: 3 additions & 0 deletions

File tree

‎java-spanner/google-cloud-spanner/src/test/java/com/google/cloud/spanner/BuiltInMetricsBothSinksTest.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ private static void executeSelect1(Spanner spanner) {
102102
try (ResultSet resultSet = client.singleUse().executeQuery(SELECT1)) {
103103
assertThat(resultSet.next()).isTrue();
104104
assertThat(resultSet.getLong(0)).isEqualTo(1L);
105+
assertThat(resultSet.next()).isFalse();
105106
}
106107
}
107108

‎java-spanner/google-cloud-spanner/src/test/java/com/google/cloud/spanner/BuiltInMetricsCustomOpenTelemetryTest.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.google.cloud.spanner;
1818

1919
import static com.google.common.truth.Truth.assertThat;
20+
import static org.junit.Assert.assertFalse;
2021
import static org.junit.Assert.assertNotNull;
2122
import static org.junit.Assert.assertNull;
2223
import static org.junit.Assert.assertTrue;
@@ -79,6 +80,7 @@ private static void executeSelect1(Spanner spanner) {
7980
try (ResultSet resultSet = client.singleUse().executeQuery(SELECT1)) {
8081
assertTrue(resultSet.next());
8182
assertThat(resultSet.getLong(0)).isEqualTo(1L);
83+
assertFalse(resultSet.next());
8284
}
8385
}
8486

0 commit comments

Comments
 (0)