Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix the orphaned channel due to the GrpcChannelFacadeTest #1000

Merged
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
Loading