[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kdelibs/frameworks] tier1/threadweaver/autotests: Verify that the Queue clears all references to fi
From:       Mirko Boehm (Endocode) <mirko () endocode ! com>
Date:       2013-10-31 18:50:27
Message-ID: E1VbxK7-0000SU-Vt () scm ! kde ! org
[Download RAW message or body]

Git commit dadfd7a89fa9a2b7be27e8f59a64f1cc72a91aea by Mirko Boehm (Endocod=
e).
Committed on 31/10/2013 at 00:44.
Pushed by mirko into branch 'frameworks'.

Verify that the Queue clears all references to finished jobs.

This test currently fails. The threads hold references to the previous
jobs that because of that will not get deleted.

M  +32   -0    tier1/threadweaver/autotests/JobTests.cpp
M  +1    -0    tier1/threadweaver/autotests/JobTests.h

http://commits.kde.org/kdelibs/dadfd7a89fa9a2b7be27e8f59a64f1cc72a91aea

diff --git a/tier1/threadweaver/autotests/JobTests.cpp b/tier1/threadweaver=
/autotests/JobTests.cpp
index ba91ad1..6dd1667 100644
--- a/tier1/threadweaver/autotests/JobTests.cpp
+++ b/tier1/threadweaver/autotests/JobTests.cpp
@@ -9,6 +9,7 @@
 #include <JobSequence.h>
 #include <Lambda.h>
 #include <ThreadWeaver.h>
+#include <Thread.h>
 #include <DebuggingAids.h>
 #include <JobCollection.h>
 #include <ResourceRestrictionPolicy.h>
@@ -854,5 +855,36 @@ void JobTests::IdDecoratorSingleAllocationTest()
     QCOMPARE(job.sequence, QString::fromLatin1("a"));
 }
 =

+struct InstanceCountedJob : public Job {
+    static QAtomicInt counter;
+
+    void run(ThreadWeaver::JobPointer, ThreadWeaver::Thread* thread) {
+        qDebug() << thread->objectName();
+    }
+
+    InstanceCountedJob() {
+        counter.fetchAndAddRelease(1);
+    }
+
+    ~InstanceCountedJob() {
+        counter.fetchAndAddRelease(0);
+    }
+};
+
+QAtomicInt InstanceCountedJob::counter;
+
+void JobTests::JobsAreDestroyedAfterFinish()
+{
+    using namespace ThreadWeaver;
+
+    WaitForIdleAndFinished w(Weaver::instance());
+    Weaver::instance()->suspend();
+    Weaver::instance()->enqueue(JobPointer(new InstanceCountedJob));
+    QCOMPARE(InstanceCountedJob::counter.loadAcquire(), 1);
+    Weaver::instance()->resume();
+    Weaver::instance()->finish();
+    QCOMPARE(InstanceCountedJob::counter.loadAcquire(), 0);
+}
+
 QTEST_MAIN ( JobTests )
 =

diff --git a/tier1/threadweaver/autotests/JobTests.h b/tier1/threadweaver/a=
utotests/JobTests.h
index c75abd6..863c2db 100644
--- a/tier1/threadweaver/autotests/JobTests.h
+++ b/tier1/threadweaver/autotests/JobTests.h
@@ -49,6 +49,7 @@ private Q_SLOTS:
     void IdDecoratorDecoratesTest();
     void IdDecoratorAutoDeleteTest();
     void IdDecoratorSingleAllocationTest();
+    void JobsAreDestroyedAfterFinish();
 =

 public Q_SLOTS: // slots used during tests that are not test cases
     void jobStarted(ThreadWeaver::JobPointer);

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic