summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/io/qlockfile
diff options
context:
space:
mode:
authorAhmad Samir <a.samirh78@gmail.com>2023-02-27 21:50:23 +0200
committerAhmad Samir <a.samirh78@gmail.com>2023-03-14 22:15:35 +0200
commit5cea5fc80b9e1b19d620ec6be1acd5cdbd220971 (patch)
tree23aa2bc463a9b384d982a24d1f5ce8be2ab9ad53 /tests/auto/corelib/io/qlockfile
parent425e635ecd8d588a87da66a1ef89fbf9ef469f1e (diff)
QLockFile: tryLock(): use chrono first
I.e. tryLock(chrono::milliseconds) shouldn't call the int overload as that truncates the timeout (milliseconds is typically int64_t). Add a note to the tryLock(millisecons) docs that passing milliseconds::max() will make it wait forever to obtain the lock. Task-number: QTBUG-110059 Change-Id: Ib48d9b1b117ce816348625331543d6ba8a788973 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/io/qlockfile')
-rw-r--r--tests/auto/corelib/io/qlockfile/tst_qlockfile.cpp18
1 files changed, 10 insertions, 8 deletions
diff --git a/tests/auto/corelib/io/qlockfile/tst_qlockfile.cpp b/tests/auto/corelib/io/qlockfile/tst_qlockfile.cpp
index aa40353c99..1f26dc785f 100644
--- a/tests/auto/corelib/io/qlockfile/tst_qlockfile.cpp
+++ b/tests/auto/corelib/io/qlockfile/tst_qlockfile.cpp
@@ -26,6 +26,8 @@
#include <private/qlockfile_p.h> // for getLockFileHandle()
+using namespace std::chrono_literals;
+
class tst_QLockFile : public QObject
{
Q_OBJECT
@@ -96,7 +98,7 @@ void tst_QLockFile::lockUnlock()
QVERIFY(lockFile.getLockInfo(&pid, &hostname, &appname));
QCOMPARE(pid, QCoreApplication::applicationPid());
QCOMPARE(appname, qAppName());
- QVERIFY(!lockFile.tryLock(200));
+ QVERIFY(!lockFile.tryLock(200ms));
QCOMPARE(int(lockFile.error()), int(QLockFile::LockFailedError));
// Unlock deletes the lock file
@@ -341,8 +343,8 @@ void tst_QLockFile::staleLongLockFromBusyProcess()
QTRY_VERIFY(QFile::exists(fileName));
QLockFile secondLock(fileName);
- secondLock.setStaleLockTime(0);
- QVERIFY(!secondLock.tryLock(100)); // never stale
+ secondLock.setStaleLockTime(0ms);
+ QVERIFY(!secondLock.tryLock(100ms)); // never stale
QCOMPARE(int(secondLock.error()), int(QLockFile::LockFailedError));
qint64 pid;
QTRY_VERIFY(secondLock.getLockInfo(&pid, NULL, NULL));
@@ -510,8 +512,8 @@ void tst_QLockFile::corruptedLockFile()
}
QLockFile secondLock(fileName);
- secondLock.setStaleLockTime(100);
- QVERIFY(secondLock.tryLock(10000));
+ secondLock.setStaleLockTime(100ms);
+ QVERIFY(secondLock.tryLock(10s));
QCOMPARE(int(secondLock.error()), int(QLockFile::NoError));
}
@@ -564,7 +566,7 @@ void tst_QLockFile::hostnameChange()
{
// we should fail to lock
QLockFile lock2(lockFile);
- QVERIFY(!lock2.tryLock(1000));
+ QVERIFY(!lock2.tryLock(1s));
}
}
@@ -591,7 +593,7 @@ void tst_QLockFile::differentMachines()
{
// we should fail to lock
QLockFile lock2(lockFile);
- QVERIFY(!lock2.tryLock(1000));
+ QVERIFY(!lock2.tryLock(1s));
}
}
@@ -620,7 +622,7 @@ void tst_QLockFile::reboot()
f.close();
// we should succeed in locking
- QVERIFY(lock1.tryLock(0));
+ QVERIFY(lock1.tryLock(0ms));
}
bool tst_QLockFile::overwritePidInLockFile(const QString &filePath, qint64 pid)