[patch] KLockFile -- try harder

Oswald Buddenhagen ossi at kde.org
Thu Jan 29 10:05:47 GMT 2009


On Thu, Jan 29, 2009 at 03:40:33AM +0200, Nick Shaforostoff wrote:
> > i think you forgot to add the autotests. :D
>
> Attached. All tests are passing.
>
seems mostly fine.
 
> Index: klockfiletest.cpp
> ===================================================================
> --- klockfiletest.cpp	(revision 918027)
> +++ klockfiletest.cpp	(working copy)
> @@ -93,4 +93,33 @@
> +void
> +Test_KLockFile::testStaleNoBlockFlag()
> +{
> +#ifdef Q_WS_WIN
> +    qDebug("unix stale lock support not implemented yet");
>
QSKIP(), but see ralf's comment.
on that matter, klockfile could use the much more efficient and less
hacky posix locking when it does not detect NFS < v3. that's a somewhat
larger task, though.

> +#else
> +    char hostname[256];
> +    ::gethostname(hostname, sizeof(hostname));
> +    
> +    QFile f(QFile::encodeName(lockName));
> +    f.open(QIODevice::WriteOnly);
> +    QTextStream stream(&f);
> +    stream << QString::number(::getpid()+42) << endl
>
i think simply using 111222 or so for the pid would be more reliable.
that would not help under real-world conditions, but at least the test
won't fail on a busy system. :)

> +    << QLatin1String("qttest") << endl
> +    << hostname << endl;
>
please line up these.

> +    stream.flush();
> +    f.close();
> +
> +    lockFile = new KLockFile(QLatin1String(lockName));
> +    QVERIFY(!lockFile->isLocked());
> +    QCOMPARE(lockFile->lock(KLockFile::NoBlockFlag), KLockFile::LockStale);
> +    QCOMPARE(lockFile->lock(KLockFile::NoBlockFlag|KLockFile::ForceFlag), KLockFile::LockOK);
> +
> +    QVERIFY(lockFile->isLocked());
> +#endif
> +}





More information about the kde-core-devel mailing list