dgs-framework icon indicating copy to clipboard operation
dgs-framework copied to clipboard

bug: Websocket Subscription client can miss events during subscribing

Open paulbakker opened this issue 3 years ago • 3 comments

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();

paulbakker avatar Sep 24 '21 17:09 paulbakker

@callumforrester FYI. We'll fix this eventually, but in case you want to have a look at it.

paulbakker avatar Sep 24 '21 17:09 paulbakker

@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.

callumforrester avatar Sep 27 '21 08:09 callumforrester

any progress here?

MarianPohling avatar Jun 27 '23 10:06 MarianPohling