Add logic to identify root cause of flakey test (#4056)

This commit is contained in:
David Perez 2024-10-09 13:03:21 -05:00 committed by GitHub
parent 57d79cd51c
commit 79d2a00bf8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -311,7 +311,7 @@ class CiphersServiceTest : BaseServiceTest() {
)
assertEquals(
createMockAttachment(number = 1),
result.getOrThrow(),
result.testGetOrThrow(),
)
}
@ -336,6 +336,25 @@ private fun setupMockUri(
return mockUri
}
/**
* A helper method to attempt validate that the the value is being boxed and causing test to
* inconsistently fail.
*
* This was modified from the code found here:
* * https://github.com/mockk/mockk/issues/485#issuecomment-1973170516
*/
@Suppress("INVISIBLE_REFERENCE", "UNCHECKED_CAST")
private fun <T> Result<T>.testGetOrThrow(): T =
when (val unboxed: Any? = value) {
is Result.Failure -> throw unboxed.exception
!is Result<*> -> unboxed as T
else -> {
// This means the result is boxed, we could make this recursive to address the issue.
println("Unboxed value = $unboxed")
unboxed as T
}
}
private const val CREATE_ATTACHMENT_SUCCESS_JSON = """
{
"attachmentId":"mockAttachmentId-1",