{"record":{"id":"b2235923047c3489","repo":"apache/beam","slug":"bigquery-test-was-not-shutdown-previously-table-is-table","errorCode":null,"errorMessage":"BigQuery test was not shutdown previously. Table is'${table}'. Current test: ${description.getDisplayName()}","messagePattern":"BigQuery test was not shutdown previously\\. Table is'(.+?)'\\. Current test: (.+?)","errorType":"exception","errorClass":"AssertionError","httpStatus":null,"severity":"error","filePath":"sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/TestBigQuery.java","lineNumber":100,"sourceCode":"   * <p>Loads GCP configuration from {@link TestPipelineOptions}.\n   */\n  public static TestBigQuery create(Schema tableSchema) {\n    return new TestBigQuery(\n        TestPipeline.testingPipelineOptions().as(TestBigQueryOptions.class), tableSchema);\n  }\n\n  private TestBigQuery(TestBigQueryOptions pipelineOptions, Schema tableSchema) {\n    this.pipelineOptions = pipelineOptions;\n    this.schema = tableSchema;\n  }\n\n  @Override\n  public Statement apply(Statement base, Description description) {\n    return new Statement() {\n      @Override\n      public void evaluate() throws Throwable {\n        if (TestBigQuery.this.datasetService != null) {\n          throw new AssertionError(\n              \"BigQuery test was not shutdown previously. \"\n                  + \"Table is'\"\n                  + table\n                  + \"'. \"\n                  + \"Current test: \"\n                  + description.getDisplayName());\n        }\n\n        try {\n          initializeBigQuery(description);\n          base.evaluate();\n        } finally {\n          tearDown();\n        }\n      }\n    };\n  }\n","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/TestBigQuery.java#L82-L118","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure each test's evaluate() completes so TestBigQuery shutdown runs; check that prior tests are not hung or aborted mid-rule","Verify the rule is declared with @Rule (per-test) and not shared as a static field without @ClassRule semantics","Check for custom Statement/RunRule wrappers that bypass the rule's cleanup","Clear the leftover state (datasetService) before the next test or create a fresh TestBigQuery instance per test","Upgrade/inspect Beam test utilities if a framework bug leaks state"],"exampleFix":"// before\nstatic TestBigQuery bigquery = new TestBigQuery(); // shared, leaked state\n// after\n@Rule public TestBigQuery bigquery = new TestBigQuery(); // fresh per test","handlingStrategy":"validation","validationCode":"assert bigqueryRules.isEmpty() : \"TestBigQuery rule still active from previous test\";","typeGuard":null,"tryCatchPattern":"try {\n  statement.evaluate();\n} catch (AssertionError e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"was not shutdown previously\")) {\n    // reset leftover rule state before retrying the test\n  } else throw e;\n}","preventionTips":["Declare TestBigQuery with @Rule per test rather than sharing instances","Ensure prior tests finish normally so cleanup runs","Avoid wrapping the rule's Statement in code that skips evaluate","Investigate hangs/timeouts in earlier tests that bypass cleanup"],"tags":["java","junit","google-bigquery","test-rule","lifecycle"],"backgroundTag":"invalid-state-transition","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}