seb
12/29/2022, 9:47 AMTestDispatcher
, and I can't wrap it. How would one do it?seb
12/29/2022, 9:51 AMJoffrey
12/29/2022, 10:22 AMseb
12/29/2022, 10:24 AMseb
12/29/2022, 10:25 AMDmitry Khalanskiy [JB]
12/29/2022, 12:41 PMFrom f6fbc81476e8b900b8e38795e5d78cf3321623b6 Mon Sep 17 00:00:00 2001
From: Dmitry Khalanskiy <Dmitry.Khalanskiy@jetbrains.com>
Date: Thu, 29 Dec 2022 13:40:01 +0100
Subject: [PATCH] Modify NonpreciseTestCoroutineDispatcher not implement a
DelayController
---
.../kotlin/org/jetbrains/skiko/FrameLimiterTest.kt | 14 +++++---------
1 file changed, 5 insertions(+), 9 deletions(-)
diff --git a/skiko/src/jvmTest/kotlin/org/jetbrains/skiko/FrameLimiterTest.kt b/skiko/src/jvmTest/kotlin/org/jetbrains/skiko/FrameLimiterTest.kt
index c95ae4cd..faaed8b3 100644
--- a/skiko/src/jvmTest/kotlin/org/jetbrains/skiko/FrameLimiterTest.kt
+++ b/skiko/src/jvmTest/kotlin/org/jetbrains/skiko/FrameLimiterTest.kt
@@ -247,21 +247,17 @@ class FrameLimiterTest {
private fun runFrameTest(
delayPrecisionMillis: Long,
block: suspend TestCoroutineScope.() -> Unit
- ) = runBlockingTest{
- val dispatcher = NonpreciseTestCoroutineDispatcher(delayPrecisionMillis)
- dispatcher.pauseDispatcher()
- val scope = TestCoroutineScope(dispatcher)
- scope.launch {
- scope.block()
+ ) = runBlockingTest {
+ withContext(NonpreciseTestCoroutineDispatcher(delayPrecisionMillis)) {
+ block()
}
- dispatcher.advanceUntilIdle()
}
@OptIn(InternalCoroutinesApi::class)
private class NonpreciseTestCoroutineDispatcher(
private val delayPrecisionMillis: Long,
private val original: TestCoroutineDispatcher = TestCoroutineDispatcher()
- ) : CoroutineDispatcher(), Delay, DelayController by original {
+ ) : CoroutineDispatcher(), Delay {
override fun dispatch(context: CoroutineContext, block: Runnable) {
original.dispatch(context, block)
}
@@ -271,4 +267,4 @@ class FrameLimiterTest {
original.scheduleResumeAfterDelay(delay, continuation)
}
}
-}
\ No newline at end of file
+}
--
2.34.1
This approach should work just as well and doesn't require the wrapper to also be a test dispatcher.Dmitry Khalanskiy [JB]
12/29/2022, 12:41 PM.patch
file.seb
12/29/2022, 12:41 PMseb
12/29/2022, 5:01 PMrunTest
API instead of the deprecated runBlockingTest
, this wouldn't work though. Is that something that is even possible, out of curiosity?seb
12/29/2022, 5:01 PMrunTest
API... it's annoying me a bit that I have to use the deprecated API 🙂Dmitry Khalanskiy [JB]
12/30/2022, 9:42 AMTestCoroutineDispatcher
-> TestDispatcher
etc), and everything should still work. Just make sure to pass the testScheduler
to a newly-constructed StandardTestDispatcher
. Sorry for being brief, I'm on a vacation and typing from my phone.seb
12/30/2022, 9:42 AM