Skip to content

Commit

Permalink
Resolve buildGrpcManagedChannel orphaned channel & ensure connections…
Browse files Browse the repository at this point in the history
… mocked (dapr#1003)

* okhttpclient is mocked

Signed-off-by: Cassandra Coyle <[email protected]>

* mock workflowRuntime to rm log: 'The sidecar at address localhost:4001 is unavailable. Will continue retrying.'

Signed-off-by: Cassandra Coyle <[email protected]>

* fix several NetworkUtilsTest orphaned channels

Signed-off-by: Cassandra Coyle <[email protected]>

* reset workflow changes since I still see the log output

Signed-off-by: Cassandra Coyle <[email protected]>

* Close daprClient on DaprClientGrpcTelemetryTest

Signed-off-by: Artur Souza <[email protected]>

* try latest runtime rc

Signed-off-by: Cassandra Coyle <[email protected]>

* Update runtime to 1.12.4

Signed-off-by: Artur Souza <[email protected]>

* Mvn test is now verbose, temporatily.

Signed-off-by: Artur Souza <[email protected]>

* try fixing RetryPolicyTest

Signed-off-by: Cassandra Coyle <[email protected]>

* comment out RetryPolicyTest

Signed-off-by: Cassandra Coyle <[email protected]>

* add RetryPolicyTest back

Signed-off-by: Cassandra Coyle <[email protected]>

* trying to figure out which test func is the issue

Signed-off-by: Cassandra Coyle <[email protected]>

* try ubuntu-20.04

Signed-off-by: Cassandra Coyle <[email protected]>

* try rm-ing GrpcChannelFacadeTest

Signed-off-by: Cassandra Coyle <[email protected]>

* try rm-ing DaprClientHttpTest

Signed-off-by: Cassandra Coyle <[email protected]>

* try t.join just in case

Signed-off-by: Cassandra Coyle <[email protected]>

* is this the bad test?

Signed-off-by: Cassandra Coyle <[email protected]>

* are these other healthcheck tests the problem?

Signed-off-by: Cassandra Coyle <[email protected]>

* is it the ok test?

Signed-off-by: Cassandra Coyle <[email protected]>

* is it due to an invoke test?

Signed-off-by: Cassandra Coyle <[email protected]>

* is it the config/subscribeConfig tests

Signed-off-by: Cassandra Coyle <[email protected]>

* is it noHotMono?

Signed-off-by: Cassandra Coyle <[email protected]>

* is it a publish test?

Signed-off-by: Cassandra Coyle <[email protected]>

* is it the other noHotMono tests?

Signed-off-by: Cassandra Coyle <[email protected]>

* is it a state test?

Signed-off-by: Cassandra Coyle <[email protected]>

* is it a save state test?

Signed-off-by: Cassandra Coyle <[email protected]>

* is it a secret test?

Signed-off-by: Cassandra Coyle <[email protected]>

* is it a delete state test?

Signed-off-by: Cassandra Coyle <[email protected]>

* is it the rest -1 and - ending tests?

Signed-off-by: Cassandra Coyle <[email protected]>

* no client calls, only end of file remaining

Signed-off-by: Cassandra Coyle <[email protected]>

* add teardown - did it work?

Signed-off-by: Cassandra Coyle <[email protected]>

* is it just needing daprClientHttpXML to be closed?

Signed-off-by: Cassandra Coyle <[email protected]>

* Reuse mock and builder.

Signed-off-by: Artur Souza <[email protected]>

* Try dedicated executor.

Signed-off-by: Artur Souza <[email protected]>

* Comment out the remaining tests.

Signed-off-by: Artur Souza <[email protected]>

* Remove before and after.

Signed-off-by: Artur Souza <[email protected]>

* Remove sdk/src/test/java/io/dapr/client/DaprClientHttpTest.java

Signed-off-by: Artur Souza <[email protected]>

* Remove sdk/src/test/java/io/dapr/client/DaprHttpTest.java.

Signed-off-by: Artur Souza <[email protected]>

* Delete a batch of tests.

Signed-off-by: Artur Souza <[email protected]>

* restore deleted test files

Signed-off-by: Cassandra Coyle <[email protected]>

* add back in RetryPolicyTest

Signed-off-by: Cassandra Coyle <[email protected]>

---------

Signed-off-by: Cassandra Coyle <[email protected]>
Signed-off-by: Artur Souza <[email protected]>
Co-authored-by: Artur Souza <[email protected]>
Co-authored-by: Artur Souza <[email protected]>
  • Loading branch information
3 people authored Feb 8, 2024
1 parent 22427c9 commit b2968af
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 14 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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/[email protected]
- name: Install jars
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
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;
Expand All @@ -47,7 +47,6 @@

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 {
Expand All @@ -70,6 +69,13 @@ public class DaprClientGrpcTelemetryTest {

private DaprClient client;

@AfterEach
public void teardown() throws Exception {
if (client != null) {
client.close();
}
}

public static Stream<Arguments> data() {
return Stream.of(
Arguments.of(
Expand Down
25 changes: 20 additions & 5 deletions sdk/src/test/java/io/dapr/utils/NetworkUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,38 @@

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));
System.setProperty(Properties.SIDECAR_IP.getName(), defaultSidecarIP);
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());
Expand All @@ -27,7 +42,7 @@ public void testBuildGrpcManagedChannel() {
@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());
Expand All @@ -36,7 +51,7 @@ public void testBuildGrpcManagedChannel_httpEndpointNoPort() {
@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());
Expand All @@ -45,7 +60,7 @@ public void testBuildGrpcManagedChannel_httpEndpointWithPort() {
@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());
Expand All @@ -54,7 +69,7 @@ public void testBuildGrpcManagedChannel_httpsEndpointNoPort() {
@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());
Expand Down

0 comments on commit b2968af

Please sign in to comment.