From 5cea5fc80b9e1b19d620ec6be1acd5cdbd220971 Mon Sep 17 00:00:00 2001 From: Ahmad Samir Date: Mon, 27 Feb 2023 21:50:23 +0200 Subject: 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 --- tests/auto/corelib/io/qlockfile/tst_qlockfile.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'tests/auto/corelib/io/qlockfile') 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 // 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) -- cgit v1.2.3