Page MenuHomePhabricator

D4768.id15793.diff
No OneTemporary

D4768.id15793.diff

diff --git a/services/tunnelbroker/test/AmqpManagerTest.cpp b/services/tunnelbroker/test/AmqpManagerTest.cpp
--- a/services/tunnelbroker/test/AmqpManagerTest.cpp
+++ b/services/tunnelbroker/test/AmqpManagerTest.cpp
@@ -117,3 +117,37 @@
<< receivedMessage.payload;
AmqpManager::getInstance().ack(receivedMessage.deliveryTag);
}
+
+TEST_F(AmqpManagerTest, MultipleThreadsMessagesSendingStressTest) {
+ const size_t MESSAGES_NUMBER = 10;
+ const size_t THREADS_NUMBER = 100;
+ const std::string toDeviceID =
+ "mobile:" + tools::generateRandomString(DEVICEID_CHAR_LENGTH);
+
+ std::vector<std::thread> sendingThreads;
+ for (size_t i = 0; i < THREADS_NUMBER; ++i) {
+ sendingThreads.push_back(std::thread([toDeviceID, MESSAGES_NUMBER]() {
+ for (size_t i = 0; i < MESSAGES_NUMBER; ++i) {
+ const std::string messageID = tools::generateUUID();
+ const std::string fromDeviceID =
+ "web:" + tools::generateRandomString(DEVICEID_CHAR_LENGTH);
+ const std::string payload = tools::generateRandomString(512);
+ const database::MessageItem messageItem{
+ messageID, fromDeviceID, toDeviceID, payload, ""};
+ EXPECT_TRUE(AmqpManager::getInstance().send(&messageItem));
+ }
+ }));
+ }
+
+ std::vector<DeliveryBrokerMessage> receivedMessage;
+
+ for (size_t i = 0; i < MESSAGES_NUMBER * THREADS_NUMBER; ++i) {
+ receivedMessage.push_back(DeliveryBroker::getInstance().pop(toDeviceID));
+ AmqpManager::getInstance().ack(receivedMessage.back().deliveryTag);
+ }
+ EXPECT_TRUE(DeliveryBroker::getInstance().isEmpty(toDeviceID));
+ EXPECT_EQ(receivedMessage.size(), MESSAGES_NUMBER * THREADS_NUMBER);
+ for (std::thread &thread : sendingThreads) {
+ thread.join();
+ }
+}

File Metadata

Mime Type
text/plain
Expires
Fri, Dec 27, 4:45 AM (9 h, 29 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2710567
Default Alt Text
D4768.id15793.diff (1 KB)

Event Timeline