This is an automated email from the ASF dual-hosted git repository.
zclll pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new 1740fc9f560 [feature](regression) add waitUntilSafeExecutionTime
function to framework (#52885)
1740fc9f560 is described below
commit 1740fc9f560d700873e30a6010d856f63efad7a2
Author: shuke <[email protected]>
AuthorDate: Thu Jul 10 23:51:51 2025 +0800
[feature](regression) add waitUntilSafeExecutionTime function to framework
(#52885)
### What problem does this PR solve?
Add a new regression framework function solves the problem where tests
cannot span hour or day boundaries.
For example: Some tests may fail when crossing hour or day boundaries.
Using this function
ensures that tests are executed within a safe time window to avoid
crossing specified time boundaries.
---
.../org/apache/doris/regression/suite/Suite.groovy | 50 ++++++++++++++++++++++
.../test_information_schema_timezone.groovy | 10 +++++
2 files changed, 60 insertions(+)
diff --git
a/regression-test/framework/src/main/groovy/org/apache/doris/regression/suite/Suite.groovy
b/regression-test/framework/src/main/groovy/org/apache/doris/regression/suite/Suite.groovy
index 79ee1273685..9457effed88 100644
---
a/regression-test/framework/src/main/groovy/org/apache/doris/regression/suite/Suite.groovy
+++
b/regression-test/framework/src/main/groovy/org/apache/doris/regression/suite/Suite.groovy
@@ -84,6 +84,9 @@ import java.sql.PreparedStatement
import java.sql.ResultSetMetaData
import org.junit.Assert
+import java.time.LocalDateTime
+import java.time.temporal.ChronoUnit
+
@Slf4j
class Suite implements GroovyInterceptable {
final SuiteContext context
@@ -2971,4 +2974,51 @@ class Suite implements GroovyInterceptable {
beHostToHashFile
}
+ /**
+ * Wait until the specified time constraint is satisfied before executing
the test.
+ *
+ * This function solves the problem where tests cannot span hour or day
boundaries.
+ * For example: Some tests may fail when crossing hour or day boundaries.
Using this function
+ * ensures that tests are executed within a safe time window to avoid
crossing specified time boundaries.
+ *
+ * @param caseSpanConstraint:
+ * - "NOT_CROSS_HOUR_BOUNDARY": Test cannot cross hour boundary
+ * - "NOT_CROSS_DAY_BOUNDARY": Test cannot cross day boundary
+ * @param caseElapseSeconds Expected total execution time of the test in
seconds
+ */
+ void waitUntilSafeExecutionTime(String caseSpanConstraint, int
caseElapseSeconds) {
+ if (caseElapseSeconds <= 0) {
+ throw new IllegalArgumentException("invalid caseElapseSeconds,
${caseElapseSeconds}")
+ }
+
+ long sleepSeconds = 0
+ LocalDateTime now = LocalDateTime.now();
+
+ switch (caseSpanConstraint) {
+ case "NOT_CROSS_HOUR_BOUNDARY":
+ LocalDateTime nextHour =
now.withMinute(0).withSecond(0).withNano(0).plusHours(1);
+ long secondsToNextHour = ChronoUnit.SECONDS.between(now,
nextHour)
+
+ if (secondsToNextHour < caseElapseSeconds) {
+ sleepSeconds = secondsToNextHour
+ }
+ break
+
+ case "NOT_CROSS_DAY_BOUNDARY":
+ LocalDateTime startOfNextDay =
now.toLocalDate().plusDays(1).atStartOfDay();
+ long secondsToNextDay = ChronoUnit.SECONDS.between(now,
startOfNextDay)
+
+ if (secondsToNextDay < caseElapseSeconds) {
+ sleepSeconds = secondsToNextDay
+ }
+ break
+ default:
+ throw new IllegalArgumentException("invalid
caseSpanConstraint:${caseSpanConstraint}")
+ }
+
+ if (sleepSeconds > 0) {
+ logger.info("test sleeps ${sleepSeconds} to satisfy
${caseSpanConstraint}")
+ Thread.sleep(sleepSeconds * 1000)
+ }
+ }
}
diff --git
a/regression-test/suites/external_table_p0/info_schema_db/test_information_schema_timezone.groovy
b/regression-test/suites/external_table_p0/info_schema_db/test_information_schema_timezone.groovy
index 3e3e168c054..ede50175343 100644
---
a/regression-test/suites/external_table_p0/info_schema_db/test_information_schema_timezone.groovy
+++
b/regression-test/suites/external_table_p0/info_schema_db/test_information_schema_timezone.groovy
@@ -19,6 +19,16 @@ import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
suite("test_information_schema_timezone",
"p0,external,hive,kerberos,external_docker,external_docker_kerberos") {
+ /*
+ * In this test case, we compare the intervals between two time zones.
+ * List<List<Object>> routines_res_1 = sql """ select
CREATED,LAST_ALTERED from information_schema.routines where
ROUTINE_NAME="TEST_INFORMATION_SCHEMA_TIMEZONE1" """
+ * List<List<Object>> routines_res_2 = sql """ select
CREATED,LAST_ALTERED from information_schema.routines where
ROUTINE_NAME="TEST_INFORMATION_SCHEMA_TIMEZONE2"; """
+ * assertEquals(true, isEightHoursDiff(tables_res_2[0][0],
tables_res_1[0][0]))
+ * If the two SQL queries are executed across the hour mark, it will cause
the test case to fail.
+ * eg. routines_res_1 executed at 00:59:50, and routines_res_2 executed at
01:00:05, assert will fail.
+ * The execution time of this test case is within 2 minutes, and the
interval between the two queries is about 20 seconds.
+ */
+ waitUntilSafeExecutionTime("NOT_CROSS_HOUR_BOUNDARY", 45)
def table_name = "test_information_schema_timezone"
sql """ DROP TABLE IF EXISTS ${table_name} """
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]