Skip to content

Commit

Permalink
[Github-Actions] Improve Test cases (#7592)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
AlbumenJ committed Apr 21, 2021
1 parent 6e09966 commit f8e25ec
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,6 +35,8 @@
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;

Expand Down Expand Up @@ -70,6 +74,7 @@ public void testOnServiceConfigExportedEvent() {
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());
Expand Down
13 changes: 13 additions & 0 deletions dubbo-config/dubbo-config-spring/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,22 @@ public void constructor(final TestInfo testInfo) throws IOException {
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);
Expand All @@ -76,6 +87,7 @@ private static boolean usesAuthentication(final TestInfo testInfo) {
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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@
*/
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;
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;

Expand All @@ -34,25 +35,36 @@
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");
private URL registryUrl;
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
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;
Expand Down Expand Up @@ -79,7 +80,7 @@ public void testAnyHost() {
*/
@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));
Expand Down Expand Up @@ -181,7 +182,7 @@ public void notify(List<URL> urls) {
*/
@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());
}
Expand Down Expand Up @@ -219,7 +220,7 @@ public void testDefaultPort() {
*/
@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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -52,11 +54,22 @@ public void setUp() throws Exception {
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
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;
Expand All @@ -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);
Expand All @@ -70,7 +77,9 @@ public void after() throws Exception {
@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();
}
Expand All @@ -81,10 +90,12 @@ class ThreadNameVerifyHandler implements ChannelHandler {
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() {
Expand Down Expand Up @@ -118,12 +129,14 @@ public void disconnected(Channel channel) throws RemotingException {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,18 @@ public void setUp(final TestInfo testInfo) throws IOException {
.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);
}

Expand Down

0 comments on commit f8e25ec

Please sign in to comment.