From 70c5b3abf439a288219efd147c5c37aeafd6ea3a Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Fri, 29 Jun 2018 14:22:04 +0200 Subject: Autotests: Allow to parameterize the "file unlock grace period" ... via the environment. This should help reduce false positives in our CI. Change-Id: I28492b4e476289f2d9418a272b167d9a679ebc5f Reviewed-by: Oliver Wolff --- tests/auto/api/tst_api.cpp | 5 +---- tests/auto/shared.h | 12 ++++++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/tests/auto/api/tst_api.cpp b/tests/auto/api/tst_api.cpp index 7af87fc32..e07aaf029 100644 --- a/tests/auto/api/tst_api.cpp +++ b/tests/auto/api/tst_api.cpp @@ -2202,10 +2202,7 @@ void TestApi::projectDataAfterProductInvalidation() void TestApi::processResult() { - // On Windows, even closed files seem to sometimes block the removal of their parent directories - // for a while. - if (qbs::Internal::HostOsInfo::isWindowsHost()) - QTest::qWait(500); + waitForFileUnlock(); removeBuildDir(defaultSetupParameters("process-result")); QFETCH(int, expectedExitCode); diff --git a/tests/auto/shared.h b/tests/auto/shared.h index b7a3e2b11..6f2552774 100644 --- a/tests/auto/shared.h +++ b/tests/auto/shared.h @@ -65,6 +65,18 @@ inline int testTimeoutInMsecs() return timeoutInSecs * 1000; } +// On Windows, it appears that a lock is sometimes held on files for a short while even after +// they are closed. The likelihood for that seems to increase with the slowness of the machine. +inline void waitForFileUnlock() +{ + bool ok; + int timeoutInSecs = qEnvironmentVariableIntValue("QBS_AUTOTEST_IO_GRACE_PERIOD", &ok); + if (!ok) + timeoutInSecs = qbs::Internal::HostOsInfo::isWindowsHost() ? 1 : 0; + if (timeoutInSecs > 0) + QTest::qWait(timeoutInSecs * 1000); +} + using SettingsPtr = std::unique_ptr; inline SettingsPtr settings() { -- cgit v1.2.3