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