diff options
author | Chris Narkiewicz <hello@ezaquarii.com> | 2022-07-04 01:45:01 +0300 |
---|---|---|
committer | Chris Narkiewicz <hello@ezaquarii.com> | 2022-07-04 02:30:30 +0300 |
commit | 98230e1296ed4538e4e0d6d9322c9e9e8fc683b0 (patch) | |
tree | 160785f78c577d51dcc0be6867a65416bfb8b998 | |
parent | 29390e1fe06842a80a81b4c837ea8bd9189ce431 (diff) |
Fix flaky Logger overflow testfix-flaky-logger-test
Load event is processed before overlow condition check can
result in warning log line being appended. This resulted
in a race condition.
We simply poll the log file until we either find interesting
log line or we give up after several seconds.
Fixes #10416
Signed-off-by: Chris Narkiewicz <hello@ezaquarii.com>
-rw-r--r-- | app/src/test/java/com/nextcloud/client/logger/LoggerTest.kt | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/app/src/test/java/com/nextcloud/client/logger/LoggerTest.kt b/app/src/test/java/com/nextcloud/client/logger/LoggerTest.kt index 5074684381..8c42dbc1ab 100644 --- a/app/src/test/java/com/nextcloud/client/logger/LoggerTest.kt +++ b/app/src/test/java/com/nextcloud/client/logger/LoggerTest.kt @@ -25,6 +25,7 @@ import com.nextcloud.client.core.ClockImpl import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse import org.junit.Assert.assertNotEquals +import org.junit.Assert.assertNotNull import org.junit.Assert.assertNull import org.junit.Assert.assertTrue import org.junit.Before @@ -249,23 +250,30 @@ class LoggerTest { // THEN // overflow occurrence is logged - val posted = CountDownLatch(1) whenever(osHandler.post(any())).thenAnswer { (it.arguments[0] as Runnable).run() - posted.countDown() true } - val listener: OnLogsLoaded = mock() - logger.load(listener) - assertTrue("Logs not loaded", posted.await(1, TimeUnit.SECONDS)) - - verify(listener).invoke( - argThat { - "Logger queue overflow" in last().message - }, - any() - ) + // load continuously until we find expected log line or we give up + var lostMessageWarning: LogEntry? = null + for (i in 0..10) { + val loaded = CountDownLatch(1) + logger.load { entries, totalLogSize -> + lostMessageWarning = entries.find { + it.message.contains("Logger queue overflow") + } + loaded.countDown() + } + val ok = loaded.await(1000, TimeUnit.MILLISECONDS) + assertTrue("load callback not invoked; did you enable handler mock?", ok) + if (lostMessageWarning != null) { + break + } else { + Thread.sleep(1000) + } + } + assertNotNull(lostMessageWarning) } @Test |