-
Notifications
You must be signed in to change notification settings - Fork 21
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
Added extensions for virtual time testing #19
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,12 @@ | |
package reactor.kotlin.test | ||
|
||
import org.junit.Test | ||
import reactor.core.publisher.Flux | ||
import reactor.core.publisher.Mono | ||
import reactor.kotlin.core.publisher.toMono | ||
import reactor.test.StepVerifierOptions | ||
import reactor.test.scheduler.VirtualTimeScheduler | ||
import java.time.Duration | ||
|
||
class StepVerifierExtensionsTests { | ||
|
||
|
@@ -53,4 +58,49 @@ class StepVerifierExtensionsTests { | |
.verifyError<IllegalStateException>() | ||
} | ||
|
||
@Test | ||
fun `testUsingVirtualTime()`() { | ||
{ Mono.just("foo").delayElement(Duration.ofDays(1)) } | ||
.testUsingVirtualTime() | ||
.thenAwait(Duration.ofDays(1)) | ||
.expectNext("foo") | ||
.verifyComplete() | ||
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. alternatively, each of these tests could use the 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. I think that's the better approach, so I decided to go with that one. As a bonus, the code is now indented in the same style as Sergei's tests above :) |
||
} | ||
|
||
@Test | ||
fun `testUsingVirtualTime() requesting n elements`() { | ||
{ Flux.just("foo", "bar").delayElements(Duration.ofDays(1)) } | ||
.testUsingVirtualTime(1) | ||
.thenAwait(Duration.ofDays(1)) | ||
.expectNext("foo") | ||
.expectNoEvent(Duration.ofDays(7)) | ||
.thenRequest(1) | ||
.thenAwait(Duration.ofDays(1)) | ||
.expectNext("bar") | ||
.verifyComplete() | ||
} | ||
|
||
@Test | ||
fun `testUsingVirtualTime() passing scheduler and requesting n elements`() { | ||
val vts = VirtualTimeScheduler.create() | ||
Flux.just("foo", "bar").delayElements(Duration.ofDays(1), vts) | ||
.testUsingVirtualTime({vts}, 1) | ||
.thenAwait(Duration.ofDays(1)) | ||
.expectNext("foo") | ||
.expectNoEvent(Duration.ofDays(7)) | ||
.thenRequest(1) | ||
.thenAwait(Duration.ofDays(1)) | ||
.expectNext("bar") | ||
.verifyComplete() | ||
} | ||
|
||
@Test | ||
fun `testUsingVirtualTime() passing options`() { | ||
val vts = VirtualTimeScheduler.create() | ||
Mono.just("foo").delayElement(Duration.ofDays(1), vts) | ||
.testUsingVirtualTime(StepVerifierOptions.create().virtualTimeSchedulerSupplier { vts }) | ||
.thenAwait(Duration.ofDays(1)) | ||
.expectNext("foo") | ||
.verifyComplete() | ||
} | ||
} |
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, if anything goes wrong, use
Duration.ofMinutes(10)
or something long enough that vts is significant, but if somehow it ends up using realtime the CI won't get stuck for too long?