Skip to content

Commit

Permalink
fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
VitorVieiraZ committed Nov 5, 2024
1 parent 78a5a00 commit b574a27
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
39 changes: 22 additions & 17 deletions app/test/testmerginapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2945,29 +2945,34 @@ void TestMerginApi::testParseVersion()

void TestMerginApi::testDownloadWithNetworkError()
{
// MockNetworkManager *mockManager = new MockNetworkManager( mApi );
// mApi->setNetworkManager( mockManager );
QString projectName = "testDownloadWithNetworkError";
QString projectNamespace = mWorkspaceName;

// QString projectName = "testDownloadWithNetworkError";
// QString projectNamespace = mWorkspaceName;
// createRemoteProject( mApiExtra, projectNamespace, projectName, mTestDataPath + "/" + TEST_PROJECT_NAME + "/" );
// Create a test project on server
createRemoteProject( mApiExtra, projectNamespace, projectName, mTestDataPath + "/" + TEST_PROJECT_NAME + "/" );

// mockManager->setShouldFail( true );
// Create mock network manager
MockNetworkManager *mockManager = new MockNetworkManager( mApi );
mApi->setNetworkManager( mockManager );

// QSignalSpy spy( mApi, &MerginApi::syncProjectFinished );
// QSignalSpy errorSpy( mApi, &MerginApi::networkErrorOccurred );
// Track retry signals
QSignalSpy retrySpy( mApi, &MerginApi::downloadItemRetried );

// mApi->pullProject( projectNamespace, projectName );
// Start download and make network fail after project info
mApi->pullProject( projectNamespace, projectName );

// QVERIFY( spy.wait( TestUtils::LONG_REPLY * 5 ) );
QSignalSpy pullStartedSpy( mApi, &MerginApi::pullFilesStarted );
QVERIFY( pullStartedSpy.wait( TestUtils::SHORT_REPLY ) );
mockManager->setShouldFail( true );

// QCOMPARE( spy.count(), 1 );
// QList<QVariant> arguments = spy.takeFirst();
// QVERIFY( !arguments.at( 1 ).toBool() );
// Wait for sync to finish
QSignalSpy syncFinishedSpy( mApi, &MerginApi::syncProjectFinished );
QVERIFY( syncFinishedSpy.wait( TestUtils::LONG_REPLY ) );

// QCOMPARE( errorSpy.count(), 1 );
// Verify we got retry signals
QVERIFY( retrySpy.count() > 0 );

// mApi->setNetworkManager( new QNetworkAccessManager( mApi ) );

// deleteRemoteProjectNow( mApi, projectNamespace, projectName );
// Cleanup
mApi->setNetworkManager( new QNetworkAccessManager( mApi ) );
deleteRemoteProjectNow( mApi, projectNamespace, projectName );
}
2 changes: 2 additions & 0 deletions core/merginapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,8 @@ void MerginApi::downloadItemReplyFinished( DownloadQueueItem item )
CoreUtils::log( "pull " + projectFullName, QStringLiteral( "Retrying download (attempt %1 of 5)" ).arg( transaction.retryCount ) );

downloadNextItem( projectFullName );

emit downloadItemRetried( projectFullName, transaction.retryCount );
transaction.replyPullItems.remove( r );
r->deleteLater();
}
Expand Down
2 changes: 2 additions & 0 deletions core/merginapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,8 @@ class MerginApi: public QObject
void serverWasUpgraded();
void networkManagerChanged();

void downloadItemRetried( const QString &projectFullName, int retryCount );

private slots:
void listProjectsReplyFinished( QString requestId );
void listProjectsByNameReplyFinished( QString requestId );
Expand Down

0 comments on commit b574a27

Please sign in to comment.