From e8883065d3ba500c792436ade8b4dbed52908906 Mon Sep 17 00:00:00 2001 From: Mariano Barrios Date: Thu, 8 Jun 2023 18:29:23 +0200 Subject: [PATCH] Avoid non-local return in test (deprecated) --- .../scala/tlschannel/ConcurrentTest.scala | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/test/scala/tlschannel/ConcurrentTest.scala b/src/test/scala/tlschannel/ConcurrentTest.scala index eb49ff83..c577cbdf 100644 --- a/src/test/scala/tlschannel/ConcurrentTest.scala +++ b/src/test/scala/tlschannel/ConcurrentTest.scala @@ -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 { @@ -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() } }