diff --git a/data/src/test/java/org/oppia/android/data/backends/gae/NetworkLoggingInterceptorTest.kt b/data/src/test/java/org/oppia/android/data/backends/gae/NetworkLoggingInterceptorTest.kt index e62b1bcc384..6b82cb460fb 100644 --- a/data/src/test/java/org/oppia/android/data/backends/gae/NetworkLoggingInterceptorTest.kt +++ b/data/src/test/java/org/oppia/android/data/backends/gae/NetworkLoggingInterceptorTest.kt @@ -93,6 +93,7 @@ class NetworkLoggingInterceptorTest { val firstRequestsDeferred = CoroutineScope(backgroundTestDispatcher).async { networkLoggingInterceptor.logNetworkCallFlow.take(1).toList() } + testCoroutineDispatchers.advanceUntilIdle() // Ensure the flow is subscribed before emit(). client.newCall(request).execute() testCoroutineDispatchers.advanceUntilIdle() @@ -116,6 +117,7 @@ class NetworkLoggingInterceptorTest { networkLoggingInterceptor.logFailedNetworkCallFlow.take(1).toList() } mockWebServer.enqueue(mockResponse) + testCoroutineDispatchers.advanceUntilIdle() // Ensure the flow is subscribed before emit(). client.newCall(request).execute() testCoroutineDispatchers.advanceUntilIdle() @@ -141,6 +143,7 @@ class NetworkLoggingInterceptorTest { val firstFailingRequestsDeferred = CoroutineScope(backgroundTestDispatcher).async { networkLoggingInterceptor.logFailedNetworkCallFlow.take(1).toList() } + testCoroutineDispatchers.advanceUntilIdle() // Ensure the flow is subscribed before emit(). try { client.newCall(request).execute() } catch (e: ConnectException) { diff --git a/utility/src/test/java/org/oppia/android/util/logging/ConsoleLoggerTest.kt b/utility/src/test/java/org/oppia/android/util/logging/ConsoleLoggerTest.kt index 65e37d6bdcc..6a314de75fe 100644 --- a/utility/src/test/java/org/oppia/android/util/logging/ConsoleLoggerTest.kt +++ b/utility/src/test/java/org/oppia/android/util/logging/ConsoleLoggerTest.kt @@ -65,6 +65,8 @@ class ConsoleLoggerTest { val firstErrorContextsDeferred = CoroutineScope(backgroundTestDispatcher).async { consoleLogger.logErrorMessagesFlow.take(1).toList() } + + testCoroutineDispatchers.advanceUntilIdle() // Ensure the flow is subscribed before emit(). consoleLogger.e(testTag, testMessage) testCoroutineDispatchers.advanceUntilIdle()