Skip to content

Commit

Permalink
fix: Fix regression when sync id check is disabled (#17238)
Browse files Browse the repository at this point in the history
When syncId check is disabled, long-polling push cache filter always cached all messages.
This change fixes the regression, by preventing message cache when syncId check is disabled.
  • Loading branch information
TatuLund authored and vaadin-bot committed Jul 20, 2023
1 parent 643fcee commit 6b68024
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Expand Up @@ -68,7 +68,10 @@ public BroadcastAction filter(String broadcasterId, AtmosphereResource r,
String uuid = r.uuid();
int lastSeenOnClient = session.getAttribute(SEEN_SERVER_SYNC_ID,
Integer.class);
if (pushMessage.alreadySeen(lastSeenOnClient)) {
if (lastSeenOnClient == -1) {
return new BroadcastAction(BroadcastAction.ACTION.CONTINUE,
message);
} else if (pushMessage.alreadySeen(lastSeenOnClient)) {
getLogger().trace(
"Discarding message {} for resource {} as client already seen {}. {}",
pushMessage.serverSyncId, uuid, lastSeenOnClient,
Expand Down
Expand Up @@ -73,6 +73,19 @@ public void filter_notLongPollingTransport_continueWithCurrentMessage() {
verifyMessageIsNotCached();
}

@Test
public void filter_syncIdCheckDisabled_continueWithCurrentMessage() {
setTransport(AtmosphereResource.TRANSPORT.LONG_POLLING);
setSeenServerSyncIdHeader(-1);
BroadcastAction action = filter.filter("broadcasterId", resource,
originalMessage, message);
Assert.assertEquals(ACTION.CONTINUE, action.action());
Assert.assertSame(
"Message should not be altered by filter if syncId check is disabled",
message, action.message());
verifyMessageIsNotCached();
}

@Test
public void filter_missingLastSeenServerSyncId_continueWithCurrentMessage() {
setTransport(AtmosphereResource.TRANSPORT.LONG_POLLING);
Expand Down Expand Up @@ -216,4 +229,4 @@ private void simulatePushConnection() {
private void verifyMessageIsNotCached() {
Mockito.verifyNoInteractions(cache);
}
}
}

0 comments on commit 6b68024

Please sign in to comment.