Retire the explicit "handle new message available" system in favor of implicit presence-on-insert values

This commit is contained in:
Jon Chambers
2024-11-07 16:21:44 -05:00
committed by Jon Chambers
parent eeeb565313
commit 084607f359
7 changed files with 28 additions and 126 deletions

View File

@@ -10,6 +10,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyByte;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -20,7 +21,6 @@ import com.google.protobuf.ByteString;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import org.apache.commons.lang3.RandomStringUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.params.ParameterizedTest;
@@ -35,21 +35,16 @@ import org.whispersystems.textsecuregcm.storage.MessagesManager;
class MessageSenderTest {
private PubSubClientEventManager pubSubClientEventManager;
private MessagesManager messagesManager;
private PushNotificationManager pushNotificationManager;
private MessageSender messageSender;
@BeforeEach
void setUp() {
pubSubClientEventManager = mock(PubSubClientEventManager.class);
messagesManager = mock(MessagesManager.class);
pushNotificationManager = mock(PushNotificationManager.class);
when(pubSubClientEventManager.handleNewMessageAvailable(any(), anyByte()))
.thenReturn(CompletableFuture.completedFuture(true));
messageSender = new MessageSender(pubSubClientEventManager, messagesManager, pushNotificationManager);
messageSender = new MessageSender(messagesManager, pushNotificationManager);
}
@CartesianTest
@@ -77,10 +72,9 @@ class MessageSenderTest {
.when(pushNotificationManager).sendNewMessageNotification(any(), anyByte(), anyBoolean());
}
when(pubSubClientEventManager.handleNewMessageAvailable(accountIdentifier, deviceId))
.thenReturn(CompletableFuture.completedFuture(clientPresent));
when(messagesManager.insert(eq(accountIdentifier), eq(deviceId), any())).thenReturn(clientPresent);
assertDoesNotThrow(() -> messageSender.sendMessage(account, device, message, onlineMessage).join());
assertDoesNotThrow(() -> messageSender.sendMessage(account, device, message, onlineMessage));
final MessageProtos.Envelope expectedMessage = onlineMessage
? message.toBuilder().setEphemeral(true).build()

View File

@@ -140,30 +140,6 @@ class PubSubClientEventManagerTest {
assertTrue(firstListenerConnectedElsewhere.get());
}
@ParameterizedTest
@ValueSource(booleans = {true, false})
void handleNewMessageAvailable(final boolean messageAvailableRemotely) throws InterruptedException {
final UUID accountIdentifier = UUID.randomUUID();
final byte deviceId = Device.PRIMARY_ID;
final CountDownLatch messageReceivedLatch = new CountDownLatch(1);
localPresenceManager.handleClientConnected(accountIdentifier, deviceId, new ClientEventAdapter() {
@Override
public void handleNewMessageAvailable() {
messageReceivedLatch.countDown();
}
}).toCompletableFuture().join();
final PubSubClientEventManager messagePresenceManager =
messageAvailableRemotely ? remotePresenceManager : localPresenceManager;
assertTrue(messagePresenceManager.handleNewMessageAvailable(accountIdentifier, deviceId).toCompletableFuture().join());
assertTrue(messageReceivedLatch.await(2, TimeUnit.SECONDS),
"Message not received within time limit");
}
@ParameterizedTest
@ValueSource(booleans = {true, false})
void handleMessagesPersisted(final boolean messagesPersistedRemotely) throws InterruptedException {
@@ -188,21 +164,6 @@ class PubSubClientEventManagerTest {
"Message persistence event not received within time limit");
}
@Test
void handleClientDisconnected() {
final UUID accountIdentifier = UUID.randomUUID();
final byte deviceId = Device.PRIMARY_ID;
localPresenceManager.handleClientConnected(accountIdentifier, deviceId, new ClientEventAdapter())
.toCompletableFuture().join();
assertTrue(localPresenceManager.handleNewMessageAvailable(accountIdentifier, deviceId).toCompletableFuture().join());
localPresenceManager.handleClientDisconnected(accountIdentifier, deviceId).toCompletableFuture().join();
assertFalse(localPresenceManager.handleNewMessageAvailable(accountIdentifier, deviceId).toCompletableFuture().join());
}
@Test
void isLocallyPresent() {
final UUID accountIdentifier = UUID.randomUUID();