Skip to content

Commit

Permalink
Avoid non-local return in test (deprecated)
Browse files Browse the repository at this point in the history
  • Loading branch information
marianobarrios committed Jun 8, 2023
1 parent 6bc8d0d commit e888306
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/test/scala/tlschannel/ConcurrentTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import org.junit.jupiter.api.{Test, TestInstance}
import org.junit.jupiter.api.TestInstance.Lifecycle
import tlschannel.helpers.{SocketGroup, SocketPairFactory, SslContextFactory, TestUtil}

import scala.util.control.Breaks.{break, breakable}

@TestInstance(Lifecycle.PER_CLASS)
class ConcurrentTest extends StrictLogging {

Expand Down Expand Up @@ -82,19 +84,21 @@ class ConcurrentTest extends StrictLogging {
}

private def readerLoopUntilEof(socketGroup: SocketGroup, accumulator: AtomicLong): Unit = TestUtil.cannotFail {
logger.debug(s"Starting reader loop.")
val readArray = Array.ofDim[Byte](bufferSize)
while (true) {
val readBuffer = ByteBuffer.wrap(readArray, 0, bufferSize)
val c = socketGroup.external.read(readBuffer)
if (c == -1) {
logger.debug("Finalizing reader loop")
return
breakable {
logger.debug(s"Starting reader loop.")
val readArray = Array.ofDim[Byte](bufferSize)
while (true) {
val readBuffer = ByteBuffer.wrap(readArray, 0, bufferSize)
val c = socketGroup.external.read(readBuffer)
if (c == -1) {
logger.debug("Finalizing reader loop")
break()
}
assertTrue(c > 0, "blocking read must return a positive number")
accumulator.addAndGet(c)
}
assertTrue(c > 0, "blocking read must return a positive number")
accumulator.addAndGet(c)
fail()
}
fail()
}

}

0 comments on commit e888306

Please sign in to comment.