[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
This commit is contained in:
Albumen Kevin 2021-04-21 22:43:20 +08:00 committed by GitHub
parent 6e0996654f
commit f8e25ec779
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 109 additions and 29 deletions

View File

@ -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"

View File

@ -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());

View File

@ -177,4 +177,17 @@
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<groupId>org.apache.maven.plugins</groupId>
<configuration>
<forkCount>1</forkCount>
<reuseForks>false</reuseForks>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -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));

View File

@ -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();

View File

@ -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();

View File

@ -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);
}

View File

@ -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

View File

@ -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);
}