Skip to content

Commit

Permalink
Merge pull request #29 from armanbilge/pr/fix-hanging-ping-pong
Browse files Browse the repository at this point in the history
Do not background server in ping-pong test
  • Loading branch information
armanbilge authored Sep 8, 2022
2 parents 145e940 + 9c59225 commit 9fb9929
Showing 1 changed file with 20 additions and 21 deletions.
41 changes: 20 additions & 21 deletions tests/shared/src/test/scala/epollcat/TcpSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -152,27 +152,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
}
}

Expand Down

0 comments on commit 9fb9929

Please sign in to comment.