From 0c9d03f5dffc37f3eda500fd520907a142ac061f Mon Sep 17 00:00:00 2001 From: flow Date: Sun, 7 Aug 2022 08:34:26 -0300 Subject: [PATCH] fix(tests): add timeout on ModFolderModel's tests If the update never ends, the signal is not emitted and we become stuck in the event loop forever. So a very lenient timer is added to prevent that. Signed-off-by: flow --- .../minecraft/mod/ModFolderModel_test.cpp | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/launcher/minecraft/mod/ModFolderModel_test.cpp b/launcher/minecraft/mod/ModFolderModel_test.cpp index b4d37ce5..1b50ebd6 100644 --- a/launcher/minecraft/mod/ModFolderModel_test.cpp +++ b/launcher/minecraft/mod/ModFolderModel_test.cpp @@ -35,6 +35,7 @@ #include #include +#include #include "FileSystem.h" #include "minecraft/mod/ModFolderModel.h" @@ -65,11 +66,25 @@ slots: { QString folder = source; QTemporaryDir tempDir; + QEventLoop loop; + ModFolderModel m(tempDir.path(), true); + connect(&m, &ModFolderModel::updateFinished, &loop, &QEventLoop::quit); + + QTimer expire_timer; + expire_timer.callOnTimeout(&loop, &QEventLoop::quit); + expire_timer.setSingleShot(true); + expire_timer.start(4000); + m.installMod(folder); + loop.exec(); + + QVERIFY2(expire_timer.isActive(), "Timer has expired. The update never finished."); + expire_timer.stop(); + verify(tempDir.path()); } @@ -79,9 +94,21 @@ slots: QTemporaryDir tempDir; QEventLoop loop; ModFolderModel m(tempDir.path(), true); + connect(&m, &ModFolderModel::updateFinished, &loop, &QEventLoop::quit); + + QTimer expire_timer; + expire_timer.callOnTimeout(&loop, &QEventLoop::quit); + expire_timer.setSingleShot(true); + expire_timer.start(4000); + m.installMod(folder); + loop.exec(); + + QVERIFY2(expire_timer.isActive(), "Timer has expired. The update never finished."); + expire_timer.stop(); + verify(tempDir.path()); } }