How to test multiple input events using StepVerifier

How to test multiple input events using StepVerifier


0

I want to test receiving multiple events for GraphQl subscription.
For this I tried to use the following code:

    StepVerifier stepVerifier = StepVerifier.create(flux)
        .expectSubscription()
        .expectNext(expectingEvent1)
        .expectNext(expectingEvent2)
        .thenCancel()
        .verifyLater();

    graphQlService.sendEvent(sendingEvent1);
    graphQlService.sendEvent(sendingEvent2);
    stepVerifier.verify();

Method sendEvent contains the following logic:
fluxSinks.forEach(fluxSink -> fluxSink.next(response));
But it seems that in this test only the first event is sent, judging by the test logs. What needs to be fixed in the test to check both events in one StepVerifier?

P.S. As expected, this approach works, but it seems to me that it is possible to do the same in one StepVerifier:

    StepVerifier stepVerifier1 = StepVerifier.create(flux)
        .expectSubscription()
        .expectNext(expectingEvent1)
        .thenCancel()
        .verifyLater();
    graphQlService.sendEvent(sendingEvent1);
    stepVerifier1.verify();

    StepVerifier stepVerifier2 = StepVerifier.create(flux)
        .expectSubscription()
        .expectNext(expectingEvent2)
        .thenCancel()
        .verifyLater();
    graphQlService.sendEvent(sendingEvent2);
    stepVerifier2.verify();

I also tried the method .expectNextSequence(), but it did not help.

New contributor

Дмитрий Кулеба is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.


Load 6 more related questions


Show fewer related questions

0



Leave a Reply

Your email address will not be published. Required fields are marked *