apache/beam · error · AssertionError

BigQuery test was not shutdown previously. Table is

Error message

BigQuery test was not shutdown previously. Table is'${table}'. Current test: ${description.getDisplayName()}

What it means

TestBigQuery is a JUnit TestRule managing a temporary BigQuery dataset. Its state (datasetService) is initialized in evaluate() and cleared afterward; if it is still non-null when a new statement is applied, the previous test never shut the rule down, so this AssertionError fires naming the leftover table and current test.

Solutions

  1. Ensure each test's evaluate() completes so TestBigQuery shutdown runs; check that prior tests are not hung or aborted mid-rule
  2. Verify the rule is declared with @Rule (per-test) and not shared as a static field without @ClassRule semantics
  3. Check for custom Statement/RunRule wrappers that bypass the rule's cleanup
  4. Clear the leftover state (datasetService) before the next test or create a fresh TestBigQuery instance per test
  5. Upgrade/inspect Beam test utilities if a framework bug leaks state

Example fix

// before
static TestBigQuery bigquery = new TestBigQuery(); // shared, leaked state
// after
@Rule public TestBigQuery bigquery = new TestBigQuery(); // fresh per test
Defensive patterns

Strategy: validation

Validate before calling

assert bigqueryRules.isEmpty() : "TestBigQuery rule still active from previous test";

Try / catch

try {
  statement.evaluate();
} catch (AssertionError e) {
  if (e.getMessage() != null && e.getMessage().contains("was not shutdown previously")) {
    // reset leftover rule state before retrying the test
  } else throw e;
}

Prevention

When it happens

Trigger: Reusing a single TestBigQuery rule across tests without the previous test completing (skipped or failed cleanup), applying the rule twice, or a prior test throwing in a way that bypassed the rule's finally cleanup.

Common situations: Suite-level rule reuse, tests aborted by timeout/interrupt before cleanup, custom Statement wrappers that swallow the rule's evaluate, or misconfigured @Rule vs @ClassRule usage.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/b2235923047c3489. Report an issue: GitHub.

Appendix: source

Thrown at sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/TestBigQuery.java:100

   * <p>Loads GCP configuration from {@link TestPipelineOptions}.
   */
  public static TestBigQuery create(Schema tableSchema) {
    return new TestBigQuery(
        TestPipeline.testingPipelineOptions().as(TestBigQueryOptions.class), tableSchema);
  }

  private TestBigQuery(TestBigQueryOptions pipelineOptions, Schema tableSchema) {
    this.pipelineOptions = pipelineOptions;
    this.schema = tableSchema;
  }

  @Override
  public Statement apply(Statement base, Description description) {
    return new Statement() {
      @Override
      public void evaluate() throws Throwable {
        if (TestBigQuery.this.datasetService != null) {
          throw new AssertionError(
              "BigQuery test was not shutdown previously. "
                  + "Table is'"
                  + table
                  + "'. "
                  + "Current test: "
                  + description.getDisplayName());
        }

        try {
          initializeBigQuery(description);
          base.evaluate();
        } finally {
          tearDown();
        }
      }
    };
  }

View on GitHub (pinned to 12126d8942)