Skip to content

Commit

Permalink
Enhance Unit test stability. (alibaba#8346)
Browse files Browse the repository at this point in the history
* Enhance Unit test stability.

* print detail stacktrace when unit test error.
  • Loading branch information
KomachiSion authored May 11, 2022
1 parent ed999d9 commit 3998026
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- name: Build with Maven
run: mvn -Prelease-nacos -Dmaven.test.skip=true clean install -U
- name: Test With Maven
run: mvn -Prelease-nacos clean test
run: mvn -Prelease-nacos clean test -DtrimStackTrace=false
- name: Codecov
uses: codecov/codecov-action@v3.1.0
with:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,19 @@ public class UdpConnector {

private final DatagramSocket udpSocket;

private volatile boolean running = true;

public UdpConnector() throws SocketException {
this.ackMap = new ConcurrentHashMap<>();
this.callbackMap = new ConcurrentHashMap<>();
this.udpSocket = new DatagramSocket();
GlobalExecutor.scheduleUdpReceiver(new UdpReceiver());
}

public void shutdown() {
running = false;
}

public boolean containAck(String ackId) {
return ackMap.containsKey(ackId);
}
Expand Down Expand Up @@ -180,7 +186,7 @@ private class UdpReceiver implements Runnable {

@Override
public void run() {
while (true) {
while (running) {
byte[] buffer = new byte[1024 * 64];
DatagramPacket packet = new DatagramPacket(buffer, buffer.length);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.alibaba.nacos.naming.core.v2.client.manager.ClientManager;
import com.alibaba.nacos.naming.misc.SwitchDomain;
import com.alibaba.nacos.naming.misc.SwitchManager;
import com.alibaba.nacos.naming.monitor.MetricsMonitor;
import com.alibaba.nacos.sys.env.Constants;
import com.alibaba.nacos.sys.env.EnvUtil;
import com.fasterxml.jackson.databind.node.ObjectNode;
Expand Down Expand Up @@ -86,6 +87,7 @@ public void setUp() {

@Test
public void testPushState() {
MetricsMonitor.resetPush();
ObjectNode objectNode = operatorController.pushState(true, true);
Assert.assertTrue(objectNode.toString().contains("succeed\":0"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.remote.PushCallBack;
import com.alibaba.nacos.sys.env.EnvUtil;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
Expand Down Expand Up @@ -82,6 +83,11 @@ public void setUp() throws IOException, InterruptedException {
TimeUnit.SECONDS.sleep(1);
}

@After
public void tearDown() {
udpConnector.shutdown();
}

@Test
public void testContainAck() {
when(ackMap.containsKey(Mockito.anyString())).thenReturn(true);
Expand Down

0 comments on commit 3998026

Please sign in to comment.