Skip to content

Commit 72f54d4

Browse files
authored
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
1 parent cee2798 commit 72f54d4

3 files changed

Lines changed: 8 additions & 15 deletions

File tree

test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/storage/type/DockerStorageContainer.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,12 @@ private String getURL() {
132132
.orElseGet(() -> option.getConnectOption().getURL("localhost", getFirstMappedPort()));
133133
}
134134

135-
@SneakyThrows({SQLException.class, InterruptedException.class})
135+
@SneakyThrows(SQLException.class)
136136
@Override
137137
protected void containerIsStarted(final InspectContainerResponse containerInfo) {
138138
if (option.getCreateOption().isSupportDockerEntrypoint()) {
139139
return;
140140
}
141-
Thread.sleep(10000L);
142141
try (
143142
Connection connection = DriverManager.getConnection(option.getConnectOption().getURL("localhost", getFirstMappedPort()),
144143
option.getCreateOption().getDefaultUserWhenUnsupportedDockerEntrypoint().orElse(""),

test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/operation/pipeline/cases/migration/general/PostgreSQLToMySQLMigrationE2EIT.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
package org.apache.shardingsphere.test.e2e.operation.pipeline.cases.migration.general;
1919

20-
import lombok.SneakyThrows;
2120
import lombok.extern.slf4j.Slf4j;
2221
import org.apache.commons.lang3.RandomStringUtils;
2322
import org.apache.commons.lang3.RandomUtils;
@@ -35,6 +34,7 @@
3534
import org.apache.shardingsphere.test.e2e.operation.pipeline.framework.param.PipelineE2ETestCaseArgumentsProvider;
3635
import org.apache.shardingsphere.test.e2e.operation.pipeline.framework.param.PipelineTestParameter;
3736
import org.awaitility.Awaitility;
37+
import org.awaitility.core.ConditionTimeoutException;
3838
import org.junit.jupiter.api.condition.EnabledIf;
3939
import org.junit.jupiter.params.ParameterizedTest;
4040
import org.junit.jupiter.params.provider.ArgumentsSource;
@@ -150,17 +150,13 @@ private void initTargetTable(final PipelineContainerComposer containerComposer)
150150
}
151151
}
152152

153-
@SneakyThrows
154153
private static boolean waitForTableExistence(final Connection connection, final String tableName) {
155-
int elapsedTime = 0;
156-
while (elapsedTime < 60) {
157-
if (tableExists(connection, tableName)) {
158-
return true;
159-
}
160-
Thread.sleep(3 * 1000L);
161-
elapsedTime += 3;
154+
try {
155+
Awaitility.await().ignoreExceptions().atMost(60L, TimeUnit.SECONDS).pollInterval(3L, TimeUnit.SECONDS).until(() -> tableExists(connection, tableName));
156+
return true;
157+
} catch (final ConditionTimeoutException ex) {
158+
return false;
162159
}
163-
return false;
164160
}
165161

166162
private static boolean tableExists(final Connection connection, final String tableName) throws SQLException {

test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/sql/it/sql/dal/DALE2EIT.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,8 @@ private void assertExecute(final SQLE2EITContext context) throws SQLException {
7474
try (Connection connection = environmentEngine.getTargetDataSource().getConnection()) {
7575
try (Statement statement = connection.createStatement()) {
7676
statement.execute(context.getSQL());
77-
Thread.sleep(1000L);
77+
Awaitility.await().pollDelay(1L, TimeUnit.SECONDS).until(() -> true);
7878
assertExecuteResult(context, statement);
79-
} catch (final InterruptedException ignore) {
80-
Thread.currentThread().interrupt();
8179
}
8280
} finally {
8381
tearDown(context);

0 commit comments

Comments
 (0)