Skip to content

Commit

Permalink
fix the orphaned channel due to the GrpcChannelFacadeTest (#1000)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
3 people authored Feb 15, 2024
1 parent f22d8f8 commit a5f0c41
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions sdk/src/test/java/io/dapr/client/GrpcChannelFacadeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@
import io.grpc.ServerBuilder;
import io.grpc.inprocess.InProcessChannelBuilder;
import io.grpc.inprocess.InProcessServerBuilder;
import io.grpc.testing.GrpcCleanupRule;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.ResponseBody;
import okhttp3.mock.Behavior;
import okhttp3.mock.MockInterceptor;
import org.junit.Before;
import org.junit.Rule;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -37,6 +39,7 @@

import java.io.IOException;
import java.time.Duration;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

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

private static DaprHttp daprHttp;

@Rule
public static final GrpcCleanupRule grpcCleanup = new GrpcCleanupRule();

/**
* Enable the waitForSidecar to allow the gRPC to check the http endpoint for the health check
*/
Expand All @@ -66,20 +72,19 @@ public void setUp() {
@BeforeAll
public static void setup() throws IOException {
port = findFreePort();
server = ServerBuilder.forPort(port)

// Create a server, add service, start, and register for automatic graceful shutdown.
grpcCleanup.register(ServerBuilder.forPort(port)
.addService(new DaprGrpc.DaprImplBase() {
})
.build();
server.start();
.build().start());
}

@AfterAll
public static void teardown() throws InterruptedException {
if (daprHttp != null) {
daprHttp.close();
}
server.shutdown();
server.awaitTermination();
}

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

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

mockInterceptor.addRule()
.get()
.path("/v1.0/healthz/outbound")
.times(6)
.respond(404, ResponseBody.create("Not Found", MediaType.get("application/json")));
mockInterceptor.addRule()
.get()
.path("/v1.0/healthz/outbound")
.times(6)
.respond(404, ResponseBody.create("Not Found", MediaType.get("application/json")));

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

ManagedChannel channel = ManagedChannelBuilder.forAddress("127.0.0.1", port)
.usePlaintext().build();

grpcCleanup.register(channel);

final GrpcChannelFacade channelFacade = new GrpcChannelFacade(channel, daprHttp);

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

0 comments on commit a5f0c41

Please sign in to comment.