Merge lp:~renatofilho/sync-monitor/fix-sync-state into lp:sync-monitor

Proposed by Renato Araujo Oliveira Filho
Status: Needs review
Proposed branch: lp:~renatofilho/sync-monitor/fix-sync-state
Merge into: lp:sync-monitor
Prerequisite: lp:~renatofilho/sync-monitor/no-gmock
Diff against target: 188 lines (+43/-6)
6 files modified
src/sync-daemon.cpp (+9/-1)
src/sync-daemon.h (+3/-0)
src/sync-dbus.cpp (+3/-2)
src/sync-queue.cpp (+7/-2)
src/sync-queue.h (+7/-1)
tests/unittest/sync-queue-test.cpp (+14/-0)
To merge this branch: bzr merge lp:~renatofilho/sync-monitor/fix-sync-state
Reviewer Review Type Date Requested Status
system-apps-ci-bot continuous-integration Approve
Ubuntu Phablet Team Pending
Review via email: mp+321565@code.launchpad.net

Commit message

Fixed sync state update.

Make sure that the state get update when the sync queue change for any reason.

To post a comment you must log in.
Revision history for this message
system-apps-ci-bot (system-apps-ci-bot) wrote :

PASSED: Continuous integration, rev:101
https://jenkins.canonical.com/system-apps/job/lp-sync-monitor-ci/6/
Executed test runs:
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build/2376
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-0-fetch/2376
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=xenial+overlay/2189
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=xenial+overlay/2189/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=zesty/2189
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=zesty/2189/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=xenial+overlay/2189
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=xenial+overlay/2189/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=zesty/2189
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=zesty/2189/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=xenial+overlay/2189
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=xenial+overlay/2189/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=zesty/2189
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=zesty/2189/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/system-apps/job/lp-sync-monitor-ci/6/rebuild

review: Approve (continuous-integration)
102. By Renato Araujo Oliveira Filho

Connect "done" signal to check for state change.

Revision history for this message
system-apps-ci-bot (system-apps-ci-bot) wrote :

PASSED: Continuous integration, rev:102
https://jenkins.canonical.com/system-apps/job/lp-sync-monitor-ci/9/
Executed test runs:
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build/2425
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-0-fetch/2425
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=xenial+overlay/2236
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=xenial+overlay/2236/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=zesty/2236
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=zesty/2236/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=xenial+overlay/2236
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=xenial+overlay/2236/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=zesty/2236
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=zesty/2236/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=xenial+overlay/2236
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=xenial+overlay/2236/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=zesty/2236
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=zesty/2236/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/system-apps/job/lp-sync-monitor-ci/9/rebuild

review: Approve (continuous-integration)

Unmerged revisions

102. By Renato Araujo Oliveira Filho

Connect "done" signal to check for state change.

101. By Renato Araujo Oliveira Filho

Fixed sync state update.

Make sure that the state get update when the sync queue change for any reason.

100. By Renato Araujo Oliveira Filho

