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

List:       kde-commits
Subject:    [kdevplatform/parsejob-sequential] language/backgroundparser/tests: Background parser unit tests: ad
From:       Sven Brauch <svenbrauch () googlemail ! com>
Date:       2012-03-02 0:57:30
Message-ID: 20120302005730.76B3DA60BB () git ! kde ! org
[Download RAW message or body]

Git commit 4907da7af04ef6cc35d758560f381855dc82e300 by Sven Brauch.
Committed on 02/03/2012 at 01:47.
Pushed by brauch into branch 'parsejob-sequential'.

Background parser unit tests: add a test which checks in which order jobs are started

This test also proves that my change to BackgroundParser::parseDocumentsInternal,
which added an additional break() in the loop is indeed necessary for it to function
properly (and also that it was broken for years and nobody noticed :))
If you remove it, the test will fail, because jobs are started in a random order
and not at all as suggested by their priority flags.

M  +27   -0    language/backgroundparser/tests/test_backgroundparser.cpp
M  +4    -0    language/backgroundparser/tests/test_backgroundparser.h

http://commits.kde.org/kdevplatform/4907da7af04ef6cc35d758560f381855dc82e300

diff --git a/language/backgroundparser/tests/test_backgroundparser.cpp \
b/language/backgroundparser/tests/test_backgroundparser.cpp index e13b78f..98a3b33 \
                100644
--- a/language/backgroundparser/tests/test_backgroundparser.cpp
+++ b/language/backgroundparser/tests/test_backgroundparser.cpp
@@ -109,6 +109,11 @@ JobPrototype JobPlan::jobForUrl(const KUrl& url)
     return JobPrototype();
 }
 
+const QVector< KUrl >& JobPlan::startedJobs()
+{
+    return m_startedJobs;
+}
+
 void JobPlan::updateReady(const IndexedString& url, const ReferencedTopDUContext& \
context)  {
     kDebug() << "update ready on " << url.toUrl();
@@ -162,6 +167,28 @@ void TestBackgroundparser::init()
     TestLanguageSupport::testInstance = &m_jobPlan;
 }
 
+void TestBackgroundparser::testParseOrdering_noSequentialProcessing()
+{
+    m_jobPlan.clear();
+    for ( int i = 0; i < 20; i++ ) {
+        // create jobs with no sequential processing, and different priorities
+        m_jobPlan.addJob(JobPrototype(KUrl("test_nsp1__" + QString::number(i) + \
".txt"), i, ParseJob::IgnoresSequentialProcessing, i)); +    }
+    for ( int i = 0; i < 8; i++ ) {
+        // create a few more jobs with the same priority
+        m_jobPlan.addJob(JobPrototype(KUrl("test_nsp2__" + QString::number(i) + \
".txt"), 10, ParseJob::IgnoresSequentialProcessing, i)); +    }
+    m_jobPlan.runJobs(1000);
+    
+    // verify they're started in the right order
+    int currentBestPriority = BackgroundParser::BestPriority;
+    foreach ( const KUrl& url, m_jobPlan.startedJobs() ) {
+        const JobPrototype p = m_jobPlan.jobForUrl(url);
+        QVERIFY(p.m_priority >= currentBestPriority);
+        currentBestPriority = p.m_priority;
+    }
+}
+
 void TestBackgroundparser::testParseOrdering_lockup()
 {
     m_jobPlan.clear();
diff --git a/language/backgroundparser/tests/test_backgroundparser.h \
b/language/backgroundparser/tests/test_backgroundparser.h index 3ce1a0d..ffc8461 \
                100644
--- a/language/backgroundparser/tests/test_backgroundparser.h
+++ b/language/backgroundparser/tests/test_backgroundparser.h
@@ -74,6 +74,8 @@ public:
 
     JobPrototype jobForUrl(const KUrl& url);
     void jobCreated(TestParseJob* job);
+    
+    const QVector<KUrl>& startedJobs();
 
 private slots:
     void updateReady(const KDevelop::IndexedString& url, const \
KDevelop::ReferencedTopDUContext& context); @@ -96,6 +98,8 @@ private slots:
 
     void testParseOrdering_simple();
     void testParseOrdering_lockup();
+//     void testParseOrdering_foregroundThread();
+    void testParseOrdering_noSequentialProcessing();
 
 private:
     JobPlan m_jobPlan;


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

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