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 <flowlnlnln@gmail.com>
This commit is contained in:
parent
92aa24ae34
commit
0c9d03f5df
@ -35,6 +35,7 @@
|
|||||||
|
|
||||||
#include <QTest>
|
#include <QTest>
|
||||||
#include <QTemporaryDir>
|
#include <QTemporaryDir>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
#include "FileSystem.h"
|
#include "FileSystem.h"
|
||||||
#include "minecraft/mod/ModFolderModel.h"
|
#include "minecraft/mod/ModFolderModel.h"
|
||||||
@ -65,11 +66,25 @@ slots:
|
|||||||
{
|
{
|
||||||
QString folder = source;
|
QString folder = source;
|
||||||
QTemporaryDir tempDir;
|
QTemporaryDir tempDir;
|
||||||
|
|
||||||
QEventLoop loop;
|
QEventLoop loop;
|
||||||
|
|
||||||
ModFolderModel m(tempDir.path(), true);
|
ModFolderModel m(tempDir.path(), true);
|
||||||
|
|
||||||
connect(&m, &ModFolderModel::updateFinished, &loop, &QEventLoop::quit);
|
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);
|
m.installMod(folder);
|
||||||
|
|
||||||
loop.exec();
|
loop.exec();
|
||||||
|
|
||||||
|
QVERIFY2(expire_timer.isActive(), "Timer has expired. The update never finished.");
|
||||||
|
expire_timer.stop();
|
||||||
|
|
||||||
verify(tempDir.path());
|
verify(tempDir.path());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,9 +94,21 @@ slots:
|
|||||||
QTemporaryDir tempDir;
|
QTemporaryDir tempDir;
|
||||||
QEventLoop loop;
|
QEventLoop loop;
|
||||||
ModFolderModel m(tempDir.path(), true);
|
ModFolderModel m(tempDir.path(), true);
|
||||||
|
|
||||||
connect(&m, &ModFolderModel::updateFinished, &loop, &QEventLoop::quit);
|
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);
|
m.installMod(folder);
|
||||||
|
|
||||||
loop.exec();
|
loop.exec();
|
||||||
|
|
||||||
|
QVERIFY2(expire_timer.isActive(), "Timer has expired. The update never finished.");
|
||||||
|
expire_timer.stop();
|
||||||
|
|
||||||
verify(tempDir.path());
|
verify(tempDir.path());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user