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>
This commit is contained in:
Cassie Coyle 2024-02-15 16:04:46 -06:00 committed by GitHub
parent f22d8f8b68
commit a5f0c41fd6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 19 additions and 10 deletions

View File

@ -22,12 +22,14 @@ import io.grpc.Server;
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;
@ -37,6 +39,7 @@ import reactor.test.scheduler.VirtualTimeScheduler;
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;
@ -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
*/
@ -66,11 +72,12 @@ public class GrpcChannelFacadeTest {
@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
@ -78,8 +85,6 @@ public class GrpcChannelFacadeTest {
if (daprHttp != null) {
daprHttp.close();
}
server.shutdown();
server.awaitTermination();
}
@Test
@ -88,13 +93,14 @@ public class GrpcChannelFacadeTest {
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()
@ -110,6 +116,9 @@ public class GrpcChannelFacadeTest {
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