[partition] Test automount job in a queue

This commit is contained in:
Adriaan de Groot 2021-02-03 01:26:49 +01:00
parent 38fa1d9567
commit 17f73b1294
2 changed files with 31 additions and 1 deletions

View File

@ -25,7 +25,8 @@ AutoMountManagementJob::prettyName() const
Calamares::JobResult
AutoMountManagementJob::exec()
{
Logger::CDebug(Logger::LOGVERBOSE) << "this" << Logger::Pointer( this ) << "value" << Logger::Pointer( m_stored );
Logger::CDebug( Logger::LOGVERBOSE ) << "this" << Logger::Pointer( this ) << "value" << Logger::Pointer( m_stored )
<< ( m_stored ? "restore" : m_disable ? "disable" : "enable" );
if ( m_stored )
{
CalamaresUtils::Partition::automountRestore( m_stored );

View File

@ -10,6 +10,7 @@
#include "jobs/AutoMountManagementJob.h"
#include "utils/Logger.h"
#include "JobQueue.h"
#include <QObject>
#include <QtTest/QtTest>
@ -22,6 +23,7 @@ public:
private Q_SLOTS:
void testRunThrice();
void testRunQueue();
};
AutoMountJobTests::AutoMountJobTests() {}
@ -50,6 +52,33 @@ AutoMountJobTests::testRunThrice()
CalamaresUtils::Partition::automountRestore( original );
}
void AutoMountJobTests::testRunQueue()
{
Calamares::JobQueue q;
Calamares::job_ptr jp( new AutoMountManagementJob( false ) );
QSignalSpy progress( &q, &Calamares::JobQueue::progress );
QSignalSpy finish( &q, &Calamares::JobQueue::finished );
QSignalSpy fail( &q, &Calamares::JobQueue::failed );
Logger::setupLogLevel( Logger::LOGVERBOSE );
cDebug() << "Got automount job" << jp;
QVERIFY( !q.isRunning() );
q.enqueue( 2, { jp, jp } );
QVERIFY( !q.isRunning() );
QEventLoop loop;
QTimer::singleShot( std::chrono::milliseconds( 100 ), [&q](){ q.start(); } );
QTimer::singleShot( std::chrono::milliseconds( 5000 ), [&loop](){ loop.quit(); } );
connect( &q, &Calamares::JobQueue::finished, &loop, &QEventLoop::quit );
loop.exec();
QCOMPARE( fail.count(), 0 );
QCOMPARE( finish.count(), 1 );
// 5 progress: 0% and 100% for each *job* and then 100% overall
QCOMPARE( progress.count(), 5 );
}
QTEST_GUILESS_MAIN( AutoMountJobTests )