Skip to content
This repository was archived by the owner on Mar 4, 2023. It is now read-only.

Commit 3615abf

Browse files
committed
completed integrationt test
1 parent 9df69ad commit 3615abf

File tree

3 files changed

+158
-9
lines changed

3 files changed

+158
-9
lines changed

src/datasync/remoteconnector.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ void RemoteConnector::binaryMessageReceived(const QByteArray &message)
464464
else if(Message::isType<DevicesMessage>(name))
465465
onDevices(Message::deserializeMessage<DevicesMessage>(stream));
466466
else if(Message::isType<RemoveAckMessage>(name))
467-
onRemoved(Message::deserializeMessage<RemoveAckMessage>(stream));
467+
onRemoveAck(Message::deserializeMessage<RemoveAckMessage>(stream));
468468
else if(Message::isType<ProofMessage>(name))
469469
onProof(Message::deserializeMessage<ProofMessage>(stream));
470470
else if(Message::isType<AcceptAckMessage>(name))
@@ -1071,7 +1071,7 @@ void RemoteConnector::onDevices(const DevicesMessage &message)
10711071
}
10721072
}
10731073

1074-
void RemoteConnector::onRemoved(const RemoveAckMessage &message)
1074+
void RemoteConnector::onRemoveAck(const RemoveAckMessage &message)
10751075
{
10761076
if(checkIdle(message)) {
10771077
if(_deviceId == message.deviceId) {

src/datasync/remoteconnector_p.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ private Q_SLOTS:
197197
void onChangedInfo(const ChangedInfoMessage &message);
198198
void onLastChanged(const LastChangedMessage &message);
199199
void onDevices(const DevicesMessage &message);
200-
void onRemoved(const RemoveAckMessage &message);
200+
void onRemoveAck(const RemoveAckMessage &message);
201201
void onProof(const ProofMessage &message);
202202
void onAcceptAck(const AcceptAckMessage &message);
203203
void onMacUpdateAck(const MacUpdateAckMessage &message);

tests/auto/datasync/IntegrationTest/tst_integration.cpp

Lines changed: 155 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ private Q_SLOTS:
1717
void testAddAccount();
1818
void testLiveSync();
1919
void testPassiveSync();
20+
void testRemoveAndResetAccount();
21+
void testAddAccountTrusted();
2022

2123
Q_SIGNALS:
2224
void unlock();
@@ -31,6 +33,8 @@ private Q_SLOTS:
3133
AccountManager *acc2;
3234
SyncManager *sync2;
3335
DataTypeStore<TestData> *store2;
36+
37+
QUuid dev2Id;
3438
};
3539

3640
void IntegrationTest::initTestCase()
@@ -192,6 +196,7 @@ void IntegrationTest::testAddAccount()
192196

193197
//export from acc1
194198
acc1->exportAccount(false, [this](QJsonObject exp) {
199+
QVERIFY(!AccountManager::isTrustedImport(exp));
195200
acc2->importAccount(exp, [](bool ok, QString e) {
196201
QVERIFY2(ok, qUtf8Printable(e));
197202
}, true);
@@ -210,8 +215,8 @@ void IntegrationTest::testAddAccount()
210215
QVERIFY(!request.handled());
211216
QCOMPARE(request.device().name(), acc2->deviceName());
212217
QCOMPARE(request.device().fingerprint(), acc2->deviceFingerprint());
213-
auto pId = request.device().deviceId();
214-
QVERIFY(!pId.isNull());
218+
dev2Id = request.device().deviceId();
219+
QVERIFY(!dev2Id.isNull());
215220
request.accept();
216221
QVERIFY(request.handled());
217222

@@ -224,7 +229,7 @@ void IntegrationTest::testAddAccount()
224229
if(grantSpy.isEmpty())
225230
QVERIFY(grantSpy.wait());
226231
QCOMPARE(grantSpy.size(), 1);
227-
QCOMPARE(grantSpy.takeFirst()[0].toUuid(), pId);
232+
QCOMPARE(grantSpy.takeFirst()[0].toUuid(), dev2Id);
228233

229234
//wait for sync
230235
sync1->runOnSynchronized([this](SyncManager::SyncState s) {
@@ -249,7 +254,7 @@ void IntegrationTest::testAddAccount()
249254
QCOMPARE(devices1Spy.size(), 1);
250255
auto devices = devices1Spy.takeFirst()[0].value<QList<DeviceInfo>>();
251256
QCOMPARE(devices.size(), 1);
252-
QCOMPARE(devices[0].deviceId(), pId);
257+
QCOMPARE(devices[0].deviceId(), dev2Id);
253258
QCOMPARE(devices[0].name(), acc2->deviceName());
254259
QCOMPARE(devices[0].fingerprint(), acc2->deviceFingerprint());
255260

@@ -289,8 +294,9 @@ void IntegrationTest::testLiveSync()
289294
QVERIFY(sync1Spy.size() > 0);
290295
QCOMPARE(sync1Spy.takeFirst()[0].toInt(), SyncManager::Uploading);
291296
QVERIFY(unlockSpy.wait());
292-
QCOMPARE(sync1Spy.size(), 1);
293-
QCOMPARE(sync1Spy.takeFirst()[0].toInt(), SyncManager::Synchronized);
297+
QVERIFY(sync1Spy.size() > 0);
298+
QCOMPARE(sync1Spy.last()[0].toInt(), SyncManager::Synchronized);
299+
sync1Spy.clear();
294300

295301
//sync data to 2
296302
sync2->runOnDownloaded([this](SyncManager::SyncState s) {
@@ -304,6 +310,7 @@ void IntegrationTest::testLiveSync()
304310
QVERIFY(unlockSpy.wait());
305311
QVERIFY(sync2Spy.size() > 0);
306312
QCOMPARE(sync2Spy.last()[0].toInt(), SyncManager::Synchronized);
313+
sync2Spy.clear();
307314

308315
//verify data changes
309316
QCOMPARE(dataSpy.size(), 20);
@@ -442,6 +449,7 @@ void IntegrationTest::testPassiveSync()
442449
QVERIFY(unlockSpy.wait());
443450
QVERIFY(sync2Spy.size() > 0);
444451
QCOMPARE(sync2Spy.last()[0].toInt(), SyncManager::Synchronized);
452+
sync2Spy.clear();
445453

446454
//verify data changes on 1
447455
QCOMPARE(data1Spy.size(), 20);
@@ -464,6 +472,147 @@ void IntegrationTest::testPassiveSync()
464472
}
465473
}
466474

475+
void IntegrationTest::testRemoveAndResetAccount()
476+
{
477+
try {
478+
QSignalSpy error1Spy(acc1, &AccountManager::lastErrorChanged);
479+
QSignalSpy error2Spy(acc2, &AccountManager::lastErrorChanged);
480+
QSignalSpy sync1Spy(sync1, &SyncManager::syncStateChanged);
481+
QSignalSpy sync2Spy(sync2, &SyncManager::syncStateChanged);
482+
QSignalSpy devices1Spy(acc1, &AccountManager::accountDevices);
483+
QSignalSpy data1Spy(store1, &DataTypeStoreBase::dataResetted);
484+
485+
//remove 2
486+
acc1->removeDevice(dev2Id);
487+
QVERIFY(sync2Spy.wait());
488+
QCOMPARE(sync2Spy.size(), 1);
489+
QCOMPARE(sync2Spy.takeFirst()[0].toInt(), SyncManager::Disconnected);
490+
491+
//verify devices not there
492+
acc1->listDevices();
493+
QVERIFY(devices1Spy.wait());
494+
QCOMPARE(devices1Spy.size(), 1);
495+
auto devices = devices1Spy.takeFirst()[0].value<QList<DeviceInfo>>();
496+
QVERIFY(devices.isEmpty());
497+
498+
//verify connect fails
499+
sync2->reconnect();
500+
//wait for init
501+
if(sync2Spy.isEmpty())
502+
QVERIFY(sync2Spy.wait());
503+
QVERIFY(sync2Spy.size() > 0);
504+
QCOMPARE(sync2Spy.takeFirst()[0].toInt(), SyncManager::Initializing);
505+
//wait for error
506+
if(sync2Spy.isEmpty())
507+
QVERIFY(sync2Spy.wait());
508+
QVERIFY(sync2Spy.size() > 0);
509+
QCOMPARE(sync2Spy.takeFirst()[0].toInt(), SyncManager::Error);
510+
//on error
511+
sync2->runOnSynchronized([this](SyncManager::SyncState s) {
512+
emit unlock();
513+
QCOMPARE(s, SyncManager::Error);
514+
}, false);
515+
if(error2Spy.isEmpty())
516+
QVERIFY(error2Spy.wait());
517+
QCOMPARE(error2Spy.size(), 1);
518+
error2Spy.clear();
519+
520+
//reset 1 to clear it
521+
acc1->resetAccount(false);
522+
//disconnect
523+
if(sync1Spy.isEmpty())
524+
QVERIFY(sync1Spy.wait());
525+
QVERIFY(sync1Spy.size() > 0);
526+
QCOMPARE(sync1Spy.takeFirst()[0].toInt(), SyncManager::Disconnected);
527+
//reconnect
528+
if(sync1Spy.isEmpty())
529+
QVERIFY(sync1Spy.wait());
530+
QVERIFY(sync1Spy.size() > 0);
531+
QCOMPARE(sync1Spy.takeFirst()[0].toInt(), SyncManager::Initializing);
532+
//uploading
533+
if(sync1Spy.isEmpty())
534+
QVERIFY(sync1Spy.wait());
535+
QVERIFY(sync1Spy.size() > 0);
536+
QCOMPARE(sync1Spy.takeFirst()[0].toInt(), SyncManager::Uploading);
537+
//synced
538+
if(sync1Spy.isEmpty())
539+
QVERIFY(sync1Spy.wait());
540+
QCOMPARE(sync1Spy.size(), 1);
541+
QCOMPARE(sync1Spy.takeFirst()[0].toInt(), SyncManager::Synchronized);
542+
543+
if(data1Spy.isEmpty())
544+
QVERIFY(data1Spy.wait());
545+
546+
QVERIFY(error1Spy.isEmpty());
547+
QVERIFY(error2Spy.isEmpty());
548+
} catch(std::exception &e) {
549+
QFAIL(e.what());
550+
}
551+
}
552+
553+
void IntegrationTest::testAddAccountTrusted()
554+
{
555+
try {
556+
QSignalSpy error1Spy(acc1, &AccountManager::lastErrorChanged);
557+
QSignalSpy error2Spy(acc2, &AccountManager::lastErrorChanged);
558+
QSignalSpy fprintSpy(acc2, &AccountManager::deviceFingerprintChanged);
559+
QSignalSpy requestSpy(acc1, &AccountManager::loginRequested);
560+
QSignalSpy acceptSpy(acc2, &AccountManager::importAccepted);
561+
QSignalSpy grantSpy(acc1, &AccountManager::accountAccessGranted);
562+
QSignalSpy unlockSpy(this, &IntegrationTest::unlock);
563+
564+
//export from acc1
565+
auto password = QStringLiteral("password");
566+
acc1->exportAccountTrusted(false, password, [&](QJsonObject exp) {
567+
QVERIFY(AccountManager::isTrustedImport(exp));
568+
acc2->importAccountTrusted(exp, password, [&](bool ok, QString e) {
569+
QVERIFY2(ok, qUtf8Printable(e));
570+
if(error2Spy.wait())
571+
error2Spy.clear();
572+
}, false);
573+
}, [](QString e) {
574+
QFAIL(qUtf8Printable(e));
575+
});
576+
577+
//wait for acc2 fingerprint update
578+
QVERIFY(fprintSpy.wait());
579+
QCOMPARE(fprintSpy.size(), 1);
580+
581+
//wait for login request to not come...
582+
QVERIFY(!requestSpy.wait());
583+
584+
//wait for accept
585+
if(acceptSpy.isEmpty())
586+
QVERIFY(acceptSpy.wait());
587+
QCOMPARE(acceptSpy.size(), 1);
588+
589+
//wait for grant
590+
if(grantSpy.isEmpty())
591+
QVERIFY(grantSpy.wait());
592+
QCOMPARE(grantSpy.size(), 1);
593+
594+
//wait for sync
595+
sync1->runOnSynchronized([this](SyncManager::SyncState s) {
596+
emit unlock();
597+
QCOMPARE(s, SyncManager::Synchronized);
598+
}, true);
599+
unlockSpy.wait();
600+
sync2->runOnSynchronized([this](SyncManager::SyncState s) {
601+
emit unlock();
602+
QCOMPARE(s, SyncManager::Synchronized);
603+
});
604+
unlockSpy.wait();
605+
606+
QCOMPARE(store1->count(), 0);
607+
QCOMPARE(store2->count(), 0);
608+
609+
QVERIFY(error1Spy.isEmpty());
610+
QVERIFY(error2Spy.isEmpty());
611+
} catch(std::exception &e) {
612+
QFAIL(e.what());
613+
}
614+
}
615+
467616
QTEST_MAIN(IntegrationTest)
468617

469618
#include "tst_integration.moc"

0 commit comments

Comments
 (0)