I’m using `runTest` to perform a test of some GraphQL client logic (mocking the underlying Apollo co...
s

Sam Pengilly

about 2 years ago
I’m using
runTest
to perform a test of some GraphQL client logic (mocking the underlying Apollo code and testing my own behaviours on top). This test has been fine for months, but for some reason it’s now acting flaky in the CI environment (and seemingly only in the CI environment), triggering the “UncompletedCoroutinesError: After waiting for 10s, the test coroutine is not completing” error. I can’t see anything in the body of the test that would be causing a hung coroutine. Could I get a sanity check on it from someone?
@Test
fun `should return parsed data upon network success`() = runTest {
    // Mocks the `call.execute()` suspending function to return an immediate result

    val call = successApolloCall(data = TestQueryData, errors = null)
    val mockApolloClient = mockk<ApolloClient> { every { query(TestQuery) } returns call }

    // executeQuery just wraps the Apollo query/execute calls to add retry behaviours and catching any exceptions using Arrow's Either
    // The retry policy uses Arrow's Scheduler which just uses delay() under the hood and should get skipped in test execution?

    val result = MyWrappingClient(mockApolloClient).executeQuery(TestQuery) { data, errors ->
        // Part of my client API that takes GraphQL response/error data and parses it
        (data == TestQueryData && errors == null).right()
    }

    result shouldBeRight true
    coVerify(exactly = 1) { call.execute() }
}