Avoid possible race condition

Change-Id: I12988ad9583740b2c72d8e40e68414a7cba08364
Reviewed-by: Niels Weber <niels.weber@theqtcompany.com>
Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
This commit is contained in:
Christian Stenger
2016-01-19 13:31:55 +01:00
parent 3b423602ed
commit e60a7a6923

View File

@@ -180,8 +180,13 @@ static void performTestRun(QFutureInterface<TestResult *> &futureInterface,
bool ok = testProcess.waitForStarted();
QTime executionTimer;
executionTimer.start();
bool canceledByTimeout = false;
if (ok) {
while (testProcess.state() == QProcess::Running && executionTimer.elapsed() < timeout) {
while (testProcess.state() == QProcess::Running) {
if (executionTimer.elapsed() >= timeout) {
canceledByTimeout = true;
break;
}
if (futureInterface.isCanceled()) {
testProcess.kill();
testProcess.waitForFinished();
@@ -191,13 +196,13 @@ static void performTestRun(QFutureInterface<TestResult *> &futureInterface,
}
}
if (executionTimer.elapsed() >= timeout) {
if (canceledByTimeout) {
if (testProcess.state() != QProcess::NotRunning) {
testProcess.kill();
testProcess.waitForFinished();
futureInterface.reportResult(new FaultyTestResult(Result::MessageFatal, QObject::tr(
"Test case canceled due to timeout. \nMaybe raise the timeout?")));
}
futureInterface.reportResult(new FaultyTestResult(Result::MessageFatal, QObject::tr(
"Test case canceled due to timeout. \nMaybe raise the timeout?")));
}
}
futureInterface.setProgressValue(testCaseCount);