Fix memory leaks & data races in tests (#4772)
* Add a few pre-made sanitizer suppressions * Test Sanitization: Fix threading issues * Test Sanitization: Allow deletion of PubSub We still don't delete it in main code, but this allows us to try deleting it in tests. * Test Sanitization: Fix some memory leaks * fix gtest clang-tidy warning * const emojis test :-)
This commit is contained in:
@@ -4,6 +4,8 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <QString>
|
||||
|
||||
#include <tuple>
|
||||
|
||||
using namespace chatterino;
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
@@ -13,30 +15,30 @@ const QString TARGET_USER_NAME = "Alien";
|
||||
TEST(BttvLiveUpdates, AllEvents)
|
||||
{
|
||||
const QString host("wss://127.0.0.1:9050/liveupdates/bttv/all-events");
|
||||
auto *liveUpdates = new BttvLiveUpdates(host);
|
||||
liveUpdates->start();
|
||||
chatterino::BttvLiveUpdates liveUpdates(host);
|
||||
liveUpdates.start();
|
||||
|
||||
boost::optional<BttvLiveUpdateEmoteUpdateAddMessage> addMessage;
|
||||
boost::optional<BttvLiveUpdateEmoteUpdateAddMessage> updateMessage;
|
||||
boost::optional<BttvLiveUpdateEmoteRemoveMessage> removeMessage;
|
||||
|
||||
liveUpdates->signals_.emoteAdded.connect([&](const auto &m) {
|
||||
std::ignore = liveUpdates.signals_.emoteAdded.connect([&](const auto &m) {
|
||||
addMessage = m;
|
||||
});
|
||||
liveUpdates->signals_.emoteUpdated.connect([&](const auto &m) {
|
||||
std::ignore = liveUpdates.signals_.emoteUpdated.connect([&](const auto &m) {
|
||||
updateMessage = m;
|
||||
});
|
||||
liveUpdates->signals_.emoteRemoved.connect([&](const auto &m) {
|
||||
std::ignore = liveUpdates.signals_.emoteRemoved.connect([&](const auto &m) {
|
||||
removeMessage = m;
|
||||
});
|
||||
|
||||
std::this_thread::sleep_for(50ms);
|
||||
liveUpdates->joinChannel(TARGET_USER_ID, TARGET_USER_NAME);
|
||||
liveUpdates.joinChannel(TARGET_USER_ID, TARGET_USER_NAME);
|
||||
std::this_thread::sleep_for(500ms);
|
||||
|
||||
ASSERT_EQ(liveUpdates->diag.connectionsOpened, 1);
|
||||
ASSERT_EQ(liveUpdates->diag.connectionsClosed, 0);
|
||||
ASSERT_EQ(liveUpdates->diag.connectionsFailed, 0);
|
||||
ASSERT_EQ(liveUpdates.diag.connectionsOpened, 1);
|
||||
ASSERT_EQ(liveUpdates.diag.connectionsClosed, 0);
|
||||
ASSERT_EQ(liveUpdates.diag.connectionsFailed, 0);
|
||||
|
||||
auto add = *addMessage;
|
||||
ASSERT_EQ(add.channelID, TARGET_USER_ID);
|
||||
@@ -52,8 +54,8 @@ TEST(BttvLiveUpdates, AllEvents)
|
||||
ASSERT_EQ(rem.channelID, TARGET_USER_ID);
|
||||
ASSERT_EQ(rem.emoteID, QString("55898e122612142e6aaa935b"));
|
||||
|
||||
liveUpdates->stop();
|
||||
ASSERT_EQ(liveUpdates->diag.connectionsOpened, 1);
|
||||
ASSERT_EQ(liveUpdates->diag.connectionsClosed, 1);
|
||||
ASSERT_EQ(liveUpdates->diag.connectionsFailed, 0);
|
||||
liveUpdates.stop();
|
||||
ASSERT_EQ(liveUpdates.diag.connectionsOpened, 1);
|
||||
ASSERT_EQ(liveUpdates.diag.connectionsClosed, 1);
|
||||
ASSERT_EQ(liveUpdates.diag.connectionsFailed, 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user