[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kdevplatform/parsejob-sequential] language/backgroundparser/tests: Add a new unit test for the back
From: Sven Brauch <svenbrauch () googlemail ! com>
Date: 2012-02-29 22:53:42
Message-ID: 20120229225342.05623A60A9 () git ! kde ! org
[Download RAW message or body]
Git commit 916df849a5e0259d203c54abd28871a687782a8a by Sven Brauch.
Committed on 29/02/2012 at 23:52.
Pushed by brauch into branch 'parsejob-sequential'.
Add a new unit test for the backgroundparser stuff
This test proves that several low-priority jobs which ignore sequential processing
can run alongside a high-priority one which requires it. This might for example
be relevant to verify that the background parsing won't stall when an active
document is being edited.
M +36 -9 language/backgroundparser/tests/test_backgroundparser.cpp
M +5 -2 language/backgroundparser/tests/test_backgroundparser.h
M +4 -0 language/backgroundparser/tests/testparsejob.cpp
M +4 -0 language/backgroundparser/tests/testparsejob.h
http://commits.kde.org/kdevplatform/916df849a5e0259d203c54abd28871a687782a8a
diff --git a/language/backgroundparser/tests/test_backgroundparser.cpp \
b/language/backgroundparser/tests/test_backgroundparser.cpp index 4cfffc7..be3bd3a \
100644
--- a/language/backgroundparser/tests/test_backgroundparser.cpp
+++ b/language/backgroundparser/tests/test_backgroundparser.cpp
@@ -35,12 +35,15 @@
#include <language/duchain/duchain.h>
#include "testlanguagesupport.h"
+#include "testparsejob.h"
#include <language/backgroundparser/backgroundparser.h>
#include <interfaces/ilanguagecontroller.h>
#include <interfaces/iplugincontroller.h>
QTEST_KDEMAIN(TestBackgroundparser, NoGUI)
+int TestParseJob::duration_ms;
+
using namespace KDevelop;
JobPlan::JobPlan()
@@ -56,7 +59,14 @@ void JobPlan::addJob(const JobPrototype& job)
void JobPlan::clear()
{
m_jobs.clear();
- m_processedJobs.clear();
+ m_finishedJobs.clear();
+ m_startedJobs.clear();
+}
+
+void JobPlan::jobStarted(const IndexedString& url)
+{
+ m_startedJobs.append(url.toUrl());
+ kDebug() << "job was started: " << url.toUrl();
}
bool JobPlan::runJobs(int timeoutMS)
@@ -66,16 +76,19 @@ bool JobPlan::runJobs(int timeoutMS)
ICore::self()->languageController()->backgroundParser()->addDocument(
job.m_url, TopDUContext::Empty, job.m_priority, this, job.m_flags
);
+ // TODO: where to connect the signal?
}
+
+ ICore::self()->languageController()->backgroundParser()->parseDocuments();
QElapsedTimer t;
t.start();
- while ( !t.hasExpired(timeoutMS) && m_jobs.size() != m_processedJobs.size() ) {
+ while ( !t.hasExpired(timeoutMS) && m_jobs.size() != m_finishedJobs.size() ) {
QTest::qWait(50);
}
- return m_processedJobs.size() == m_jobs.size();
+ return m_finishedJobs.size() == m_jobs.size();
}
JobPrototype JobPlan::jobForUrl(const KUrl& url)
@@ -105,13 +118,13 @@ void JobPlan::updateReady(const IndexedString& url, const \
ReferencedTopDUContext
if (otherJob.m_flags & ParseJob::RespectsSequentialProcessing &&
otherJob.m_priority < job.m_priority)
{
- QVERIFY(m_processedJobs.contains(otherJob.m_url));
+ QVERIFY(m_finishedJobs.contains(otherJob.m_url));
}
}
}
- QVERIFY(!m_processedJobs.contains(job.m_url));
- m_processedJobs << job.m_url;
+ QVERIFY(!m_finishedJobs.contains(job.m_url));
+ m_finishedJobs << job.m_url;
}
void TestBackgroundparser::initTestCase()
@@ -140,13 +153,27 @@ void TestBackgroundparser::init()
m_jobPlan.clear();
}
-void TestBackgroundparser::testParseOrdering()
+void TestBackgroundparser::testParseOrdering_lockup()
+{
+ m_jobPlan.clear();
+ TestParseJob::duration_ms = 200;
+ for ( int i = 3; i > 0; i-- ) {
+ // add 3 jobs which do not care about sequential processing, at 4 threads it \
should take no more than 1s to process them + \
m_jobPlan.addJob(JobPrototype(KUrl("test" + QString::number(i) + ".txt"), i, \
ParseJob::IgnoresSequentialProcessing)); + }
+ // add one job which requires sequential processing with high priority
+ m_jobPlan.addJob(JobPrototype(KUrl("test_hp.txt"), -200, \
ParseJob::FullSequentialProcessing)); + // verify that the low-priority \
nonsequential jobs are run simultaneously with the other one. + \
QVERIFY(m_jobPlan.runJobs(700)); +}
+
+void TestBackgroundparser::testParseOrdering_simple()
{
+ m_jobPlan.clear();
for ( int i = 20; i > 0; i-- ) {
// the job with priority i should be at place i in the finished list
// (lower priority value -> should be parsed first)
- ParseJob::SequentialProcessingFlags flags = \
ParseJob::RequiresSequentialProcessing
- | \
ParseJob::RespectsSequentialProcessing; + ParseJob::SequentialProcessingFlags \
flags = ParseJob::FullSequentialProcessing;
m_jobPlan.addJob(JobPrototype(KUrl("test" + QString::number(i) + ".txt"),
i, flags));
}
diff --git a/language/backgroundparser/tests/test_backgroundparser.h \
b/language/backgroundparser/tests/test_backgroundparser.h index 0063c84..f7e1084 \
100644
--- a/language/backgroundparser/tests/test_backgroundparser.h
+++ b/language/backgroundparser/tests/test_backgroundparser.h
@@ -71,10 +71,12 @@ public:
private slots:
void updateReady(const KDevelop::IndexedString& url, const \
KDevelop::ReferencedTopDUContext& context); + void jobStarted(const \
KDevelop::IndexedString& url);
private:
QVector<JobPrototype> m_jobs;
- QVector<KUrl> m_processedJobs;
+ QVector<KUrl> m_finishedJobs;
+ QVector<KUrl> m_startedJobs;
};
class TestBackgroundparser : public QObject
@@ -86,7 +88,8 @@ private slots:
void cleanupTestCase();
void init();
- void testParseOrdering();
+ void testParseOrdering_simple();
+ void testParseOrdering_lockup();
private:
JobPlan m_jobPlan;
diff --git a/language/backgroundparser/tests/testparsejob.cpp \
b/language/backgroundparser/tests/testparsejob.cpp index 81df917..b59796d 100644
--- a/language/backgroundparser/tests/testparsejob.cpp
+++ b/language/backgroundparser/tests/testparsejob.cpp
@@ -20,6 +20,7 @@
*/
#include "testparsejob.h"
+#include <QTest>
TestParseJob::TestParseJob(const KUrl& url): ParseJob(url)
{
@@ -29,4 +30,7 @@ TestParseJob::TestParseJob(const KUrl& url): ParseJob(url)
void TestParseJob::run()
{
kDebug() << "Running parse job for" << document().toUrl();
+ emit(started(document().toUrl()));
+ kDebug() << "waiting" << duration_ms << "ms";
+ QTest::qWait(duration_ms);
}
diff --git a/language/backgroundparser/tests/testparsejob.h \
b/language/backgroundparser/tests/testparsejob.h index bbcb484..ff7a34f 100644
--- a/language/backgroundparser/tests/testparsejob.h
+++ b/language/backgroundparser/tests/testparsejob.h
@@ -28,9 +28,13 @@ using namespace KDevelop;
class TestParseJob : public KDevelop::ParseJob
{
+Q_OBJECT
public:
TestParseJob(const KUrl& url);
virtual void run();
+ static int duration_ms;
+signals:
+ void started(const KUrl& url);
};
#endif
\ No newline at end of file
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic