armanbilge/epollcat

Chance to simplify TcpSuite ping-pong

Closed this issue · 2 comments

We are chasing more important errors in TcpSuite ping-pong.

Whilst chasing those, I noticed the lines in the client side

  _ <- IO(
            assert(clue(clientLocalAddr.asInstanceOf[InetSocketAddress].getPort()) != 0)

Does that tell us anything we do not already know, or that the writes immediately
below will not complain about. I have a hard time imagining how connect() could
succeed without setting a localAddress. Perhaps this was early development
time only belt-and-suspenders implementation insurance code?

Yes, belt-and-suspenders I think 😆 we now have a better test for this here I believe:

test("local and remote addresses") {
IOServerSocketChannel.open.evalTap(_.bind(new InetSocketAddress("127.0.0.1", 0))).use {
server =>
IOSocketChannel.open.use { clientCh =>
server.localAddress.flatMap(clientCh.connect(_)) *>
server.accept.use { serverCh =>
for {
serverLocal <- serverCh.localAddress
serverRemote <- serverCh.remoteAddress
clientLocal <- clientCh.localAddress
clientRemote <- clientCh.remoteAddress
} yield {
assertEquals(clientRemote, serverLocal)
assertEquals(serverRemote, clientLocal)
}
}
}
}
}

Yes, this is a better test.

By my reading this is OK, because the ServerSocket is listening(), as part of pseudo-JVM bind(),
and the client connection can happen as long as there is only a short pause before the accept.
I would have to check what the definition of "short" is: seconds?