diff --git a/src/libcalamares/utils/Tests.cpp b/src/libcalamares/utils/Tests.cpp index e38aed0f2..acd6ee2c0 100644 --- a/src/libcalamares/utils/Tests.cpp +++ b/src/libcalamares/utils/Tests.cpp @@ -31,6 +31,8 @@ #include +#include + #include #include #include @@ -56,6 +58,7 @@ private Q_SLOTS: void testCommandConstructors(); void testCommandConstructorsYAML(); void testCommandRunning(); + void testCommandTimeout(); void testCommandVerbose(); /** @section Test that all the UMask objects work correctly. */ @@ -455,6 +458,38 @@ LibCalamaresTests::testCommandRunning() tempRoot.setAutoRemove( true ); } +void +LibCalamaresTests::testCommandTimeout() +{ + + QTemporaryDir tempRoot( QDir::tempPath() + QStringLiteral( "/test-job-XXXXXX" ) ); + tempRoot.setAutoRemove( false ); + + const QString testExecutable = tempRoot.filePath( "example.sh" ); + + cDebug() << "Creating example executable" << testExecutable; + + { + QFile f( testExecutable ); + QVERIFY( f.open( QIODevice::WriteOnly ) ); + f.write( "#! /bin/sh\necho early\nsleep 3\necho late" ); + f.close(); + Calamares::Permissions::apply( testExecutable, 0755 ); + } + + { + Calamares::CommandList l( false ); // no chroot + Calamares::CommandLine c( testExecutable, {}, std::chrono::seconds( 2 ) ); + l.push_back( c ); + + const auto r = l.run(); + QVERIFY( !bool( r ) ); // Because it times out after 2 seconds + // The **command** timed out, but the job result is a generic "error" + // QCOMPARE( r.errorCode(), static_cast>(Calamares::ProcessResult::Code::TimedOut)); + QCOMPARE( r.errorCode(), -1 ); + } +} + void LibCalamaresTests::testCommandVerbose() {