Skip to content

Commit

Permalink
Fix one more STOMP WebSocket test race condition
Browse files Browse the repository at this point in the history
https://build.spring.io/browse/INT-B43-JOB1-7

We need to wait for the **real** `UNSUBSCRIBE` from server before go ahead.
  • Loading branch information
artembilan committed Nov 20, 2015
1 parent e55a7b8 commit 350355e
Showing 1 changed file with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,10 @@ public void testWebSocketStompClient() throws Exception {

this.stompInboundChannelAdapter.removeDestination("/topic/myTopic");

waitForUnsubscribe("/topic/myTopic");

messagingTemplate.convertAndSend("/topic/myTopic", "foo");
receive = this.stompInputChannel.receive(1000);
receive = this.errorChannel.receive(100);
assertNull(receive);

this.stompInboundChannelAdapter.addDestination("/topic/myTopic");
Expand Down Expand Up @@ -191,6 +193,7 @@ public void testWebSocketStompClient() throws Exception {
messagingTemplate.convertAndSend("/topic/myTopic", "foo");
receive = this.errorChannel.receive(10000);
assertNotNull(receive);
assertEquals(0, ((QueueChannel) this.errorChannel).getQueueSize());
}

private void waitForSubscribe(String destination) throws InterruptedException {
Expand All @@ -207,6 +210,21 @@ private void waitForSubscribe(String destination) throws InterruptedException {
assertTrue("The subscription for the '" + destination + "' destination hasn't been registered", n < 100);
}

private void waitForUnsubscribe(String destination) throws InterruptedException {
SimpleBrokerMessageHandler serverBrokerMessageHandler =
this.serverContext.getBean("simpleBrokerMessageHandler", SimpleBrokerMessageHandler.class);

SubscriptionRegistry subscriptionRegistry = serverBrokerMessageHandler.getSubscriptionRegistry();

int n = 0;
while (containsDestination(destination, subscriptionRegistry) && n++ < 100) {
Thread.sleep(100);
}

assertTrue("The subscription for the '" + destination + "' destination hasn't been registered", n < 100);
}


private boolean containsDestination(String destination, SubscriptionRegistry subscriptionRegistry) {
StompHeaderAccessor stompHeaderAccessor = StompHeaderAccessor.create(StompCommand.MESSAGE);
stompHeaderAccessor.setDestination(destination);
Expand Down

0 comments on commit 350355e

Please sign in to comment.