AutoTest: Disable timeout by default

Usually test frameworks or tools have their own timeout
handling or not at all.
Let the user decide whether to use a timeout or not.
This is a behavior change as now the test run does not
get automatically canceled anymore except when the user
explicitly enables this feature.

Fixes: QTCREATORBUG-30668
Change-Id: Ic5d98db0c52bfea092e427d317b12c41d6484ad0
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Stenger
2024-04-18 15:29:27 +02:00
parent 820e65894d
commit a7f92dd8be
7 changed files with 25 additions and 15 deletions

View File

@@ -359,10 +359,6 @@
found by the code based test frameworks and are registered as test
with the build system.
If a test takes more than a minute to execute, the default timeout might
stop the test execution. To increase the timeout, go to \preferences >
\uicontrol {Testing} > \uicontrol General.
\section1 Select tests to run
The \uicontrol Tests view shows all the tests found for the currently active
@@ -501,7 +497,7 @@
the current project.
\row
\li \uicontrol {Timeout}
\li The maximum time in seconds to execute a test case.
\li Set a maximum time in seconds to execute a test case.
\row
\li \uicontrol {Reset Cached Choices}
\li Sometimes, \QC cannot deduce which executable or run configuration to

View File

@@ -87,7 +87,11 @@ QList<ITestConfiguration *> CTestTreeItem::testConfigurationsFor(const QStringLi
return {};
const ProjectExplorer::BuildSystem *buildSystem = target->buildSystem();
QStringList options{"--timeout", QString::number(testSettings().timeout() / 1000)};
QStringList options;
if (testSettings().useTimeout()) {
options << "--timeout"
<< QString::number(testSettings().timeout() / 1000);
}
options << theCTestTool().activeSettingsAsOptions();
CommandLine command = buildSystem->commandLineForTests(selected, options);
if (command.executable().isEmpty())

View File

@@ -137,9 +137,11 @@ Environment prepareBasicEnvironment(const Environment &env)
result.set("QT_FORCE_STDERR_LOGGING", "1");
result.set("QT_LOGGING_TO_CONSOLE", "1");
}
if (testSettings().useTimeout()) {
const int timeout = testSettings().timeout();
if (timeout > 5 * 60 * 1000) // Qt5.5 introduced hard limit, Qt5.6.1 added env var to raise this
result.set("QTEST_FUNCTION_TIMEOUT", QString::number(timeout));
}
return result;
}

View File

@@ -412,8 +412,10 @@ void TestRunner::runTestsHelper()
}
process.setEnvironment(environment);
if (testSettings().useTimeout()) {
m_cancelTimer.setInterval(testSettings().timeout());
m_cancelTimer.start();
}
qCInfo(runnerLog) << "Command:" << process.commandLine().executable();
qCInfo(runnerLog) << "Arguments:" << process.commandLine().arguments();

View File

@@ -33,13 +33,19 @@ TestSettings::TestSettings()
scanThreadLimit.setSpecialValueText("Automatic");
scanThreadLimit.setToolTip(Tr::tr("Number of worker threads used when scanning for tests."));
useTimeout.setSettingsKey("UseTimeout");
useTimeout.setDefaultValue(false);
useTimeout.setLabelText(Tr::tr("Timeout"));
useTimeout.setToolTip(Tr::tr("Use a timeout while executing test cases."));
timeout.setSettingsKey("Timeout");
timeout.setDefaultValue(defaultTimeout);
timeout.setRange(5000, 36'000'000); // 36 Mio ms = 36'000 s = 10 h
timeout.setSuffix(Tr::tr(" s")); // we show seconds, but store milliseconds
timeout.setDisplayScaleFactor(1000);
timeout.setToolTip(Tr::tr("Timeout used when executing test cases. This will apply "
"for each test case on its own, not the whole project."));
"for each test case on its own, not the whole project. "
"Overrides test framework or build system defaults."));
omitInternalMsg.setSettingsKey("OmitInternal");
omitInternalMsg.setDefaultValue(true);
@@ -106,6 +112,7 @@ TestSettings::TestSettings()
fromSettings();
timeout.setEnabler(&useTimeout);
resultDescriptionMaxSize.setEnabler(&limitResultDescription);
popupOnFail.setEnabler(&popupOnFinish);
}

View File

@@ -31,6 +31,7 @@ public:
void fromSettings();
Utils::IntegerAspect scanThreadLimit{this};
Utils::BoolAspect useTimeout{this};
Utils::IntegerAspect timeout{this};
Utils::BoolAspect omitInternalMsg{this};
Utils::BoolAspect omitRunConfigWarn{this};

View File

@@ -50,8 +50,6 @@ private:
TestSettingsWidget::TestSettingsWidget()
{
auto timeoutLabel = new QLabel(Tr::tr("Timeout:"));
timeoutLabel->setToolTip(Tr::tr("Timeout used when executing each test case."));
auto scanThreadLabel = new QLabel(Tr::tr("Scan threads:"));
scanThreadLabel->setToolTip("Number of worker threads used when scanning for tests.");
@@ -98,7 +96,7 @@ TestSettingsWidget::TestSettingsWidget()
s.displayApplication,
s.processArgs,
Row { Tr::tr("Automatically run"), s.runAfterBuild, st },
Row { timeoutLabel, s.timeout, st },
Row { s.useTimeout, s.timeout, st },
Row { resetChoicesButton, st }
}
};