diff --git a/regression-test/suites/partition_p0/auto_partition/test_auto_new_recycle.groovy b/regression-test/suites/partition_p0/auto_partition/test_auto_new_recycle.groovy index b37437bdcbf3f2..5f984c37a718c6 100644 --- a/regression-test/suites/partition_p0/auto_partition/test_auto_new_recycle.groovy +++ b/regression-test/suites/partition_p0/auto_partition/test_auto_new_recycle.groovy @@ -15,6 +15,9 @@ // specific language governing permissions and limitations // under the License. +import java.util.concurrent.TimeUnit +import org.awaitility.Awaitility + suite("test_auto_new_recycle", "nonConcurrent") { sql "drop table if exists auto_recycle" test { @@ -113,6 +116,16 @@ suite("test_auto_new_recycle", "nonConcurrent") { waitUntilSafeExecutionTime("NOT_CROSS_DAY_BOUNDARY", 20) + def waitPartitionCount = { int expectedCount -> + Awaitility.await().atMost(1200, TimeUnit.SECONDS).pollInterval(1, TimeUnit.SECONDS).until { + res = sql "show partitions from auto_recycle" + logger.info("partition count: ${res.size()}, expected: ${expectedCount}") + res.size() == expectedCount + } + res = sql "show partitions from auto_recycle" + assertEquals(expectedCount, res.size()) + } + sql """ insert into auto_recycle select date_add('2020-01-01 00:00:00', interval number day) from numbers("number" = "100"); """ @@ -124,9 +137,7 @@ suite("test_auto_new_recycle", "nonConcurrent") { assertTrue(res[0][1].contains('"partition.retention_count" = "3"')) sql """ admin set frontend config ('dynamic_partition_check_interval_seconds' = '1') """ - sleep(8000) - res = sql "show partitions from auto_recycle" - assertEquals(res.size(), 3) + waitPartitionCount.call(3) // before everytime insert data, we should avoid recycle because if they conflict, insert will fail sql """ admin set frontend config ('dynamic_partition_check_interval_seconds' = '600') """ @@ -135,15 +146,11 @@ suite("test_auto_new_recycle", "nonConcurrent") { insert into auto_recycle select date_add('2020-01-01 00:00:00', interval number day) from numbers("number" = "100"); """ sql """ admin set frontend config ('dynamic_partition_check_interval_seconds' = '1') """ - sleep(8000) - res = sql "show partitions from auto_recycle" - assertEquals(res.size(), 3) + waitPartitionCount.call(3) qt_sql0 "select * from auto_recycle order by k0" sql "alter table auto_recycle set ('partition.retention_count' = '1')" - sleep(5000) - res = sql "show partitions from auto_recycle" - assertEquals(res.size(), 1) + waitPartitionCount.call(1) sql "alter table auto_recycle set ('partition.retention_count' = '10')" sql """ admin set frontend config ('dynamic_partition_check_interval_seconds' = '600') """ @@ -152,9 +159,7 @@ suite("test_auto_new_recycle", "nonConcurrent") { insert into auto_recycle select date_add('2022-01-01 00:00:00', interval number day) from numbers("number" = "100"); """ sql """ admin set frontend config ('dynamic_partition_check_interval_seconds' = '1') """ - sleep(8000) - res = sql "show partitions from auto_recycle" - assertEquals(res.size(), 10) + waitPartitionCount.call(10) qt_sql1 "select * from auto_recycle order by k0" // verify not consider future partition when do recycle @@ -175,11 +180,9 @@ suite("test_auto_new_recycle", "nonConcurrent") { insert into auto_recycle select date_add(now(), interval number-5 day) from numbers("number" = "8"); """ sql """ admin set frontend config ('dynamic_partition_check_interval_seconds' = '1') """ - sleep(8000) - res = sql "show partitions from auto_recycle" - assertEquals(res.size(), 6) // [-5, -1] -> [-3, -1], [0, 2] -> [0, 2] + waitPartitionCount.call(6) // [-5, -1] -> [-3, -1], [0, 2] -> [0, 2] res = sql "select * from auto_recycle order by k0" assertEquals(res.size(), 6) sql """ admin set frontend config ('dynamic_partition_check_interval_seconds' = '600') """ -} \ No newline at end of file +}