From b2968af89609ec6bcb4fcd19c70e14b5830d2756 Mon Sep 17 00:00:00 2001 From: Cassie Coyle Date: Thu, 8 Feb 2024 16:47:32 -0600 Subject: [PATCH] Resolve buildGrpcManagedChannel orphaned channel & ensure connections mocked (#1003) * okhttpclient is mocked Signed-off-by: Cassandra Coyle * mock workflowRuntime to rm log: 'The sidecar at address localhost:4001 is unavailable. Will continue retrying.' Signed-off-by: Cassandra Coyle * fix several NetworkUtilsTest orphaned channels Signed-off-by: Cassandra Coyle * reset workflow changes since I still see the log output Signed-off-by: Cassandra Coyle * Close daprClient on DaprClientGrpcTelemetryTest Signed-off-by: Artur Souza * try latest runtime rc Signed-off-by: Cassandra Coyle * Update runtime to 1.12.4 Signed-off-by: Artur Souza * Mvn test is now verbose, temporatily. Signed-off-by: Artur Souza * try fixing RetryPolicyTest Signed-off-by: Cassandra Coyle * comment out RetryPolicyTest Signed-off-by: Cassandra Coyle * add RetryPolicyTest back Signed-off-by: Cassandra Coyle * trying to figure out which test func is the issue Signed-off-by: Cassandra Coyle * try ubuntu-20.04 Signed-off-by: Cassandra Coyle * try rm-ing GrpcChannelFacadeTest Signed-off-by: Cassandra Coyle * try rm-ing DaprClientHttpTest Signed-off-by: Cassandra Coyle * try t.join just in case Signed-off-by: Cassandra Coyle * is this the bad test? Signed-off-by: Cassandra Coyle * are these other healthcheck tests the problem? Signed-off-by: Cassandra Coyle * is it the ok test? Signed-off-by: Cassandra Coyle * is it due to an invoke test? Signed-off-by: Cassandra Coyle * is it the config/subscribeConfig tests Signed-off-by: Cassandra Coyle * is it noHotMono? Signed-off-by: Cassandra Coyle * is it a publish test? Signed-off-by: Cassandra Coyle * is it the other noHotMono tests? Signed-off-by: Cassandra Coyle * is it a state test? Signed-off-by: Cassandra Coyle * is it a save state test? Signed-off-by: Cassandra Coyle * is it a secret test? Signed-off-by: Cassandra Coyle * is it a delete state test? Signed-off-by: Cassandra Coyle * is it the rest -1 and - ending tests? Signed-off-by: Cassandra Coyle * no client calls, only end of file remaining Signed-off-by: Cassandra Coyle * add teardown - did it work? Signed-off-by: Cassandra Coyle * is it just needing daprClientHttpXML to be closed? Signed-off-by: Cassandra Coyle * Reuse mock and builder. Signed-off-by: Artur Souza * Try dedicated executor. Signed-off-by: Artur Souza * Comment out the remaining tests. Signed-off-by: Artur Souza * Remove before and after. Signed-off-by: Artur Souza * Remove sdk/src/test/java/io/dapr/client/DaprClientHttpTest.java Signed-off-by: Artur Souza * Remove sdk/src/test/java/io/dapr/client/DaprHttpTest.java. Signed-off-by: Artur Souza * Delete a batch of tests. Signed-off-by: Artur Souza * restore deleted test files Signed-off-by: Cassandra Coyle * add back in RetryPolicyTest Signed-off-by: Cassandra Coyle --------- Signed-off-by: Cassandra Coyle Signed-off-by: Artur Souza Co-authored-by: Artur Souza Co-authored-by: Artur Souza --- .github/workflows/build.yml | 8 +++--- .github/workflows/validate.yml | 6 ++--- .../client/DaprClientGrpcTelemetryTest.java | 10 ++++++-- .../java/io/dapr/utils/NetworkUtilsTest.java | 25 +++++++++++++++---- 4 files changed, 35 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2718206dd..ba34ff9af 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -41,9 +41,9 @@ jobs: GOARCH: amd64 GOPROXY: https://proxy.golang.org JDK_VER: ${{ matrix.java }} - DAPR_CLI_VER: 1.12.0-rc.1 - DAPR_RUNTIME_VER: 1.12.0-rc.5 - DAPR_INSTALL_URL: https://raw.githubusercontent.com/dapr/cli/v1.12.0-rc.1/install/install.sh + DAPR_CLI_VER: 1.12.0 + DAPR_RUNTIME_VER: 1.12.4 + DAPR_INSTALL_URL: https://raw.githubusercontent.com/dapr/cli/v1.12.0/install/install.sh DAPR_CLI_REF: DAPR_REF: TOXIPROXY_URL: https://github.com/Shopify/toxiproxy/releases/download/v2.5.0/toxiproxy-server-linux-amd64 @@ -115,7 +115,7 @@ jobs: - name: Build sdk run: ./mvnw compile -B -q - name: Unit tests - run: ./mvnw -B test -q + run: ./mvnw test # making it temporarily verbose. - name: Codecov uses: codecov/codecov-action@v3.1.4 - name: Install jars diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index ad67a0787..d476892c9 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -37,9 +37,9 @@ jobs: GOARCH: amd64 GOPROXY: https://proxy.golang.org JDK_VER: ${{ matrix.java }} - DAPR_CLI_VER: 1.12.0-rc.1 - DAPR_RUNTIME_VER: 1.12.0-rc.5 - DAPR_INSTALL_URL: https://raw.githubusercontent.com/dapr/cli/v1.12.0-rc.1/install/install.sh + DAPR_CLI_VER: 1.12.0 + DAPR_RUNTIME_VER: 1.12.4 + DAPR_INSTALL_URL: https://raw.githubusercontent.com/dapr/cli/v1.12.0/install/install.sh DAPR_CLI_REF: DAPR_REF: steps: diff --git a/sdk/src/test/java/io/dapr/client/DaprClientGrpcTelemetryTest.java b/sdk/src/test/java/io/dapr/client/DaprClientGrpcTelemetryTest.java index f7ec4ccef..9ec9352df 100644 --- a/sdk/src/test/java/io/dapr/client/DaprClientGrpcTelemetryTest.java +++ b/sdk/src/test/java/io/dapr/client/DaprClientGrpcTelemetryTest.java @@ -30,8 +30,8 @@ import io.grpc.inprocess.InProcessChannelBuilder; import io.grpc.inprocess.InProcessServerBuilder; import io.grpc.testing.GrpcCleanupRule; import org.junit.Rule; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; import org.junit.jupiter.migrationsupport.rules.EnableRuleMigrationSupport; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; @@ -47,7 +47,6 @@ import reactor.util.context.ContextView; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertTrue; @EnableRuleMigrationSupport public class DaprClientGrpcTelemetryTest { @@ -70,6 +69,13 @@ public class DaprClientGrpcTelemetryTest { private DaprClient client; + @AfterEach + public void teardown() throws Exception { + if (client != null) { + client.close(); + } + } + public static Stream data() { return Stream.of( Arguments.of( diff --git a/sdk/src/test/java/io/dapr/utils/NetworkUtilsTest.java b/sdk/src/test/java/io/dapr/utils/NetworkUtilsTest.java index 93945b947..adcc6c473 100644 --- a/sdk/src/test/java/io/dapr/utils/NetworkUtilsTest.java +++ b/sdk/src/test/java/io/dapr/utils/NetworkUtilsTest.java @@ -2,13 +2,21 @@ package io.dapr.utils; import io.dapr.config.Properties; import io.grpc.ManagedChannel; +import io.grpc.testing.GrpcCleanupRule; +import org.junit.Rule; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import static org.mockito.Mockito.mock; + public class NetworkUtilsTest { private final int defaultGrpcPort = 4000; private final String defaultSidecarIP = "127.0.0.1"; + + private ManagedChannel channel; + @BeforeEach public void setUp() { System.setProperty(Properties.GRPC_PORT.getName(), Integer.toString(defaultGrpcPort)); @@ -16,9 +24,16 @@ public class NetworkUtilsTest { System.setProperty(Properties.GRPC_ENDPOINT.getName(), ""); } + @AfterEach + public void tearDown() { + if (channel != null && !channel.isShutdown()) { + channel.shutdown(); + } + } + @Test public void testBuildGrpcManagedChannel() { - ManagedChannel channel = NetworkUtils.buildGrpcManagedChannel(); + channel = NetworkUtils.buildGrpcManagedChannel(); String expectedAuthority = String.format("%s:%s", defaultSidecarIP, defaultGrpcPort); Assertions.assertEquals(expectedAuthority, channel.authority()); @@ -27,7 +42,7 @@ public class NetworkUtilsTest { @Test public void testBuildGrpcManagedChannel_httpEndpointNoPort() { System.setProperty(Properties.GRPC_ENDPOINT.getName(), "http://example.com"); - ManagedChannel channel = NetworkUtils.buildGrpcManagedChannel(); + channel = NetworkUtils.buildGrpcManagedChannel(); String expectedAuthority = "example.com:80"; Assertions.assertEquals(expectedAuthority, channel.authority()); @@ -36,7 +51,7 @@ public class NetworkUtilsTest { @Test public void testBuildGrpcManagedChannel_httpEndpointWithPort() { System.setProperty(Properties.GRPC_ENDPOINT.getName(), "http://example.com:3000"); - ManagedChannel channel = NetworkUtils.buildGrpcManagedChannel(); + channel = NetworkUtils.buildGrpcManagedChannel(); String expectedAuthority = "example.com:3000"; Assertions.assertEquals(expectedAuthority, channel.authority()); @@ -45,7 +60,7 @@ public class NetworkUtilsTest { @Test public void testBuildGrpcManagedChannel_httpsEndpointNoPort() { System.setProperty(Properties.GRPC_ENDPOINT.getName(), "https://example.com"); - ManagedChannel channel = NetworkUtils.buildGrpcManagedChannel(); + channel = NetworkUtils.buildGrpcManagedChannel(); String expectedAuthority = "example.com:443"; Assertions.assertEquals(expectedAuthority, channel.authority()); @@ -54,7 +69,7 @@ public class NetworkUtilsTest { @Test public void testBuildGrpcManagedChannel_httpsEndpointWithPort() { System.setProperty(Properties.GRPC_ENDPOINT.getName(), "https://example.com:3000"); - ManagedChannel channel = NetworkUtils.buildGrpcManagedChannel(); + channel = NetworkUtils.buildGrpcManagedChannel(); String expectedAuthority = "example.com:3000"; Assertions.assertEquals(expectedAuthority, channel.authority());