github-code-scanning[bot] commented on code in PR #2110:
URL: https://github.com/apache/avro/pull/2110#discussion_r1111237221
##########
lang/java/ipc-netty/src/test/java/org/apache/avro/ipc/netty/TestNettyServer.java:
##########
@@ -144,23 +148,55 @@
@Test
void connectionsCount() throws Exception {
+ // It happens on a regular basis that the server still has a connection
+ // that is in the process of being terminated (previous test?).
+ // We wait for that to happen because otherwise this test will fail.
+ assertNumberOfConnectionsOnServer(1, 1000);
+
Transceiver transceiver2 = new NettyTransceiver(new
InetSocketAddress(server.getPort()), CONNECT_TIMEOUT_MILLIS,
channelInitializer);
Mail proxy2 = SpecificRequestor.getClient(Mail.class, transceiver2);
proxy.fireandforget(createMessage());
proxy2.fireandforget(createMessage());
- assertEquals(2, ((NettyServer) server).getNumActiveConnections());
+ assertNumberOfConnectionsOnServer(2, 0);
transceiver2.close();
// Check the active connections with some retries as closing at the client
// side might not take effect on the server side immediately
+ assertNumberOfConnectionsOnServer(1, 5000);
+ }
+
+ /**
+ * Assert for the number of server connections. This does repeated checks
(with
+ * timeout) if it not matches at first because closing at the client side
might
+ * not take effect on the server side immediately.
+ *
+ * @param wantedNumberOfConnections How many do we want to have
+ * @param maxWaitMs Within how much time (0= immediately)
+ */
+ private static void assertNumberOfConnectionsOnServer(int
wantedNumberOfConnections, long maxWaitMs)
+ throws InterruptedException {
int numActiveConnections = ((NettyServer)
server).getNumActiveConnections();
- for (int i = 0; i < 50 && numActiveConnections == 2; ++i) {
- System.out.println("Server still has 2 active connections; retrying...");
- Thread.sleep(100);
- numActiveConnections = ((NettyServer) server).getNumActiveConnections();
+ if (numActiveConnections == wantedNumberOfConnections) {
+ return; // We're good.
+ }
+ long startMs = System.currentTimeMillis();
+ long waited = 0;
+ if (maxWaitMs > 0) {
+ boolean timeOut = false;
+ int i = 1;
Review Comment:
## Unread local variable
Variable 'int i' is never read.
[Show more
details](https://github.com/apache/avro/security/code-scanning/2979)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]