Skip to content

Commit

Permalink
Do not hard-code port for test
Browse files Browse the repository at this point in the history
  • Loading branch information
armanbilge committed Feb 18, 2023
1 parent 33ac347 commit 233aeee
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions tests/shared/src/test/scala/epollcat/TcpSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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_)
}

}

0 comments on commit 233aeee

Please sign in to comment.