Skip to content

Commit

Permalink
fix: add time limit to avoid block
Browse files Browse the repository at this point in the history
  • Loading branch information
Lambert-Rao committed Apr 18, 2024
1 parent 32e4170 commit 2f8366d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public void doCheck(HealthCheckCallback callback) {
}
} catch (NacosException e) {
callback.onFail(e);
} finally {
destroy();
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ public void testStartExecute() throws InterruptedException {
healthExecutor.execute(failHealthCheckService);
//to test startExecute(), we need to call endExecute() first
healthExecutor.endExecute();
Thread.sleep(500);
healthExecutor.startExecute();
HealthCheckResultEntity query = new HealthCheckResultEntity();
query.setClusterId(1L);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.eventmesh.dashboard.console.function.health.check.config.HealthCheckObjectConfig;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -40,14 +41,16 @@ public void init() {
.healthCheckResourceType("meta")
.healthCheckResourceSubType("nacos")
.clusterId(1L)
.connectUrl("127.0.0.1:8848")
.connectUrl("175.27.155.139:8848")
.requestTimeoutMillis(1000L)
.build();
nacosCheck = new NacosConfigCheck(config);
}

@Test
public void testDoCheck() throws InterruptedException {
CountDownLatch latch = new CountDownLatch(1);
Thread.sleep(100);
nacosCheck.doCheck(new HealthCheckCallback() {
@Override
public void onSuccess() {
Expand All @@ -61,7 +64,7 @@ public void onFail(Exception e) {
log.error("{}, failed for reason {}", this.getClass().getSimpleName(), e);
}
});
latch.await();
latch.await(2, TimeUnit.SECONDS);
}

@AfterEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.eventmesh.dashboard.console.function.health.check.config.HealthCheckObjectConfig;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -41,13 +42,15 @@ public void init() {
.healthCheckResourceSubType("nacos")
.clusterId(1L)
.connectUrl("175.27.155.139:8848")
.requestTimeoutMillis(1000L)
.build();
nacosRegisterCheck = new NacosNamingServiceCheck(config);
}

@Test
public void testDoCheck() throws InterruptedException {
CountDownLatch latch = new CountDownLatch(1);
Thread.sleep(100);
nacosRegisterCheck.doCheck(new HealthCheckCallback() {
@Override
public void onSuccess() {
Expand All @@ -61,7 +64,7 @@ public void onFail(Exception e) {
log.error("{}, failed for reason {}", this.getClass().getSimpleName(), e.getMessage());
}
});
latch.await();
latch.await(2, TimeUnit.SECONDS);
}

@AfterEach
Expand Down

0 comments on commit 2f8366d

Please sign in to comment.