Commit a9be84f5 authored by David Faure's avatar David Faure

jobtest: add test for killing a subjob

Summary:
- it turns out that the whole job gets terminated
- after changing FakeSession to delay reconnect like Session,
the unittest actually makes more sense (no more comment about signal not
received because emitted from the constructor)
- call socketDisconnected like Session ends up doing

The main point was to debug a crash I was having in TransactionSequence
when killing subjobs in rollback(). The take away is that disconnecting
from slotResult is a horrible idea, it means mCurrentSubJob stays
dangling and later lostConnection() crashes. Disconnecting is currently
only done for non-running jobs, but too much code sharing brought me into
that bug :)

Reviewers: dvratil

Reviewed By: dvratil

Subscribers: kde-pim

Tags: #kde_pim

Differential Revision: https://phabricator.kde.org/D19742
parent aad2d379
......@@ -23,6 +23,7 @@
#include "private/protocol_p.h"
#include <QCoreApplication>
#include <QTimer>
class FakeSessionPrivate : public SessionPrivate
{
......@@ -58,9 +59,13 @@ public:
return;
}
Q_EMIT q_ptr->reconnected();
connected = true;
startNext();
// Like Session does: delay the actual disconnect+reconnect
QTimer::singleShot(10, q_ptr, [&]() {
socketDisconnected();
Q_EMIT q_ptr->reconnected();
connected = true;
startNext();
});
}
/* reimp */
......
......@@ -112,7 +112,7 @@ private Q_SLOTS:
QCOMPARE(job1DoneSpy.size(), 1);
QCOMPARE(job2DoneSpy.size(), 1);
QCOMPARE(sessionReconnectSpy.size(), 1); // the first one is missed as it happens directly from the ctor
QCOMPARE(sessionReconnectSpy.size(), 2);
}
void testKillQueuedJob()
......@@ -145,7 +145,7 @@ private Q_SLOTS:
job1->done();
QCOMPARE(job1DoneSpy.size(), 1);
QCOMPARE(job2DoneSpy.size(), 1);
QCOMPARE(sessionReconnectSpy.size(), 0); // the first one is missed as it happens directly from the ctor
QCOMPARE(sessionReconnectSpy.size(), 1);
}
void testKillRunningJob()
......@@ -178,12 +178,62 @@ private Q_SLOTS:
// session needs to reconnect, then execute the next job
QSignalSpy job2AboutToStartSpy(job2, &Job::aboutToStart);
QVERIFY(job2AboutToStartSpy.wait());
QCOMPARE(sessionReconnectSpy.size(), 1);
QCOMPARE(sessionReconnectSpy.size(), 2);
job2->done();
QCOMPARE(job1DoneSpy.size(), 1);
QCOMPARE(job2DoneSpy.size(), 1);
QCOMPARE(sessionReconnectSpy.size(), 1); // the first one is missed as it happens directly from the ctor
QCOMPARE(sessionReconnectSpy.size(), 2);
}
void testKillRunningSubjob()
{
FakeSession session("fakeSession", FakeSession::EndJobsManually);
QSignalSpy sessionQueueSpy(&session, &FakeSession::jobAdded);
QSignalSpy sessionReconnectSpy(&session, &Session::reconnected);
FakeJob *parentJob = new FakeJob(&session);
parentJob->setObjectName(QStringLiteral("parentJob"));
QSignalSpy parentJobDoneSpy(parentJob, &KJob::result);
FakeJob *subjob = new FakeJob(parentJob);
subjob->setObjectName(QStringLiteral("subjob"));
QSignalSpy subjobDoneSpy(subjob, &KJob::result);
FakeJob *subjob2 = new FakeJob(parentJob);
subjob2->setObjectName(QStringLiteral("subjob2"));
QSignalSpy subjob2DoneSpy(subjob2, &KJob::result);
FakeJob *nextJob = new FakeJob(&session);
nextJob->setObjectName(QStringLiteral("nextJob"));
QSignalSpy nextJobDoneSpy(nextJob, &KJob::result);
QCOMPARE(sessionQueueSpy.size(), 2);
QSignalSpy parentJobAboutToStart(parentJob, &Job::aboutToStart);
QVERIFY(parentJobAboutToStart.wait());
QSignalSpy subjobAboutToStart(subjob, &Job::aboutToStart);
QVERIFY(subjobAboutToStart.wait());
// one parent job, one subjob running (another one waiting), now kill the running subjob
QVERIFY(subjob->kill(KJob::EmitResult));
QCOMPARE(subjobDoneSpy.size(), 1);
QCOMPARE(subjob2DoneSpy.size(), 0);
// Note that killing a subjob aborts the whole parent job
// Since the session only knows about the parent
QCOMPARE(parentJobDoneSpy.size(), 1);
// session needs to reconnect, then execute the next job
QSignalSpy nextJobAboutToStartSpy(nextJob, &Job::aboutToStart);
QVERIFY(nextJobAboutToStartSpy.wait());
QCOMPARE(sessionReconnectSpy.size(), 2);
nextJob->done();
QCOMPARE(subjob2DoneSpy.size(), 0);
QCOMPARE(nextJobDoneSpy.size(), 1);
}
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment