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