From 9c5922529868637961bc785a88f8af8d897fe680 Mon Sep 17 00:00:00 2001 From: Arman Bilge Date: Tue, 6 Sep 2022 03:15:25 +0000 Subject: [PATCH] Do not background server in ping-pong test --- .../src/test/scala/epollcat/TcpSuite.scala | 41 +++++++++---------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/tests/shared/src/test/scala/epollcat/TcpSuite.scala b/tests/shared/src/test/scala/epollcat/TcpSuite.scala index 21780af..7719621 100644 --- a/tests/shared/src/test/scala/epollcat/TcpSuite.scala +++ b/tests/shared/src/test/scala/epollcat/TcpSuite.scala @@ -142,27 +142,26 @@ class TcpSuite extends EpollcatSuite { } yield () } - serverCh.bind(new InetSocketAddress(0)) *> server.background.use { _ => - val ch = clientCh - for { - serverAddr <- serverCh.localAddress - _ <- ch.connect(serverAddr) - clientLocalAddr <- ch.localAddress - _ <- IO( - assert(clue(clientLocalAddr.asInstanceOf[InetSocketAddress].getPort()) != 0) - ) - bb <- IO(ByteBuffer.wrap("ping".getBytes)) - wrote <- ch.write(bb) - _ <- IO(assertEquals(bb.remaining(), 0)) - _ <- IO(assertEquals(wrote, 4)) - bb <- IO(ByteBuffer.allocate(4)) - readed <- ch.read(bb) - _ <- IO(assertEquals(readed, 4)) - _ <- IO(assertEquals(bb.remaining(), 0)) - res <- IO(bb.position(0)) *> IO(decode(bb)) - _ <- IO(assertEquals(res, "pong")) - } yield () - } + val client = for { + serverAddr <- serverCh.localAddress + _ <- clientCh.connect(serverAddr) + clientLocalAddr <- clientCh.localAddress + _ <- IO( + assert(clue(clientLocalAddr.asInstanceOf[InetSocketAddress].getPort()) != 0) + ) + bb <- IO(ByteBuffer.wrap("ping".getBytes)) + wrote <- clientCh.write(bb) + _ <- IO(assertEquals(bb.remaining(), 0)) + _ <- IO(assertEquals(wrote, 4)) + bb <- IO(ByteBuffer.allocate(4)) + readed <- clientCh.read(bb) + _ <- IO(assertEquals(readed, 4)) + _ <- IO(assertEquals(bb.remaining(), 0)) + res <- IO(bb.position(0)) *> IO(decode(bb)) + _ <- IO(assertEquals(res, "pong")) + } yield () + + serverCh.bind(new InetSocketAddress(0)) *> server.both(client).void } }