diff options
Diffstat (limited to 'tests/auto/corelib/io/qlockfile/tst_qlockfile.cpp')
-rw-r--r-- | tests/auto/corelib/io/qlockfile/tst_qlockfile.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/auto/corelib/io/qlockfile/tst_qlockfile.cpp b/tests/auto/corelib/io/qlockfile/tst_qlockfile.cpp index bd9e28beb5..de5d641c57 100644 --- a/tests/auto/corelib/io/qlockfile/tst_qlockfile.cpp +++ b/tests/auto/corelib/io/qlockfile/tst_qlockfile.cpp @@ -57,6 +57,7 @@ private slots: void lockUnlock(); void lockOutOtherProcess(); void lockOutOtherThread(); + void raceWithOtherThread(); void waitForLock_data(); void waitForLock(); void staleLockFromCrashedProcess_data(); @@ -165,6 +166,25 @@ void tst_QLockFile::lockOutOtherThread() QCOMPARE(ret2.result(), QLockFile::NoError); } +static QLockFile::LockError lockFromThread(const QString &fileName) +{ + QLockFile lockInThread(fileName); + lockInThread.lock(); + return lockInThread.error(); +} + +// QTBUG-38853, best way to trigger it was to add a QThread::sleep(1) in QLockFilePrivate::getLockInfo() after the first readLine. +// Then (on Windows), the QFile::remove() in unlock() (called by the first thread who got the lock, in the destructor) +// would fail due to the existing reader on the file. Fixed by checking the return value of QFile::remove() in unlock(). +void tst_QLockFile::raceWithOtherThread() +{ + const QString fileName = dir.path() + "/raceWithOtherThread"; + QFuture<QLockFile::LockError> ret = QtConcurrent::run<QLockFile::LockError>(lockFromThread, fileName); + QFuture<QLockFile::LockError> ret2 = QtConcurrent::run<QLockFile::LockError>(lockFromThread, fileName); + QCOMPARE(ret.result(), QLockFile::NoError); + QCOMPARE(ret2.result(), QLockFile::NoError); +} + static bool lockFromThread(const QString &fileName, int sleepMs, QSemaphore *semThreadReady, QSemaphore *semMainThreadDone) { QLockFile lockFile(fileName); |