This is an automated email from the ASF dual-hosted git repository.
xiaoyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new b573b8c00 test: replace `Thread.sleep` with `Awaitility` (#4244)
b573b8c00 is described below
commit b573b8c000ecd96d4c9cdeebf037bfe2757355f4
Author: youzipi <[email protected]>
AuthorDate: Sun Dec 25 16:56:47 2022 +0800
test: replace `Thread.sleep` with `Awaitility` (#4244)
Co-authored-by: xiaoyu <[email protected]>
---
shenyu-plugin/shenyu-plugin-mqtt/pom.xml | 6 ++++++
.../shenyu/plugin/mqtt/handler/MqttPluginDataHandlerTest.java | 8 ++++++--
2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/shenyu-plugin/shenyu-plugin-mqtt/pom.xml
b/shenyu-plugin/shenyu-plugin-mqtt/pom.xml
index 2094b5f52..65a339267 100644
--- a/shenyu-plugin/shenyu-plugin-mqtt/pom.xml
+++ b/shenyu-plugin/shenyu-plugin-mqtt/pom.xml
@@ -38,6 +38,12 @@
<artifactId>shenyu-plugin-base</artifactId>
<version>${project.version}</version>
</dependency>
+
+ <dependency>
+ <groupId>org.awaitility</groupId>
+ <artifactId>awaitility</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
\ No newline at end of file
diff --git
a/shenyu-plugin/shenyu-plugin-mqtt/src/test/java/org/apache/shenyu/plugin/mqtt/handler/MqttPluginDataHandlerTest.java
b/shenyu-plugin/shenyu-plugin-mqtt/src/test/java/org/apache/shenyu/plugin/mqtt/handler/MqttPluginDataHandlerTest.java
index 14ca4fbe0..2fecf5b8a 100644
---
a/shenyu-plugin/shenyu-plugin-mqtt/src/test/java/org/apache/shenyu/plugin/mqtt/handler/MqttPluginDataHandlerTest.java
+++
b/shenyu-plugin/shenyu-plugin-mqtt/src/test/java/org/apache/shenyu/plugin/mqtt/handler/MqttPluginDataHandlerTest.java
@@ -18,11 +18,13 @@
package org.apache.shenyu.plugin.mqtt.handler;
import org.apache.shenyu.common.dto.PluginData;
+import org.awaitility.Awaitility;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.net.InetAddress;
import java.net.Socket;
+import java.util.concurrent.TimeUnit;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -66,8 +68,10 @@ public class MqttPluginDataHandlerTest {
+ " \"leakDetectorLevel\": \"DISABLED\""
+ "}", "0", false);
mqttPluginDataHandlerUnderTest.handlerPlugin(disablePluginData);
- Thread.sleep(5000);
- assertFalse(isPortUsing());
+
+ Awaitility.await()
+ .atMost(5, TimeUnit.SECONDS)
+ .untilAsserted(() -> assertFalse(isPortUsing()));
}
private boolean isPortUsing() {