Use gmock from system intead of keep a copy internally.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/sync-daemon.cpp'
2--- src/sync-daemon.cpp 2016-09-01 12:20:42 +0000
3+++ src/sync-daemon.cpp 2017-04-05 12:48:52 +0000
4@@ -58,7 +58,7 @@
5 m_syncQueue = new SyncQueue();
6 m_offlineQueue = new SyncQueue();
7 m_networkStatus = new SyncNetwork(this);
8- connect(m_networkStatus, SIGNAL(stateChanged(SyncNetwork::NetworkState)), SLOT(onOnlineStatusChanged(SyncNetwork::NetworkState)));
9+
10
11 m_powerd = new PowerdProxy(this);
12 connect(this, SIGNAL(syncAboutToStart()), m_powerd, SLOT(lock()));
13@@ -67,7 +67,10 @@
14 m_timeout = new QTimer(this);
15 m_timeout->setInterval(DAEMON_SYNC_TIMEOUT);
16 m_timeout->setSingleShot(true);
17+
18+ connect(m_networkStatus, SIGNAL(stateChanged(SyncNetwork::NetworkState)), SLOT(onOnlineStatusChanged(SyncNetwork::NetworkState)));
19 connect(m_timeout, SIGNAL(timeout()), SLOT(continueSync()));
20+ connect(m_syncQueue, SIGNAL(countChanged(int)), SIGNAL(queueCountChanged(int)));
21 }
22
23 SyncDaemon::~SyncDaemon()
24@@ -466,6 +469,11 @@
25 m_settings.sync();
26 }
27
28+int SyncDaemon::queueCount() const
29+{
30+ return m_syncQueue->count();
31+}
32+
33 SyncAccount *SyncDaemon::accountById(quint32 accountId)
34 {
35 return m_accounts.value(accountId);
36
37=== modified file 'src/sync-daemon.h'
38--- src/sync-daemon.h 2016-06-23 16:41:46 +0000
39+++ src/sync-daemon.h 2017-04-05 12:48:52 +0000
40@@ -40,6 +40,7 @@
41 {
42 Q_OBJECT
43 Q_PROPERTY(bool syncOnMobileConnection READ syncOnMobileConnection WRITE setSyncOnMobileConnection)
44+ Q_PROPERTY(int queueCount READ queueCount NOTIFY queueCountChanged)
45 public:
46 SyncDaemon();
47 ~SyncDaemon();
48@@ -52,6 +53,7 @@
49 QString lastSuccessfulSyncDate(quint32 accountId, const QString &calendarId);
50 bool syncOnMobileConnection() const;
51 void setSyncOnMobileConnection(bool flag);
52+ int queueCount() const;
53
54 SyncAccount *accountById(quint32 accountId);
55
56@@ -63,6 +65,7 @@
57 void done();
58 void accountsChanged();
59 void isOnlineChanged(bool isOnline);
60+ void queueCountChanged(int size);
61
62 public Q_SLOTS:
63 void quit();
64
65=== modified file 'src/sync-dbus.cpp'
66--- src/sync-dbus.cpp 2016-07-29 22:06:20 +0000
67+++ src/sync-dbus.cpp 2017-04-05 12:48:52 +0000
68@@ -29,10 +29,11 @@
69 connect(m_parent, SIGNAL(syncStarted(SyncAccount*,QString)), SLOT(onSyncStarted(SyncAccount*,QString)));
70 connect(m_parent, SIGNAL(syncFinished(SyncAccount*,QString)), SLOT(onSyncFinished(SyncAccount*,QString)));
71 connect(m_parent, SIGNAL(syncError(SyncAccount*,QString,QString)), SLOT(onSyncError(SyncAccount*,QString,QString)));
72+ connect(m_parent, SIGNAL(accountsChanged()), SIGNAL(enabledServicesChanged()));
73+ connect(m_parent, SIGNAL(isOnlineChanged(bool)), SIGNAL(enabledServicesChanged()));
74 connect(m_parent, SIGNAL(syncAboutToStart()), SLOT(updateState()));
75 connect(m_parent, SIGNAL(done()), SLOT(updateState()));
76- connect(m_parent, SIGNAL(accountsChanged()), SIGNAL(enabledServicesChanged()));
77- connect(m_parent, SIGNAL(isOnlineChanged(bool)), SIGNAL(enabledServicesChanged()));
78+ connect(m_parent, SIGNAL(queueCountChanged(int)), SLOT(updateState()));
79 updateState();
80 }
81
82
83=== modified file 'src/sync-queue.cpp'
84--- src/sync-queue.cpp 2016-06-21 13:05:24 +0000
85+++ src/sync-queue.cpp 2017-04-05 12:48:52 +0000
86@@ -33,7 +33,8 @@
87
88 void SyncQueue::clear()
89 {
90- m_jobs.clear();;
91+ m_jobs.clear();
92+ Q_EMIT countChanged(count());
93 }
94
95 const QList<SyncJob> SyncQueue::jobs() const
96@@ -82,6 +83,7 @@
97 if (!contains(job)) {
98 m_jobs << job;
99 }
100+ Q_EMIT countChanged(count());
101 }
102
103 bool SyncQueue::contains(const SyncJob &otherJob) const
104@@ -108,7 +110,9 @@
105 if (m_jobs.isEmpty()) {
106 return SyncJob();
107 }
108- return m_jobs.takeFirst();
109+ SyncJob j = m_jobs.takeFirst();
110+ Q_EMIT countChanged(count());
111+ return j;
112 }
113
114 void SyncQueue::remove(const SyncJob &job)
115@@ -135,6 +139,7 @@
116 }
117
118 m_jobs = newList;
119+ Q_EMIT countChanged(count());
120 }
121
122 SyncJob::SyncJob()
123
124=== modified file 'src/sync-queue.h'
125--- src/sync-queue.h 2016-06-21 13:05:24 +0000
126+++ src/sync-queue.h 2017-04-05 12:48:52 +0000
127@@ -22,6 +22,7 @@
128 #include <QtCore/QString>
129 #include <QtCore/QStringList>
130 #include <QtCore/QMap>
131+#include <QtCore/QObject>
132
133 class SyncAccount;
134
135@@ -54,8 +55,10 @@
136 static bool compareSources(const QStringList &listA, const QStringList &listB);
137 };
138
139-class SyncQueue
140+class SyncQueue: public QObject
141 {
142+ Q_OBJECT
143+ Q_PROPERTY(int count READ count NOTIFY countChanged)
144 public:
145 SyncJob popNext();
146
147@@ -77,6 +80,9 @@
148 void clear();
149 const QList<SyncJob> jobs() const;
150
151+Q_SIGNALS:
152+ void countChanged(int count);
153+
154 private:
155 QList<SyncJob> m_jobs;
156 };
157
158=== modified file 'tests/unittest/sync-queue-test.cpp'
159--- tests/unittest/sync-queue-test.cpp 2016-06-17 22:57:30 +0000
160+++ tests/unittest/sync-queue-test.cpp 2017-04-05 12:48:52 +0000
161@@ -23,6 +23,7 @@
162
163 #include <QObject>
164 #include <QtTest>
165+#include <QSignalSpy>
166 #include <QDebug>
167
168
169@@ -160,6 +161,19 @@
170 QVERIFY(queue.contains(&account, QStringLiteral("account1Source0")));
171 QVERIFY(queue.contains(&account, QStringLiteral("account1Source1")));
172 }
173+
174+ void testCountChangedSignal()
175+ {
176+ SyncQueue queue;
177+ QSignalSpy countChanged(&queue, SIGNAL(countChanged(int)));
178+
179+ SyncAccountMock account(1);
180+ queue.push(&account, QStringLiteral("account1Source0"), false);
181+ QTRY_COMPARE(countChanged.count(), 1);
182+
183+ queue.clear();
184+ QTRY_COMPARE(countChanged.count(), 2);
185+ }
186 };
187
188 int main(int argc, char *argv[])

Subscribers

People subscribed via source and target branches