This is an automated email from the ASF dual-hosted git repository.
zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 72f54d49ccd Introduce the awaitility framework to replace Thread.sleep
in E2E (#37384)
72f54d49ccd is described below
commit 72f54d49ccd67d66d347933fc625d5adfeafcd44
Author: Liang Zhang <[email protected]>
AuthorDate: Sun Dec 14 22:01:17 2025 +0800
Introduce the awaitility framework to replace Thread.sleep in E2E (#37384)
* Add document and test cases on DistSQL of manage SQL_TRANSLATOR rule
* Add document and test cases on DistSQL of manage SQL_TRANSLATOR rule
* Add document and test cases on DistSQL of manage SQL_TRANSLATOR rule
* Add document and test cases on DistSQL of manage SQL_TRANSLATOR rule
* Introduce the awaitility framework to replace Thread.sleep in E2E
* Introduce the awaitility framework to replace Thread.sleep in E2E
* Introduce the awaitility framework to replace Thread.sleep in E2E
* Introduce the awaitility framework to replace Thread.sleep in E2E
---
.../container/storage/type/DockerStorageContainer.java | 3 +--
.../general/PostgreSQLToMySQLMigrationE2EIT.java | 16 ++++++----------
.../shardingsphere/test/e2e/sql/it/sql/dal/DALE2EIT.java | 4 +---
3 files changed, 8 insertions(+), 15 deletions(-)
diff --git
a/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/storage/type/DockerStorageContainer.java
b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/storage/type/DockerStorageContainer.java
index ffe3ff381f0..14fbcdc71ef 100644
---
a/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/storage/type/DockerStorageContainer.java
+++
b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/storage/type/DockerStorageContainer.java
@@ -132,13 +132,12 @@ public final class DockerStorageContainer extends
DockerE2EContainer implements
.orElseGet(() -> option.getConnectOption().getURL("localhost",
getFirstMappedPort()));
}
- @SneakyThrows({SQLException.class, InterruptedException.class})
+ @SneakyThrows(SQLException.class)
@Override
protected void containerIsStarted(final InspectContainerResponse
containerInfo) {
if (option.getCreateOption().isSupportDockerEntrypoint()) {
return;
}
- Thread.sleep(10000L);
try (
Connection connection =
DriverManager.getConnection(option.getConnectOption().getURL("localhost",
getFirstMappedPort()),
option.getCreateOption().getDefaultUserWhenUnsupportedDockerEntrypoint().orElse(""),
diff --git
a/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/operation/pipeline/cases/migration/general/PostgreSQLToMySQLMigrationE2EIT.java
b/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/operation/pipeline/cases/migration/general/PostgreSQLToMySQLMigrationE2EIT.java
index cb27f7301f3..694e3707a27 100644
---
a/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/operation/pipeline/cases/migration/general/PostgreSQLToMySQLMigrationE2EIT.java
+++
b/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/operation/pipeline/cases/migration/general/PostgreSQLToMySQLMigrationE2EIT.java
@@ -17,7 +17,6 @@
package
org.apache.shardingsphere.test.e2e.operation.pipeline.cases.migration.general;
-import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.RandomUtils;
@@ -35,6 +34,7 @@ import
org.apache.shardingsphere.test.e2e.operation.pipeline.framework.param.Pip
import
org.apache.shardingsphere.test.e2e.operation.pipeline.framework.param.PipelineE2ETestCaseArgumentsProvider;
import
org.apache.shardingsphere.test.e2e.operation.pipeline.framework.param.PipelineTestParameter;
import org.awaitility.Awaitility;
+import org.awaitility.core.ConditionTimeoutException;
import org.junit.jupiter.api.condition.EnabledIf;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ArgumentsSource;
@@ -150,17 +150,13 @@ class PostgreSQLToMySQLMigrationE2EIT extends
AbstractMigrationE2EIT {
}
}
- @SneakyThrows
private static boolean waitForTableExistence(final Connection connection,
final String tableName) {
- int elapsedTime = 0;
- while (elapsedTime < 60) {
- if (tableExists(connection, tableName)) {
- return true;
- }
- Thread.sleep(3 * 1000L);
- elapsedTime += 3;
+ try {
+ Awaitility.await().ignoreExceptions().atMost(60L,
TimeUnit.SECONDS).pollInterval(3L, TimeUnit.SECONDS).until(() ->
tableExists(connection, tableName));
+ return true;
+ } catch (final ConditionTimeoutException ex) {
+ return false;
}
- return false;
}
private static boolean tableExists(final Connection connection, final
String tableName) throws SQLException {
diff --git
a/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/sql/it/sql/dal/DALE2EIT.java
b/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/sql/it/sql/dal/DALE2EIT.java
index b52d0df479d..81351799aaf 100644
---
a/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/sql/it/sql/dal/DALE2EIT.java
+++
b/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/sql/it/sql/dal/DALE2EIT.java
@@ -74,10 +74,8 @@ class DALE2EIT implements SQLE2EIT {
try (Connection connection =
environmentEngine.getTargetDataSource().getConnection()) {
try (Statement statement = connection.createStatement()) {
statement.execute(context.getSQL());
- Thread.sleep(1000L);
+ Awaitility.await().pollDelay(1L, TimeUnit.SECONDS).until(() ->
true);
assertExecuteResult(context, statement);
- } catch (final InterruptedException ignore) {
- Thread.currentThread().interrupt();
}
} finally {
tearDown(context);