From 9d7dac0f16d4fd8c4723dd722e1e61ded5ef205b Mon Sep 17 00:00:00 2001 From: tangjiafu Date: Sat, 13 Apr 2024 12:49:50 +0800 Subject: [PATCH] fix flaky failure in CI for RichErrorModelTest --- .../myapp/helloworld/grpc/RichErrorModelTest.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/interop-tests/src/test/java/example/myapp/helloworld/grpc/RichErrorModelTest.java b/interop-tests/src/test/java/example/myapp/helloworld/grpc/RichErrorModelTest.java index 5cc75e70..61d8d284 100644 --- a/interop-tests/src/test/java/example/myapp/helloworld/grpc/RichErrorModelTest.java +++ b/interop-tests/src/test/java/example/myapp/helloworld/grpc/RichErrorModelTest.java @@ -20,7 +20,9 @@ import io.grpc.Status; import io.grpc.StatusRuntimeException; import io.grpc.protobuf.StatusProto; +import java.time.Duration; import java.util.concurrent.CompletionStage; +import java.util.concurrent.TimeUnit; import org.apache.pekko.actor.ActorSystem; import org.apache.pekko.grpc.GrpcClientSettings; import org.apache.pekko.http.javadsl.Http; @@ -43,7 +45,6 @@ private CompletionStage run(ActorSystem sys) throws Exception { org.apache.pekko.japi.function.Function> service = GreeterServiceHandlerFactory.create(impl, sys); - return Http.get(sys).newServerAt("127.0.0.1", 8090).bind(service); } @@ -52,8 +53,7 @@ private CompletionStage run(ActorSystem sys) throws Exception { public void testManualApproach() throws Exception { Config conf = ConfigFactory.load(); ActorSystem sys = ActorSystem.create("HelloWorld", conf); - run(sys); - + ServerBinding serverBinding = run(sys).toCompletableFuture().get(60, TimeUnit.SECONDS); GrpcClientSettings settings = GrpcClientSettings.connectToServiceAt("127.0.0.1", 8090, sys).withTls(false); @@ -68,9 +68,7 @@ public void testManualApproach() throws Exception { response .toCompletableFuture() .handle( - (res, ex) -> { - return (StatusRuntimeException) ex; - }) + (res, ex) -> (StatusRuntimeException) ex) .get(); com.google.rpc.Status status = @@ -94,6 +92,8 @@ public void testManualApproach() throws Exception { } finally { if (client != null) client.close(); sys.terminate(); + serverBinding.unbind(); + serverBinding.terminate(Duration.ofSeconds(10)); } } }