-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add TimeSource implementation to TestCoroutineScheduler #3087
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ package kotlinx.coroutines.test | |
import kotlinx.coroutines.* | ||
import kotlinx.coroutines.internal.* | ||
import kotlin.coroutines.* | ||
import kotlin.time.* | ||
|
||
/** | ||
* A coroutine scope that for launching test coroutines. | ||
|
@@ -84,6 +85,14 @@ public fun TestScope.runCurrent(): Unit = testScheduler.runCurrent() | |
@ExperimentalCoroutinesApi | ||
public fun TestScope.advanceTimeBy(delayTimeMillis: Long): Unit = testScheduler.advanceTimeBy(delayTimeMillis) | ||
|
||
/** | ||
* The [test scheduler][TestScope.testScheduler] as a [TimeSource]. | ||
* @see TestCoroutineScheduler.timeSource | ||
*/ | ||
@ExperimentalCoroutinesApi | ||
@ExperimentalTime | ||
public val TestScope.testTimeSource: TimeSource get() = testScheduler.timeSource | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't it be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was initially There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Works for me, thanks for the explanation There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added annotation as well |
||
|
||
/** | ||
* Creates a [TestScope]. | ||
* | ||
|
@@ -237,4 +246,4 @@ internal class UncaughtExceptionsBeforeTest : IllegalStateException( | |
* Thrown when a test has completed and there are tasks that are not completed or cancelled. | ||
*/ | ||
@ExperimentalCoroutinesApi | ||
internal class UncompletedCoroutinesError(message: String) : AssertionError(message) | ||
internal class UncompletedCoroutinesError(message: String) : AssertionError(message) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it is worth marking it as
ExperimentalCoroutinesApi
as well in case we'll decide to implementTimeSource
interface when it's stable?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, added