mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-21 20:28:06 +01:00
Don't send a reply to clients until messages are safely in a non-volatile store.
This commit is contained in:
committed by
Jon Chambers
parent
321e6e6679
commit
bac268a21c
@@ -16,7 +16,6 @@ import org.whispersystems.textsecuregcm.storage.Device;
|
||||
import org.whispersystems.textsecuregcm.storage.MessagesManager;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyLong;
|
||||
@@ -57,8 +56,6 @@ public class MessageSenderTest {
|
||||
messagesManager,
|
||||
gcmSender,
|
||||
apnSender,
|
||||
0,
|
||||
mock(ExecutorService.class),
|
||||
mock(PushLatencyManager.class));
|
||||
|
||||
when(account.getUuid()).thenReturn(ACCOUNT_UUID);
|
||||
@@ -66,11 +63,11 @@ public class MessageSenderTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSendOnlineMessageClientPresent() {
|
||||
public void testSendOnlineMessageClientPresent() throws Exception {
|
||||
when(clientPresenceManager.isPresent(ACCOUNT_UUID, DEVICE_ID)).thenReturn(true);
|
||||
when(device.getGcmId()).thenReturn("gcm-id");
|
||||
|
||||
messageSender.sendSynchronousMessage(account, device, message, true);
|
||||
messageSender.sendMessage(account, device, message, true);
|
||||
|
||||
verify(messagesManager).insertEphemeral(ACCOUNT_UUID, DEVICE_ID, message);
|
||||
verify(messagesManager, never()).insert(any(), anyLong(), any());
|
||||
@@ -79,11 +76,11 @@ public class MessageSenderTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSendOnlineMessageClientNotPresent() {
|
||||
public void testSendOnlineMessageClientNotPresent() throws Exception {
|
||||
when(clientPresenceManager.isPresent(ACCOUNT_UUID, DEVICE_ID)).thenReturn(false);
|
||||
when(device.getGcmId()).thenReturn("gcm-id");
|
||||
|
||||
messageSender.sendSynchronousMessage(account, device, message, true);
|
||||
messageSender.sendMessage(account, device, message, true);
|
||||
|
||||
verify(messagesManager, never()).insertEphemeral(any(), anyLong(), any());
|
||||
verify(messagesManager, never()).insert(any(), anyLong(), any());
|
||||
@@ -92,11 +89,11 @@ public class MessageSenderTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSendMessageClientPresent() {
|
||||
public void testSendMessageClientPresent() throws Exception {
|
||||
when(clientPresenceManager.isPresent(ACCOUNT_UUID, DEVICE_ID)).thenReturn(true);
|
||||
when(device.getGcmId()).thenReturn("gcm-id");
|
||||
|
||||
messageSender.sendSynchronousMessage(account, device, message, false);
|
||||
messageSender.sendMessage(account, device, message, false);
|
||||
|
||||
verify(messagesManager, never()).insertEphemeral(any(), anyLong(), any());
|
||||
verify(messagesManager).insert(ACCOUNT_UUID, DEVICE_ID, message);
|
||||
@@ -105,11 +102,11 @@ public class MessageSenderTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSendMessageGcmClientNotPresent() {
|
||||
public void testSendMessageGcmClientNotPresent() throws Exception {
|
||||
when(clientPresenceManager.isPresent(ACCOUNT_UUID, DEVICE_ID)).thenReturn(false);
|
||||
when(device.getGcmId()).thenReturn("gcm-id");
|
||||
|
||||
messageSender.sendSynchronousMessage(account, device, message, false);
|
||||
messageSender.sendMessage(account, device, message, false);
|
||||
|
||||
verify(messagesManager, never()).insertEphemeral(any(), anyLong(), any());
|
||||
verify(messagesManager).insert(ACCOUNT_UUID, DEVICE_ID, message);
|
||||
@@ -118,11 +115,11 @@ public class MessageSenderTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSendMessageApnClientNotPresent() {
|
||||
public void testSendMessageApnClientNotPresent() throws Exception {
|
||||
when(clientPresenceManager.isPresent(ACCOUNT_UUID, DEVICE_ID)).thenReturn(false);
|
||||
when(device.getApnId()).thenReturn("apn-id");
|
||||
|
||||
messageSender.sendSynchronousMessage(account, device, message, false);
|
||||
messageSender.sendMessage(account, device, message, false);
|
||||
|
||||
verify(messagesManager, never()).insertEphemeral(any(), anyLong(), any());
|
||||
verify(messagesManager).insert(ACCOUNT_UUID, DEVICE_ID, message);
|
||||
@@ -131,11 +128,11 @@ public class MessageSenderTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSendMessageFetchClientNotPresent() {
|
||||
public void testSendMessageFetchClientNotPresent() throws Exception {
|
||||
when(clientPresenceManager.isPresent(ACCOUNT_UUID, DEVICE_ID)).thenReturn(false);
|
||||
when(device.getFetchesMessages()).thenReturn(true);
|
||||
|
||||
messageSender.sendSynchronousMessage(account, device, message, false);
|
||||
messageSender.sendMessage(account, device, message, false);
|
||||
|
||||
verify(messagesManager, never()).insertEphemeral(any(), anyLong(), any());
|
||||
verify(messagesManager).insert(ACCOUNT_UUID, DEVICE_ID, message);
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013-2020 Signal Messenger, LLC
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package org.whispersystems.textsecuregcm.tests.util;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.whispersystems.textsecuregcm.util.BlockingThreadPoolExecutor;
|
||||
import org.whispersystems.textsecuregcm.util.Util;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class BlockingThreadPoolExecutorTest {
|
||||
|
||||
@Test
|
||||
public void testBlocking() {
|
||||
BlockingThreadPoolExecutor executor = new BlockingThreadPoolExecutor("test", 1, 3);
|
||||
long start = System.currentTimeMillis();
|
||||
|
||||
executor.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Util.sleep(1000);
|
||||
}
|
||||
});
|
||||
|
||||
assertTrue(System.currentTimeMillis() - start < 500);
|
||||
start = System.currentTimeMillis();
|
||||
|
||||
executor.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Util.sleep(1000);
|
||||
}
|
||||
});
|
||||
|
||||
assertTrue(System.currentTimeMillis() - start < 500);
|
||||
|
||||
start = System.currentTimeMillis();
|
||||
|
||||
executor.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Util.sleep(1000);
|
||||
}
|
||||
});
|
||||
|
||||
assertTrue(System.currentTimeMillis() - start < 500);
|
||||
|
||||
start = System.currentTimeMillis();
|
||||
|
||||
executor.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Util.sleep(1000);
|
||||
}
|
||||
});
|
||||
|
||||
assertTrue(System.currentTimeMillis() - start > 500);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user