From 9c17d9de61c676375cf603b48ab6e052f43e7823 Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Thu, 19 Nov 2026 19:17:37 +0000 Subject: [PATCH] test(bigquery): use compute query in testQueryStatistics to avoid 0 totalSlotMs flake Re-enable ITBigQueryTest.testQueryStatistics and replace SELECT CURRENT_TIMESTAMP() AS ts with SELECT SUM(x) AS total FROM UNNEST(GENERATE_ARRAY(1, 1000000)) AS x. A scalar-only query such as SELECT CURRENT_TIMESTAMP() can finish in under 1 ms of slot time on BigQuery's short-query path and legitimately report 0 totalSlotMs, causing assertThat(statistics.getTotalSlotMs()).isGreaterThan(0L) to flake. Summing a generated array remains self-contained with 0 bytes scanned (no external table dependency, safe on regional and GraalVM Native Image runs) while reliably executing real slot work. Fixes b/574587826. --- .../com/google/cloud/bigquery/it/ITBigQueryTest.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/java-bigquery/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java b/java-bigquery/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java index 54183609b685..74785532ae71 100644 --- a/java-bigquery/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java +++ b/java-bigquery/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java @@ -208,7 +208,6 @@ import org.apache.arrow.vector.VectorSchemaRoot; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Timeout; import org.threeten.extra.PeriodDuration; @@ -3594,11 +3593,13 @@ void testQuery() throws InterruptedException { assertNotNull(statistics.getQueryPlan()); } - @Disabled("Flaky test: b/574587826") @Test void testQueryStatistics() throws InterruptedException { - // Use CURRENT_TIMESTAMP to avoid potential caching. - String query = "SELECT CURRENT_TIMESTAMP() AS ts"; + // Run a lightweight, self-contained 0-byte compute query with caching disabled so BigQuery + // executes real slot work. A scalar-only query such as SELECT CURRENT_TIMESTAMP() can finish + // in under 1 ms of slot time on BigQuery's short-query path and legitimately report 0 + // totalSlotMs. + String query = "SELECT SUM(x) AS total FROM UNNEST(GENERATE_ARRAY(1, 1000000)) AS x"; QueryJobConfiguration config = QueryJobConfiguration.newBuilder(query) .setDefaultDataset(DatasetId.of(DATASET))