Harden synchronization around SockJS heartbeats

Create an explicit heartbeat task with an experiration flag so that
it can be cancelled reliably vs relying on the ScheduledFutureTask
cancel method which may return true even if the task is already
running.

Issue: SPR-14356
This commit is contained in:
Rossen Stoyanchev
2016-08-29 14:12:32 -04:00
parent ca09dcbe89
commit 5075dd4dfa
2 changed files with 54 additions and 57 deletions

View File

@@ -270,6 +270,7 @@ public class SockJsSessionTests extends AbstractSockJsSessionTests<TestSockJsSes
@Test
public void sendHeartbeatWhenDisabled() throws Exception {
this.session.disableHeartbeat();
this.session.setActive(true);
this.session.sendHeartbeat();
assertEquals(Collections.emptyList(), this.session.getSockJsFramesWritten());
@@ -292,7 +293,6 @@ public class SockJsSessionTests extends AbstractSockJsSessionTests<TestSockJsSes
this.session.cancelHeartbeat();
verify(task).isCancelled();
verify(task).cancel(false);
verifyNoMoreInteractions(task);
}