Skip to content

Commit a5f0c41

Browse files
cicoyleartursouzadapr-bot
authored
fix the orphaned channel due to the GrpcChannelFacadeTest (#1000)
Signed-off-by: Cassandra Coyle <cassie@diagrid.io> Co-authored-by: Artur Souza <artursouza.ms@outlook.com> Co-authored-by: Dapr Bot <56698301+dapr-bot@users.noreply.github.com>
1 parent f22d8f8 commit a5f0c41

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

sdk/src/test/java/io/dapr/client/GrpcChannelFacadeTest.java

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@
2222
import io.grpc.ServerBuilder;
2323
import io.grpc.inprocess.InProcessChannelBuilder;
2424
import io.grpc.inprocess.InProcessServerBuilder;
25+
import io.grpc.testing.GrpcCleanupRule;
2526
import okhttp3.MediaType;
2627
import okhttp3.OkHttpClient;
2728
import okhttp3.ResponseBody;
2829
import okhttp3.mock.Behavior;
2930
import okhttp3.mock.MockInterceptor;
3031
import org.junit.Before;
32+
import org.junit.Rule;
3133
import org.junit.jupiter.api.AfterAll;
3234
import org.junit.jupiter.api.BeforeAll;
3335
import org.junit.jupiter.api.BeforeEach;
@@ -37,6 +39,7 @@
3739

3840
import java.io.IOException;
3941
import java.time.Duration;
42+
import java.util.concurrent.TimeUnit;
4043
import java.util.concurrent.TimeoutException;
4144

4245
import static io.dapr.utils.TestUtils.findFreePort;
@@ -54,6 +57,9 @@ public class GrpcChannelFacadeTest {
5457

5558
private static DaprHttp daprHttp;
5659

60+
@Rule
61+
public static final GrpcCleanupRule grpcCleanup = new GrpcCleanupRule();
62+
5763
/**
5864
* Enable the waitForSidecar to allow the gRPC to check the http endpoint for the health check
5965
*/
@@ -66,20 +72,19 @@ public void setUp() {
6672
@BeforeAll
6773
public static void setup() throws IOException {
6874
port = findFreePort();
69-
server = ServerBuilder.forPort(port)
75+
76+
// Create a server, add service, start, and register for automatic graceful shutdown.
77+
grpcCleanup.register(ServerBuilder.forPort(port)
7078
.addService(new DaprGrpc.DaprImplBase() {
7179
})
72-
.build();
73-
server.start();
80+
.build().start());
7481
}
7582

7683
@AfterAll
7784
public static void teardown() throws InterruptedException {
7885
if (daprHttp != null) {
7986
daprHttp.close();
8087
}
81-
server.shutdown();
82-
server.awaitTermination();
8388
}
8489

8590
@Test
@@ -88,13 +93,14 @@ public void waitForSidecarTimeoutHealthCheck() throws Exception {
8893
DaprHttp daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3500, okHttpClient);
8994

9095
ManagedChannel channel = InProcessChannelBuilder.forName("waitForSidecarTimeoutHealthCheck").build();
96+
grpcCleanup.register(channel);
9197
final GrpcChannelFacade channelFacade = new GrpcChannelFacade(channel, daprHttp);
9298

93-
mockInterceptor.addRule()
94-
.get()
95-
.path("/v1.0/healthz/outbound")
96-
.times(6)
97-
.respond(404, ResponseBody.create("Not Found", MediaType.get("application/json")));
99+
mockInterceptor.addRule()
100+
.get()
101+
.path("/v1.0/healthz/outbound")
102+
.times(6)
103+
.respond(404, ResponseBody.create("Not Found", MediaType.get("application/json")));
98104

99105
StepVerifier.create(channelFacade.waitForChannelReady(1000))
100106
.expectSubscription()
@@ -110,6 +116,9 @@ public void waitForSidecarOK() {
110116

111117
ManagedChannel channel = ManagedChannelBuilder.forAddress("127.0.0.1", port)
112118
.usePlaintext().build();
119+
120+
grpcCleanup.register(channel);
121+
113122
final GrpcChannelFacade channelFacade = new GrpcChannelFacade(channel, daprHttp);
114123

115124
// added since this is doing a check against the http health check endpoint

0 commit comments

Comments
 (0)