Testing Mono.sequenceEqual

822 views Asked by At

I'm trying to figure out how to verify sequenceEqual method in Mono. My code is as follow:

Mono<Boolean> mono = Mono.sequenceEqual(Mono.just(1), Mono.just(1));
StepVerifier.create(mono)
    .expectNext(true)
    .expectComplete()
    .verify();

And here is the stacktrace I got

- java.lang.Throwable: Multiple exceptions
- java.lang.AssertionError: expectation "defaultOnSubscribe" failed (expected: onSubscribe(); actual: onNext(true))
- java.lang.AssertionError: expectation "expectNext(true)" failed (expected: onNext(true); actual: onComplete())
at reactor.test.DefaultStepVerifierBuilder$DefaultVerifySubscriber.validate(DefaultStepVerifierBuilder.java:1337)
at reactor.test.DefaultStepVerifierBuilder$DefaultVerifySubscriber.verify(DefaultStepVerifierBuilder.java:827)
at reactor.test.DefaultStepVerifierBuilder$DefaultStepVerifier.verify(DefaultStepVerifierBuilder.java:533)
at reactor.test.DefaultStepVerifierBuilder$DefaultStepVerifier.verify(DefaultStepVerifierBuilder.java:508)
1

There are 1 answers

3
Simon Baslé On

This operator isn't well-behaved with regard to subscription signal propagation, and since the StepVerifier expects a well-behaved Publisher all the way, you get an error.

To work around this bug, you could regularly subscribe to sequenceEqual and have a custom subscriber capture the events in AtomicReference or similar then assert those...