diff --git a/test/dorkboxTest/network/BaseTest.kt b/test/dorkboxTest/network/BaseTest.kt index 4e34b4ae..f26c3ef4 100644 --- a/test/dorkboxTest/network/BaseTest.kt +++ b/test/dorkboxTest/network/BaseTest.kt @@ -168,6 +168,8 @@ abstract class BaseTest { private val endPointConnections: MutableList> = CopyOnWriteArrayList() + private var errors = mutableListOf() + @Volatile private var isStopping = false @@ -195,11 +197,14 @@ abstract class BaseTest { endPoint.onConnect { logger.error("UNIT TEST: connect $id (${uuid.toHexString()})") } endPoint.onDisconnect { logger.error("UNIT TEST: disconnect $id (${uuid.toHexString()})") } - endPoint.onError { logger.error("UNIT TEST: ERROR! $id (${uuid.toHexString()})", it) } - endPoint.onError { logger.error("UNIT TEST: ERROR! $id (${uuid.toHexString()})", it) - Assert.fail("Exception caught, and it shouldn't have happened!") + errors.add(it) + } + + endPoint.onErrorGlobal { + logger.error("UNIT TEST: GLOBAL ERROR!", it) + errors.add(it) } endPointConnections.add(endPoint) @@ -272,7 +277,7 @@ abstract class BaseTest { * * @param stopAfterSeconds how many seconds to wait, the default is 2 minutes. */ - fun waitForThreads(stopAfterSeconds: Long = AUTO_FAIL_TIMEOUT) { + fun waitForThreads(stopAfterSeconds: Long = AUTO_FAIL_TIMEOUT, onShutdown: (List) -> List = { it }) { val clients = endPointConnections.filterIsInstance>() val servers = endPointConnections.filterIsInstance>() @@ -330,6 +335,18 @@ abstract class BaseTest { endPointConnections.clear() logger.error("Finished shutting down all endpoints... ($successClients, $successServers)") + + if (errors.isNotEmpty()) { + val acceptableErrors = errors.filterNot { it.message?.contains("Unable to send message. (Connection in non-connected state, aborted attempt! Not connected)") ?: false } + val filteredErrors = onShutdown(acceptableErrors) + if (filteredErrors.isNotEmpty()) { + filteredErrors.forEach { + it.printStackTrace() + } + + Assert.fail("Exception caught, and it shouldn't have happened!") + } + } } @Before diff --git a/test/dorkboxTest/network/ConnectionFilterTest.kt b/test/dorkboxTest/network/ConnectionFilterTest.kt index 4eec10ee..86d88ea1 100644 --- a/test/dorkboxTest/network/ConnectionFilterTest.kt +++ b/test/dorkboxTest/network/ConnectionFilterTest.kt @@ -271,7 +271,11 @@ class ConnectionFilterTest : BaseTest() { client.connect(LOCALHOST, 2000) } catch (e: Exception) { stopEndPoints() - waitForThreads() + waitForThreads { errors -> + errors.filterNot { + it.message?.contains("Connection was not permitted!") ?: false + } + } throw e } @@ -370,7 +374,11 @@ class ConnectionFilterTest : BaseTest() { client.connect(LOCALHOST, 2000) } catch (e: Exception) { stopEndPoints() - waitForThreads() + waitForThreads { errors -> + errors.filterNot { + it.message?.contains("Connection was not permitted!") ?: false + } + } throw e } @@ -518,7 +526,11 @@ class ConnectionFilterTest : BaseTest() { client.connect(LOCALHOST, 2000) } catch (e: Exception) { stopEndPoints() - waitForThreads() + waitForThreads{ errors -> + errors.filterNot { + it.message?.contains("Connection was not permitted!") ?: false + } + } throw e } @@ -560,7 +572,12 @@ class ConnectionFilterTest : BaseTest() { client.connect(LOCALHOST, 2000) } catch (e: Exception) { stopEndPoints() - waitForThreads() + waitForThreads{ errors -> + errors.filterNot { + it.message?.contains("Connection was not permitted!") ?: false + } + } + throw e } diff --git a/test/dorkboxTest/network/ErrorLoggerTest.kt b/test/dorkboxTest/network/ErrorLoggerTest.kt index 139287ce..160be4b7 100644 --- a/test/dorkboxTest/network/ErrorLoggerTest.kt +++ b/test/dorkboxTest/network/ErrorLoggerTest.kt @@ -27,6 +27,8 @@ class ErrorLoggerTest : BaseTest() { @Test fun customErrorLoggerTest() { + val exception = Exception("server ERROR. SHOULD BE CAUGHT") + val server = run { val configuration = serverConfig() configuration.aeronErrorFilter = { @@ -50,7 +52,7 @@ class ErrorLoggerTest : BaseTest() { } server.onMessage { - throw Exception("server ERROR. SHOULD BE CAUGHT") + throw exception } server @@ -79,6 +81,9 @@ class ErrorLoggerTest : BaseTest() { server.bind(2000) client.connect(LOCALHOST, 2000) - waitForThreads() + waitForThreads() { errors -> + // we don't want to fail the unit test for this exception + errors.filter { it != exception } + } } }