diff --git a/tests/shared/src/test/scala/epollcat/TcpSuite.scala b/tests/shared/src/test/scala/epollcat/TcpSuite.scala index cf28899..f14b8c4 100644 --- a/tests/shared/src/test/scala/epollcat/TcpSuite.scala +++ b/tests/shared/src/test/scala/epollcat/TcpSuite.scala @@ -312,13 +312,18 @@ class TcpSuite extends EpollcatSuite { } test("closing/re-opening a server does not throw BindException: Address already in use") { - val address = new InetSocketAddress("127.0.0.0", 8080) - IOServerSocketChannel.open.evalTap(_.bind(address)).use { server => - val connect = - IOSocketChannel.open.evalTap(_.connect(address)).surround(IO.sleep(1.second)) - val accept = server.accept.surround(IO.sleep(1.second)) - connect.both(accept).void - } *> IOServerSocketChannel.open.evalTap(_.bind(address)).use_ + IOServerSocketChannel + .open + .evalTap(_.bind(new InetSocketAddress("localhost", 0))) + .use { server => + server.localAddress.flatTap { address => + val connect = + IOSocketChannel.open.evalTap(_.connect(address)).surround(IO.sleep(1.second)) + val accept = server.accept.surround(IO.sleep(1.second)) + connect.both(accept).void + } + } + .flatMap(address => IOServerSocketChannel.open.evalTap(_.bind(address)).use_) } }