Skip to content

Commit

Permalink
[MINOR] fix(test): Fix flaky test for CoordinatorGrpcServerTest#testG…
Browse files Browse the repository at this point in the history
…rpcConnectionSize (#2323)

### What changes were proposed in this pull request?

Fix flaky test for CoordinatorGrpcServerTest#testGrpcConnectionSize

### Why are the changes needed?

Do some efforts to make Ci more stable.

### Does this PR introduce _any_ user-facing change?

NO

### How was this patch tested?

Existing UTs.
  • Loading branch information
maobaolong authored Jan 8, 2025
1 parent 1ac46db commit a15751b
Showing 1 changed file with 24 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,30 +69,34 @@ public void testGrpcConnectionSize() throws Exception {
.grpcMetrics(grpcMetrics)
.addService(new MockedCoordinatorGrpcService())
.build();
grpcServer.start();
try {
grpcServer.start();

// case1: test the single one connection metric
double connSize = grpcMetrics.getGaugeMap().get(GRPC_SERVER_CONNECTION_NUMBER_KEY).get();
assertEquals(0, connSize);
// case1: test the single one connection metric
double connSize = grpcMetrics.getGaugeMap().get(GRPC_SERVER_CONNECTION_NUMBER_KEY).get();
assertEquals(0, connSize);

CoordinatorGrpcClient coordinatorGrpcClient = new CoordinatorGrpcClient("localhost", 20001);
coordinatorGrpcClient.registerApplicationInfo(
new RssApplicationInfoRequest("testGrpcConnectionSize", 10000, "user"));
// case2: test the multiple connections
try (CoordinatorGrpcClient coordinatorGrpcClient =
new CoordinatorGrpcClient("localhost", 20001);
CoordinatorGrpcClient client1 = new CoordinatorGrpcClient("localhost", 20001);
CoordinatorGrpcClient client2 = new CoordinatorGrpcClient("localhost", 20001)) {
coordinatorGrpcClient.registerApplicationInfo(
new RssApplicationInfoRequest("testGrpcConnectionSize", 10000, "user"));

connSize = grpcMetrics.getGaugeMap().get(GRPC_SERVER_CONNECTION_NUMBER_KEY).get();
assertEquals(1, connSize);
connSize = grpcMetrics.getGaugeMap().get(GRPC_SERVER_CONNECTION_NUMBER_KEY).get();
assertEquals(1, connSize);

// case2: test the multiple connections
CoordinatorGrpcClient client1 = new CoordinatorGrpcClient("localhost", 20001);
CoordinatorGrpcClient client2 = new CoordinatorGrpcClient("localhost", 20001);
client1.registerApplicationInfo(
new RssApplicationInfoRequest("testGrpcConnectionSize", 10000, "user"));
client2.registerApplicationInfo(
new RssApplicationInfoRequest("testGrpcConnectionSize", 10000, "user"));
client1.registerApplicationInfo(
new RssApplicationInfoRequest("testGrpcConnectionSize", 10000, "user"));
client2.registerApplicationInfo(
new RssApplicationInfoRequest("testGrpcConnectionSize", 10000, "user"));

connSize = grpcMetrics.getGaugeMap().get(GRPC_SERVER_CONNECTION_NUMBER_KEY).get();
assertEquals(3, connSize);

grpcServer.stop();
connSize = grpcMetrics.getGaugeMap().get(GRPC_SERVER_CONNECTION_NUMBER_KEY).get();
assertEquals(3, connSize);
}
} finally {
grpcServer.stop();
}
}
}

0 comments on commit a15751b

Please sign in to comment.