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 2aab08f093
commit 16879a2cf0
2 changed files with 55 additions and 58 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);
}