From f8e25ec779cfd58df12aed2ff27396b007c6dbad Mon Sep 17 00:00:00 2001 From: Albumen Kevin Date: Wed, 21 Apr 2021 22:43:20 +0800 Subject: [PATCH] [Github-Actions] Improve Test cases (#7592) * make timeout on windows platform larger * PublishingServiceDefinitionListenerTest make port random * make port in MulticastRegistryTest random * add countdownloatch for ThreadNameTest * make fork 1 * move no fork to dubbo-config-spring * separate countDownLatch to client and server * move latch count down time * 3rd party env startup compatible * cover all redis starter * remove roundabout assignment add retry for consul --- .github/workflows/build-and-test.yml | 2 +- ...blishingServiceDefinitionListenerTest.java | 5 ++++ dubbo-config/dubbo-config-spring/pom.xml | 13 +++++++++ .../store/redis/RedisMetadataReportTest.java | 22 +++++++++++---- .../registry/consul/ConsulRegistryTest.java | 28 +++++++++++++------ .../multicast/MulticastRegistryTest.java | 7 +++-- .../registry/redis/RedisRegistryTest.java | 25 +++++++++++++---- .../transport/netty/ThreadNameTest.java | 23 +++++++++++---- .../rpc/protocol/redis/RedisProtocolTest.java | 13 ++++++++- 9 files changed, 109 insertions(+), 29 deletions(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 50088d255e..6a54bf1e7a 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -77,7 +77,7 @@ jobs: - name: "Test with Maven without Integration Tests" env: DISABLE_FILE_SYSTEM_TEST: true - timeout-minutes: 40 + timeout-minutes: 50 if: ${{ startsWith( matrix.os, 'windows') }} run: ./mvnw --batch-mode -U -e --no-transfer-progress clean test verify -D"http.keepAlive=false" -D"maven.wagon.http.pool=false" -D"maven.wagon.httpconnectionManager.ttlSeconds=120" -D"maven.wagon.http.retryHandler.count=5" -DskipTests=false -DskipIntegrationTests=true -D"checkstyle.skip=false" -D"rat.skip=false" -D"maven.javadoc.skip=true" - name: "Pack rat file if failure" diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/event/listener/PublishingServiceDefinitionListenerTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/event/listener/PublishingServiceDefinitionListenerTest.java index c2445573ca..b4a035625a 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/event/listener/PublishingServiceDefinitionListenerTest.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/event/listener/PublishingServiceDefinitionListenerTest.java @@ -16,7 +16,9 @@ */ package org.apache.dubbo.config.event.listener; +import org.apache.dubbo.common.utils.NetUtils; import org.apache.dubbo.config.ApplicationConfig; +import org.apache.dubbo.config.ProtocolConfig; import org.apache.dubbo.config.RegistryConfig; import org.apache.dubbo.config.ServiceConfig; import org.apache.dubbo.config.bootstrap.EchoService; @@ -33,6 +35,8 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import java.util.Random; + import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_METADATA_STORAGE_TYPE; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -70,6 +74,7 @@ public class PublishingServiceDefinitionListenerTest { serviceConfig.setInterface(EchoService.class); serviceConfig.setRef(new EchoServiceImpl()); serviceConfig.setRegistry(new RegistryConfig("N/A")); + serviceConfig.setProtocol(new ProtocolConfig("dubbo", NetUtils.getAvailablePort(20880 + new Random().nextInt(10000)))); serviceConfig.export(); String serviceDefinition = writableMetadataService.getServiceDefinition(EchoService.class.getName()); diff --git a/dubbo-config/dubbo-config-spring/pom.xml b/dubbo-config/dubbo-config-spring/pom.xml index ae7f3bcc1f..9c76911ec2 100644 --- a/dubbo-config/dubbo-config-spring/pom.xml +++ b/dubbo-config/dubbo-config-spring/pom.xml @@ -177,4 +177,17 @@ + + + + + maven-surefire-plugin + org.apache.maven.plugins + + 1 + false + + + + diff --git a/dubbo-metadata/dubbo-metadata-report-redis/src/test/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReportTest.java b/dubbo-metadata/dubbo-metadata-report-redis/src/test/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReportTest.java index f666ded84f..2af741feb1 100644 --- a/dubbo-metadata/dubbo-metadata-report-redis/src/test/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReportTest.java +++ b/dubbo-metadata/dubbo-metadata-report-redis/src/test/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReportTest.java @@ -62,11 +62,22 @@ public class RedisMetadataReportTest { final boolean usesAuthentication = usesAuthentication(testInfo); redisServer = newRedisServer() - .port(redisPort) - .settingIf(usesAuthentication, "requirepass " + REDIS_PASSWORD) - .settingIf(IS_OS_WINDOWS, "maxheap 128mb") - .build(); - redisServer.start(); + .port(redisPort) + .settingIf(usesAuthentication, "requirepass " + REDIS_PASSWORD) + .settingIf(IS_OS_WINDOWS, "maxheap 128mb") + .build(); + IOException exception = null; + for (int i = 0; i < 10; i++) { + try { + this.redisServer.start(); + } catch (IOException e) { + exception = e; + } + if (exception == null) { + break; + } + } + Assertions.assertNull(exception); registryUrl = newRedisUrl(usesAuthentication, redisPort); redisMetadataReport = (RedisMetadataReport) new RedisMetadataReportFactory().createMetadataReport(registryUrl); syncRedisMetadataReport = (RedisMetadataReport) new RedisMetadataReportFactory().createMetadataReport(registryUrl); @@ -76,6 +87,7 @@ public class RedisMetadataReportTest { final String methodName = testInfo.getTestMethod().get().getName(); return "testAuthRedisMetadata".equals(methodName) || "testWrongAuthRedisMetadata".equals(methodName); } + private static URL newRedisUrl(final boolean usesAuthentication, final int redisPort) { final String urlAuthSection = usesAuthentication ? REDIS_URL_AUTH_SECTION : ""; return URL.valueOf(String.format(REDIS_URL_TEMPLATE, urlAuthSection, redisPort)); diff --git a/dubbo-registry/dubbo-registry-consul/src/test/java/org/apache/dubbo/registry/consul/ConsulRegistryTest.java b/dubbo-registry/dubbo-registry-consul/src/test/java/org/apache/dubbo/registry/consul/ConsulRegistryTest.java index f0a3db923c..792f258480 100644 --- a/dubbo-registry/dubbo-registry-consul/src/test/java/org/apache/dubbo/registry/consul/ConsulRegistryTest.java +++ b/dubbo-registry/dubbo-registry-consul/src/test/java/org/apache/dubbo/registry/consul/ConsulRegistryTest.java @@ -16,8 +16,6 @@ */ package org.apache.dubbo.registry.consul; -import com.pszymczyk.consul.ConsulProcess; -import com.pszymczyk.consul.ConsulStarterBuilder; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.status.Status; import org.apache.dubbo.common.utils.NetUtils; @@ -25,7 +23,10 @@ import org.apache.dubbo.registry.NotifyListener; import org.apache.dubbo.registry.Registry; import org.apache.dubbo.registry.status.RegistryStatusChecker; +import com.pszymczyk.consul.ConsulProcess; +import com.pszymczyk.consul.ConsulStarterBuilder; import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -34,14 +35,14 @@ import java.util.Map; import java.util.Set; import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.mock; public class ConsulRegistryTest { - private static ConsulProcess consul; + private ConsulProcess consul; private ConsulRegistry consulRegistry; private String service = "org.apache.dubbo.test.injvmServie"; private URL serviceUrl = URL.valueOf("consul://127.0.0.1:" + NetUtils.getAvailablePort() + "/" + service + "?notify=false&methods=test1,test2"); @@ -49,10 +50,21 @@ public class ConsulRegistryTest { private ConsulRegistryFactory consulRegistryFactory; @BeforeEach - public void setUp() throws Exception { - this.consul = ConsulStarterBuilder.consulStarter() - .build() - .start(); + public void setUp() { + Exception exception = null; + for (int i = 0; i < 10; i++) { + try { + this.consul = ConsulStarterBuilder.consulStarter() + .build() + .start(); + } catch (Exception e) { + exception = e; + } + if (exception == null) { + break; + } + } + Assertions.assertNull(exception); this.registryUrl = URL.valueOf("consul://localhost:" + consul.getHttpPort()); consulRegistryFactory = new ConsulRegistryFactory(); diff --git a/dubbo-registry/dubbo-registry-multicast/src/test/java/org/apache/dubbo/registry/multicast/MulticastRegistryTest.java b/dubbo-registry/dubbo-registry-multicast/src/test/java/org/apache/dubbo/registry/multicast/MulticastRegistryTest.java index d666a558dd..aef45ee975 100644 --- a/dubbo-registry/dubbo-registry-multicast/src/test/java/org/apache/dubbo/registry/multicast/MulticastRegistryTest.java +++ b/dubbo-registry/dubbo-registry-multicast/src/test/java/org/apache/dubbo/registry/multicast/MulticastRegistryTest.java @@ -28,6 +28,7 @@ import java.net.InetAddress; import java.net.MulticastSocket; import java.util.List; import java.util.Map; +import java.util.Random; import java.util.Set; import static org.apache.dubbo.common.constants.RegistryConstants.EMPTY_PROTOCOL; @@ -79,7 +80,7 @@ public class MulticastRegistryTest { */ @Test public void testGetCustomPort() { - int port = NetUtils.getAvailablePort(); + int port = NetUtils.getAvailablePort(20880 + new Random().nextInt(10000)); URL customPortUrl = URL.valueOf("multicast://239.239.239.239:" + port); MulticastRegistry multicastRegistry = new MulticastRegistry(customPortUrl); assertThat(multicastRegistry.getUrl().getPort(), is(port)); @@ -181,7 +182,7 @@ public class MulticastRegistryTest { */ @Test public void testAvailability() { - int port = NetUtils.getAvailablePort(); + int port = NetUtils.getAvailablePort(20880 + new Random().nextInt(10000)); MulticastRegistry registry = new MulticastRegistry(URL.valueOf("multicast://224.5.6.8:" + port)); assertTrue(registry.isAvailable()); } @@ -219,7 +220,7 @@ public class MulticastRegistryTest { */ @Test public void testCustomedPort() { - int port = NetUtils.getAvailablePort(); + int port = NetUtils.getAvailablePort(20880 + new Random().nextInt(10000)); MulticastRegistry multicastRegistry = new MulticastRegistry(URL.valueOf("multicast://224.5.6.7:" + port)); try { MulticastSocket multicastSocket = multicastRegistry.getMulticastSocket(); diff --git a/dubbo-registry/dubbo-registry-redis/src/test/java/org/apache/dubbo/registry/redis/RedisRegistryTest.java b/dubbo-registry/dubbo-registry-redis/src/test/java/org/apache/dubbo/registry/redis/RedisRegistryTest.java index 0deeb57c7e..9fbc85646f 100644 --- a/dubbo-registry/dubbo-registry-redis/src/test/java/org/apache/dubbo/registry/redis/RedisRegistryTest.java +++ b/dubbo-registry/dubbo-registry-redis/src/test/java/org/apache/dubbo/registry/redis/RedisRegistryTest.java @@ -16,18 +16,20 @@ */ package org.apache.dubbo.registry.redis; -import org.apache.commons.lang3.SystemUtils; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.utils.NetUtils; import org.apache.dubbo.registry.NotifyListener; import org.apache.dubbo.registry.Registry; +import org.apache.commons.lang3.SystemUtils; import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import redis.clients.jedis.exceptions.JedisConnectionException; import redis.embedded.RedisServer; +import java.io.IOException; import java.util.List; import java.util.Map; import java.util.Set; @@ -52,11 +54,22 @@ public class RedisRegistryTest { final int redisPort = NetUtils.getAvailablePort(); redisServer = newRedisServer() - .port(redisPort) - // set maxheap to fix Windows error 0x70 while starting redis - .settingIf(SystemUtils.IS_OS_WINDOWS, "maxheap 128mb") - .build(); - redisServer.start(); + .port(redisPort) + // set maxheap to fix Windows error 0x70 while starting redis + .settingIf(SystemUtils.IS_OS_WINDOWS, "maxheap 128mb") + .build(); + IOException exception = null; + for (int i = 0; i < 10; i++) { + try { + this.redisServer.start(); + } catch (IOException e) { + exception = e; + } + if (exception == null) { + break; + } + } + Assertions.assertNull(exception); registryUrl = URL.valueOf("redis://localhost:" + redisPort); redisRegistry = (RedisRegistry) new RedisRegistryFactory().createRegistry(registryUrl); } diff --git a/dubbo-remoting/dubbo-remoting-netty/src/test/java/org/apache/dubbo/remoting/transport/netty/ThreadNameTest.java b/dubbo-remoting/dubbo-remoting-netty/src/test/java/org/apache/dubbo/remoting/transport/netty/ThreadNameTest.java index 3783d024b5..77d833d676 100644 --- a/dubbo-remoting/dubbo-remoting-netty/src/test/java/org/apache/dubbo/remoting/transport/netty/ThreadNameTest.java +++ b/dubbo-remoting/dubbo-remoting-netty/src/test/java/org/apache/dubbo/remoting/transport/netty/ThreadNameTest.java @@ -27,6 +27,10 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import java.util.Random; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + public class ThreadNameTest { private NettyServer server; @@ -41,14 +45,17 @@ public class ThreadNameTest { private static String serverRegex = "DubboServerHandler\\-localhost:(\\d+)\\-thread\\-(\\d+)"; private static String clientRegex = "DubboClientHandler\\-thread\\-(\\d+)"; + private final CountDownLatch serverLatch = new CountDownLatch(1); + private final CountDownLatch clientLatch = new CountDownLatch(1); + @BeforeEach public void before() throws Exception { - int port = NetUtils.getAvailablePort(); + int port = NetUtils.getAvailablePort(20880 + new Random().nextInt(10000)); serverURL = URL.valueOf("telnet://localhost?side=provider").setPort(port); clientURL = URL.valueOf("telnet://localhost?side=consumer").setPort(port); - serverHandler = new ThreadNameVerifyHandler(serverRegex, false); - clientHandler = new ThreadNameVerifyHandler(clientRegex, true); + serverHandler = new ThreadNameVerifyHandler(serverRegex, false, serverLatch); + clientHandler = new ThreadNameVerifyHandler(clientRegex, true, clientLatch); server = new NettyServer(serverURL, serverHandler); client = new NettyClient(clientURL, clientHandler); @@ -70,7 +77,9 @@ public class ThreadNameTest { @Test public void testThreadName() throws Exception { client.send("hello"); - Thread.sleep(1000L * 5L); + //Thread.sleep(1000L * 5L); + serverLatch.await(30, TimeUnit.SECONDS); + clientLatch.await(30, TimeUnit.SECONDS); if (!serverHandler.isSuccess() || !clientHandler.isSuccess()) { Assertions.fail(); } @@ -81,10 +90,12 @@ public class ThreadNameTest { private String message; private boolean success; private boolean client; + private CountDownLatch latch; - ThreadNameVerifyHandler(String msg, boolean client) { + ThreadNameVerifyHandler(String msg, boolean client, CountDownLatch latch) { message = msg; this.client = client; + this.latch = latch; } public boolean isSuccess() { @@ -118,12 +129,14 @@ public class ThreadNameTest { public void sent(Channel channel, Object message) throws RemotingException { output("sent"); checkThreadName(); + latch.countDown(); } @Override public void received(Channel channel, Object message) throws RemotingException { output("received"); checkThreadName(); + latch.countDown(); } @Override diff --git a/dubbo-rpc/dubbo-rpc-redis/src/test/java/org/apache/dubbo/rpc/protocol/redis/RedisProtocolTest.java b/dubbo-rpc/dubbo-rpc-redis/src/test/java/org/apache/dubbo/rpc/protocol/redis/RedisProtocolTest.java index 279a7e60d4..7e7dbcf1c7 100644 --- a/dubbo-rpc/dubbo-rpc-redis/src/test/java/org/apache/dubbo/rpc/protocol/redis/RedisProtocolTest.java +++ b/dubbo-rpc/dubbo-rpc-redis/src/test/java/org/apache/dubbo/rpc/protocol/redis/RedisProtocolTest.java @@ -72,7 +72,18 @@ public class RedisProtocolTest { .settingIf(usesAuthentication, "requirepass " + REDIS_PASSWORD) .settingIf(IS_OS_WINDOWS, "maxheap 128mb") .build(); - redisServer.start(); + IOException exception = null; + for (int i = 0; i < 10; i++) { + try { + this.redisServer.start(); + } catch (IOException e) { + exception = e; + } + if (exception == null) { + break; + } + } + Assertions.assertNull(exception); registryUrl = newRedisUrl(usesAuthentication, redisPort); }