When a flux has a delayElements operator, the StepVerifier.Step.expectNoEvent correctly throws an AssertionError if an event is emitted before the duration.
Consider the following test:
@Test
public void testWithDelayElements() {
StepVerifier.withVirtualTime(() -> Flux.just(1, 2, 3).delayElements(Duration.ofSeconds(1)))
.expectSubscription()
.expectNoEvent(Duration.ofSeconds(2))
.expectNext(1)
.thenCancel()
.verify();
}
which throws
expectation failed (expected no event: onNext(1))
java.lang.AssertionError:...
However, if the flux doesn't have a delayElements operator, then the test passes.
@Test
public void testWithoutDelayElements() {
StepVerifier.withVirtualTime(() -> Flux.just(1, 2, 3))
.expectSubscription()
.expectNoEvent(Duration.ofSeconds(2))
.expectNext(1)
.thenCancel()
.verify();
}
I don't understand why this passes?
Edit: I see there is a similar GitHub issue which seems to explain the blocking behavior of expectNoEvent in one of the comments. However, that seems to apply when virtual time scheduler is not being used. I am using the virtual time schedular, so the thread should not be blocked, right?