diff --git a/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/source/TestStructuredStreamingRead3.java b/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/source/TestStructuredStreamingRead3.java index 4efb883b5d6c..609de8afec21 100644 --- a/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/source/TestStructuredStreamingRead3.java +++ b/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/source/TestStructuredStreamingRead3.java @@ -175,7 +175,11 @@ public void stopStreams() throws TimeoutException { } @AfterEach - public void removeTables() { + public void removeTables() throws TimeoutException { + // Stop active streams before dropping the table. In async mode the planner's background + // thread keeps refreshing the table from the catalog; dropping the table while that thread + // is alive lets those refreshes contend with DROP TABLE and stall teardown for seconds. + stopStreams(); sql("DROP TABLE IF EXISTS %s", tableName); } diff --git a/spark/v4.0/spark/src/test/java/org/apache/iceberg/spark/source/TestStructuredStreamingRead3.java b/spark/v4.0/spark/src/test/java/org/apache/iceberg/spark/source/TestStructuredStreamingRead3.java index 06189b304299..1f2a87f17218 100644 --- a/spark/v4.0/spark/src/test/java/org/apache/iceberg/spark/source/TestStructuredStreamingRead3.java +++ b/spark/v4.0/spark/src/test/java/org/apache/iceberg/spark/source/TestStructuredStreamingRead3.java @@ -175,7 +175,11 @@ public void stopStreams() throws TimeoutException { } @AfterEach - public void removeTables() { + public void removeTables() throws TimeoutException { + // Stop active streams before dropping the table. In async mode the planner's background + // thread keeps refreshing the table from the catalog; dropping the table while that thread + // is alive lets those refreshes contend with DROP TABLE and stall teardown for seconds. + stopStreams(); sql("DROP TABLE IF EXISTS %s", tableName); } diff --git a/spark/v4.1/spark/src/test/java/org/apache/iceberg/spark/source/TestStructuredStreamingRead3.java b/spark/v4.1/spark/src/test/java/org/apache/iceberg/spark/source/TestStructuredStreamingRead3.java index 89947f73ea38..00238cfcc341 100644 --- a/spark/v4.1/spark/src/test/java/org/apache/iceberg/spark/source/TestStructuredStreamingRead3.java +++ b/spark/v4.1/spark/src/test/java/org/apache/iceberg/spark/source/TestStructuredStreamingRead3.java @@ -176,7 +176,11 @@ public void stopStreams() throws TimeoutException { } @AfterEach - public void removeTables() { + public void removeTables() throws TimeoutException { + // Stop active streams before dropping the table. In async mode the planner's background + // thread keeps refreshing the table from the catalog; dropping the table while that thread + // is alive lets those refreshes contend with DROP TABLE and stall teardown for seconds. + stopStreams(); sql("DROP TABLE IF EXISTS %s", tableName); }