dgs-framework
dgs-framework copied to clipboard
bug: Websocket Subscription client can miss events during subscribing
The handshake between client/server in the Websocket subscription client happens in a Mono.defer
. Because of this, there is a small gap in when the subscription returns, and when the subscription is actually listening for events.
I ran into this issue while writing a test that listens for subscription events that trigger when a mutation is processed. Without adding a small delay after subscribing, the first event will be missed.
This is likely only a problem in tests, but is very confusing.
StepVerifier.create(starScore)
.thenAwait(Duration.ofSeconds(1)) //The await is required to not miss the first event!
.then(() -> {
graphQLClient.reactiveExecuteQuery(addReviewMutation1.serialize(), Collections.emptyMap(), requestExecutor).block();
})
.then(() ->
graphQLClient.reactiveExecuteQuery(addReviewMutation2.serialize(), Collections.emptyMap(), requestExecutor).block())
.expectNext(5)
.expectNext(3)
.thenCancel()
.verify();
@callumforrester FYI. We'll fix this eventually, but in case you want to have a look at it.
@paulbakker thanks for raising this, I will take a look if I have time. Having only skimmed it, I've had some issues writing tests like this in the past because of https://github.com/reactor/reactor-core/issues/2139, I wonder if that could be hindering you here.
any progress here?