Make sure now that errors during unit tests are properly failing (or ignoring) as appropriate the test.
This commit is contained in:
parent
76f42c900c
commit
2cfc2e41e6
|
@ -168,6 +168,8 @@ abstract class BaseTest {
|
||||||
|
|
||||||
private val endPointConnections: MutableList<EndPoint<*>> = CopyOnWriteArrayList()
|
private val endPointConnections: MutableList<EndPoint<*>> = CopyOnWriteArrayList()
|
||||||
|
|
||||||
|
private var errors = mutableListOf<Throwable>()
|
||||||
|
|
||||||
@Volatile
|
@Volatile
|
||||||
private var isStopping = false
|
private var isStopping = false
|
||||||
|
|
||||||
|
@ -195,11 +197,14 @@ abstract class BaseTest {
|
||||||
endPoint.onConnect { logger.error("UNIT TEST: connect $id (${uuid.toHexString()})") }
|
endPoint.onConnect { logger.error("UNIT TEST: connect $id (${uuid.toHexString()})") }
|
||||||
endPoint.onDisconnect { logger.error("UNIT TEST: disconnect $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 {
|
endPoint.onError {
|
||||||
logger.error("UNIT TEST: ERROR! $id (${uuid.toHexString()})", it)
|
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)
|
endPointConnections.add(endPoint)
|
||||||
|
@ -272,7 +277,7 @@ abstract class BaseTest {
|
||||||
*
|
*
|
||||||
* @param stopAfterSeconds how many seconds to wait, the default is 2 minutes.
|
* @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<Throwable>) -> List<Throwable> = { it }) {
|
||||||
val clients = endPointConnections.filterIsInstance<Client<Connection>>()
|
val clients = endPointConnections.filterIsInstance<Client<Connection>>()
|
||||||
val servers = endPointConnections.filterIsInstance<Server<Connection>>()
|
val servers = endPointConnections.filterIsInstance<Server<Connection>>()
|
||||||
|
|
||||||
|
@ -330,6 +335,18 @@ abstract class BaseTest {
|
||||||
endPointConnections.clear()
|
endPointConnections.clear()
|
||||||
|
|
||||||
logger.error("Finished shutting down all endpoints... ($successClients, $successServers)")
|
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
|
@Before
|
||||||
|
|
|
@ -271,7 +271,11 @@ class ConnectionFilterTest : BaseTest() {
|
||||||
client.connect(LOCALHOST, 2000)
|
client.connect(LOCALHOST, 2000)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
stopEndPoints()
|
stopEndPoints()
|
||||||
waitForThreads()
|
waitForThreads { errors ->
|
||||||
|
errors.filterNot {
|
||||||
|
it.message?.contains("Connection was not permitted!") ?: false
|
||||||
|
}
|
||||||
|
}
|
||||||
throw e
|
throw e
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -370,7 +374,11 @@ class ConnectionFilterTest : BaseTest() {
|
||||||
client.connect(LOCALHOST, 2000)
|
client.connect(LOCALHOST, 2000)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
stopEndPoints()
|
stopEndPoints()
|
||||||
waitForThreads()
|
waitForThreads { errors ->
|
||||||
|
errors.filterNot {
|
||||||
|
it.message?.contains("Connection was not permitted!") ?: false
|
||||||
|
}
|
||||||
|
}
|
||||||
throw e
|
throw e
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -518,7 +526,11 @@ class ConnectionFilterTest : BaseTest() {
|
||||||
client.connect(LOCALHOST, 2000)
|
client.connect(LOCALHOST, 2000)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
stopEndPoints()
|
stopEndPoints()
|
||||||
waitForThreads()
|
waitForThreads{ errors ->
|
||||||
|
errors.filterNot {
|
||||||
|
it.message?.contains("Connection was not permitted!") ?: false
|
||||||
|
}
|
||||||
|
}
|
||||||
throw e
|
throw e
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -560,7 +572,12 @@ class ConnectionFilterTest : BaseTest() {
|
||||||
client.connect(LOCALHOST, 2000)
|
client.connect(LOCALHOST, 2000)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
stopEndPoints()
|
stopEndPoints()
|
||||||
waitForThreads()
|
waitForThreads{ errors ->
|
||||||
|
errors.filterNot {
|
||||||
|
it.message?.contains("Connection was not permitted!") ?: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
throw e
|
throw e
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,8 @@ class ErrorLoggerTest : BaseTest() {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun customErrorLoggerTest() {
|
fun customErrorLoggerTest() {
|
||||||
|
val exception = Exception("server ERROR. SHOULD BE CAUGHT")
|
||||||
|
|
||||||
val server = run {
|
val server = run {
|
||||||
val configuration = serverConfig()
|
val configuration = serverConfig()
|
||||||
configuration.aeronErrorFilter = {
|
configuration.aeronErrorFilter = {
|
||||||
|
@ -50,7 +52,7 @@ class ErrorLoggerTest : BaseTest() {
|
||||||
}
|
}
|
||||||
|
|
||||||
server.onMessage<Any> {
|
server.onMessage<Any> {
|
||||||
throw Exception("server ERROR. SHOULD BE CAUGHT")
|
throw exception
|
||||||
}
|
}
|
||||||
|
|
||||||
server
|
server
|
||||||
|
@ -79,6 +81,9 @@ class ErrorLoggerTest : BaseTest() {
|
||||||
server.bind(2000)
|
server.bind(2000)
|
||||||
client.connect(LOCALHOST, 2000)
|
client.connect(LOCALHOST, 2000)
|
||||||
|
|
||||||
waitForThreads()
|
waitForThreads() { errors ->
|
||||||
|
// we don't want to fail the unit test for this exception
|
||||||
|
errors.filter { it != exception }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue