From 32afe831084d09acf447f129282e371fa0c892f7 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Fri, 7 Jun 2019 16:45:47 +0200 Subject: [PATCH] SSH: Fix autotest - Consider the case of connection sharing being disabled. - Adapt to slower environments. Change-Id: I088622034c26ea343eb78161b24c43b3286b0512 Reviewed-by: Christian Stenger --- src/libs/ssh/sshconnection.cpp | 2 +- tests/auto/ssh/tst_ssh.cpp | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/libs/ssh/sshconnection.cpp b/src/libs/ssh/sshconnection.cpp index 88509d5b62c..b368ccc8efe 100644 --- a/src/libs/ssh/sshconnection.cpp +++ b/src/libs/ssh/sshconnection.cpp @@ -231,7 +231,7 @@ void SshConnection::disconnectFromHost() case Connecting: case Connected: if (!d->sharingEnabled) { - emitDisconnected(); + QTimer::singleShot(0, this, &SshConnection::emitDisconnected); return; } d->state = Disconnecting; diff --git a/tests/auto/ssh/tst_ssh.cpp b/tests/auto/ssh/tst_ssh.cpp index 5ce94b74623..72260c2c9af 100644 --- a/tests/auto/ssh/tst_ssh.cpp +++ b/tests/auto/ssh/tst_ssh.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -171,8 +172,10 @@ void tst_Ssh::errorHandling() connection.connectToHost(); loop.exec(); QVERIFY(timer.isActive()); - QCOMPARE(connection.state(), SshConnection::Unconnected); - QVERIFY(!connection.errorString().isEmpty()); + const bool expectConnected = !SshSettings::connectionSharingEnabled(); + QCOMPARE(connection.state(), expectConnected ? SshConnection::Connected + : SshConnection::Unconnected); + QCOMPARE(connection.errorString().isEmpty(), expectConnected); QVERIFY(!disconnected); QVERIFY2(dataReceived.isEmpty(), qPrintable(dataReceived)); } @@ -374,7 +377,7 @@ void tst_Ssh::sftp() }; FilesToTransfer filesToUpload; std::srand(QDateTime::currentDateTime().toSecsSinceEpoch()); - for (int i = 0; i < 1000; ++i) { + for (int i = 0; i < 100; ++i) { const QString fileName = "sftptestfile" + QString::number(i + 1); QFile file(dirForFilesToUpload.path() + '/' + fileName); QVERIFY2(file.open(QIODevice::WriteOnly), qPrintable(file.errorString())); @@ -413,7 +416,7 @@ void tst_Ssh::sftp() QTimer timer; QObject::connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit); timer.setSingleShot(true); - timer.setInterval((params.timeout + 5) * 1000); + timer.setInterval(30 * 1000); timer.start(); upload->start(); loop.exec(); @@ -453,7 +456,7 @@ void tst_Ssh::sftp() // Download the uploaded files to a different location const QStringList allUploadedFileNames = QDir(dirForFilesToUpload.path()).entryList(QDir::Files); - QCOMPARE(allUploadedFileNames.size(), 1001); + QCOMPARE(allUploadedFileNames.size(), 101); for (const QString &fileName : allUploadedFileNames) { const QString localFilePath = dirForFilesToUpload.path() + '/' + fileName; const QString remoteFilePath = getRemoteFilePath(fileName); @@ -462,7 +465,7 @@ void tst_Ssh::sftp() QVERIFY(downloadJob != SftpInvalidJob); jobs << downloadJob; } - QCOMPARE(jobs.size(), 1001); + QCOMPARE(jobs.size(), 101); loop.exec(); QVERIFY(!invalidFinishedSignal); QVERIFY2(jobError.isEmpty(), qPrintable(jobError)); @@ -490,6 +493,7 @@ void tst_Ssh::sftp() } // Remove the uploaded files on the remote system + timer.setInterval((params.timeout + 5) * 1000); for (const QString &fileName : allUploadedFileNames) { const QString remoteFilePath = getRemoteFilePath(fileName); const SftpJobId removeJob = sftpChannel->removeFile(remoteFilePath);