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 pro= cessing can run alongside a high-priority one which requires it. This might for exa= mple 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/la= nguage/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 = #include "testlanguagesupport.h" +#include "testparsejob.h" #include #include #include = 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()->addDocume= nt( job.m_url, TopDUContext::Empty, job.m_priority, this, job.m_fl= ags ); + // TODO: where to connect the signal? } + = + ICore::self()->languageController()->backgroundParser()->parseDocument= s(); = QElapsedTimer t; t.start(); = - while ( !t.hasExpired(timeoutMS) && m_jobs.size() !=3D m_processedJobs= .size() ) { + while ( !t.hasExpired(timeoutMS) && m_jobs.size() !=3D m_finishedJobs.= size() ) { QTest::qWait(50); } = - return m_processedJobs.size() =3D=3D m_jobs.size(); + return m_finishedJobs.size() =3D=3D m_jobs.size(); } = JobPrototype JobPlan::jobForUrl(const KUrl& url) @@ -105,13 +118,13 @@ void JobPlan::updateReady(const IndexedString& url, c= onst 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 =3D 200; + for ( int i =3D 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::Ful= lSequentialProcessing)); + // verify that the low-priority nonsequential jobs are run simultaneou= sly with the other one. + QVERIFY(m_jobPlan.runJobs(700)); +} + +void TestBackgroundparser::testParseOrdering_simple() { + m_jobPlan.clear(); for ( int i =3D 20; i > 0; i-- ) { // the job with priority i should be at place i in the finished li= st // (lower priority value -> should be parsed first) - ParseJob::SequentialProcessingFlags flags =3D ParseJob::RequiresSe= quentialProcessing - | ParseJob::RespectsSe= quentialProcessing; + ParseJob::SequentialProcessingFlags flags =3D ParseJob::FullSequen= tialProcessing; m_jobPlan.addJob(JobPrototype(KUrl("test" + QString::number(i) + "= .txt"), i, flags)); } diff --git a/language/backgroundparser/tests/test_backgroundparser.h b/lang= uage/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::R= eferencedTopDUContext& context); + void jobStarted(const KDevelop::IndexedString& url); = private: QVector m_jobs; - QVector m_processedJobs; + QVector m_finishedJobs; + QVector 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/ba= ckgroundparser/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 = 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/back= groundparser/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