diff options
author | Thiago Macieira <thiago.macieira@nokia.com> | 2010-04-16 09:22:09 (GMT) |
---|---|---|
committer | Thiago Macieira <thiago.macieira@nokia.com> | 2010-04-16 11:33:34 (GMT) |
commit | ef48cfd6cc1b2989b33ae3709634a732a1c81668 (patch) | |
tree | d0d64c0e8560494d1e787f51b25e50d3db8735fe /tests | |
parent | e2ef78accc7d3c0ccbc222b68bf14c0fd38254e1 (diff) | |
download | Qt-ef48cfd6cc1b2989b33ae3709634a732a1c81668.zip Qt-ef48cfd6cc1b2989b33ae3709634a732a1c81668.tar.gz Qt-ef48cfd6cc1b2989b33ae3709634a732a1c81668.tar.bz2 |
Add tests for remote hosts
Diffstat (limited to 'tests')
-rw-r--r-- | tests/manual/network_stresstest/tst_network_stresstest.cpp | 264 | ||||
-rw-r--r-- | tests/manual/network_stresstest/url-list.txt | 64 | ||||
-rw-r--r-- | tests/manual/network_stresstest/wwwfiles.qrc | 3 |
3 files changed, 322 insertions, 9 deletions
diff --git a/tests/manual/network_stresstest/tst_network_stresstest.cpp b/tests/manual/network_stresstest/tst_network_stresstest.cpp index 9979914..d3b007a 100644 --- a/tests/manual/network_stresstest/tst_network_stresstest.cpp +++ b/tests/manual/network_stresstest/tst_network_stresstest.cpp @@ -86,6 +86,7 @@ public: qint64 byteCounter; QNetworkAccessManager manager; + QVector<QUrl> httpUrls; bool intermediateDebug; private: @@ -108,6 +109,13 @@ private Q_SLOTS: void parallelConnectDisconnect(); void namGet_data(); void namGet(); + + void blockingSequentialRemoteHosts(); + void sequentialRemoteHosts(); + void parallelRemoteHosts_data(); + void parallelRemoteHosts(); + void namRemoteGet_data(); + void namRemoteGet(); }; tst_QTcpSocket_stresstest::tst_QTcpSocket_stresstest() @@ -121,6 +129,18 @@ tst_QTcpSocket_stresstest::tst_QTcpSocket_stresstest() #elif defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN) ::signal(SIGALRM, SIG_IGN); #endif + + QFile urlList(":/url-list.txt"); + if (urlList.open(QIODevice::ReadOnly)) { + while (!urlList.atEnd()) { + QByteArray line = urlList.readLine().trimmed(); + QUrl url = QUrl::fromEncoded(line); + if (url.scheme() == "http") + httpUrls << url; + } + } + + httpUrls << httpUrls; } void tst_QTcpSocket_stresstest::initTestCase_data() @@ -272,7 +292,7 @@ void tst_QTcpSocket_stresstest::nativeBlockingConnectDisconnect() totalBytes += byteCounter; if (intermediateDebug) { - double rate = (byteCounter / timeout.elapsed()); + double rate = (byteCounter * 1.0 / timeout.elapsed()); qDebug() << i << byteCounter << "bytes in" << timeout.elapsed() << "ms:" << (rate / 1024.0 / 1024 * 1000) << "MB/s"; } @@ -390,7 +410,7 @@ void tst_QTcpSocket_stresstest::nativeNonBlockingConnectDisconnect() totalBytes += byteCounter; if (intermediateDebug) { - double rate = (byteCounter / timeout.elapsed()); + double rate = (byteCounter * 1.0 / timeout.elapsed()); qDebug() << i << byteCounter << "bytes in" << timeout.elapsed() << "ms:" << (rate / 1024.0 / 1024 * 1000) << "MB/s"; } @@ -431,7 +451,7 @@ void tst_QTcpSocket_stresstest::blockingConnectDisconnect() totalBytes += byteCounter; if (intermediateDebug) { - double rate = (byteCounter / timeout.elapsed()); + double rate = (byteCounter * 1.0 / timeout.elapsed()); qDebug() << i << byteCounter << "bytes in" << timeout.elapsed() << "ms:" << (rate / 1024.0 / 1024 * 1000) << "MB/s"; } @@ -476,7 +496,7 @@ void tst_QTcpSocket_stresstest::blockingPipelined() totalBytes += byteCounter; if (intermediateDebug) { - double rate = (byteCounter / timeout.elapsed()); + double rate = (byteCounter * 1.0 / timeout.elapsed()); qDebug() << i << byteCounter << "bytes in" << timeout.elapsed() << "ms:" << (rate / 1024.0 / 1024 * 1000) << "MB/s"; } @@ -556,7 +576,7 @@ void tst_QTcpSocket_stresstest::blockingMultipleRequests() totalBytes += byteCounter; if (intermediateDebug) { - double rate = (byteCounter / timeout.elapsed()); + double rate = (byteCounter * 1.0 / timeout.elapsed()); qDebug() << i << byteCounter << "bytes in" << timeout.elapsed() << "ms:" << (rate / 1024.0 / 1024 * 1000) << "MB/s"; } @@ -598,7 +618,7 @@ void tst_QTcpSocket_stresstest::connectDisconnect() totalBytes += byteCounter; if (intermediateDebug) { - double rate = (byteCounter / timeout.elapsed()); + double rate = (byteCounter * 1.0 / timeout.elapsed()); qDebug() << i << byteCounter << "bytes in" << timeout.elapsed() << "ms:" << (rate / 1024.0 / 1024 * 1000) << "MB/s"; } @@ -669,7 +689,7 @@ void tst_QTcpSocket_stresstest::parallelConnectDisconnect() totalBytes += byteCounter; if (intermediateDebug) { - double rate = (byteCounter / timeout.elapsed()); + double rate = (byteCounter * 1.0 / timeout.elapsed()); qDebug() << i << byteCounter << "bytes in" << timeout.elapsed() << "ms:" << (rate / 1024.0 / 1024 * 1000) << "MB/s"; } @@ -758,7 +778,7 @@ void tst_QTcpSocket_stresstest::namGet() QVERIFY2(!timeout.hasExpired(30000), "Timeout"); totalBytes += byteCounter; if (intermediateDebug) { - double rate = (byteCounter / timeout.elapsed()); + double rate = (byteCounter * 1.0 / timeout.elapsed()); qDebug() << i << byteCounter << "bytes in" << timeout.elapsed() << "ms:" << (rate / 1024.0 / 1024 * 1000) << "MB/s"; } @@ -766,6 +786,234 @@ void tst_QTcpSocket_stresstest::namGet() qDebug() << "Average transfer rate was" << (totalBytes / 1024.0 / 1024 * 1000 / outerTimer.elapsed()) << "MB/s"; } +void tst_QTcpSocket_stresstest::blockingSequentialRemoteHosts() +{ + QFETCH_GLOBAL(bool, isLocalhost); + if (isLocalhost) + return; + + qint64 totalBytes = 0; + QElapsedTimer outerTimer; + outerTimer.start(); + + for (int i = 0; i < httpUrls.size(); ++i) { + const QUrl &url = httpUrls.at(i); + QElapsedTimer timeout; + byteCounter = 0; + timeout.start(); + + QTcpSocket socket; + socket.connectToHost(url.host(), url.port(80)); + QVERIFY2(socket.waitForConnected(10000), "Timeout connecting"); + + socket.write("GET " + url.toEncoded(QUrl::RemoveScheme | QUrl::RemoveAuthority | QUrl::RemoveFragment) + " HTTP/1.0\r\n" + "Connection: close\r\n" + "User-Agent: tst_QTcpSocket_stresstest/1.0\r\n" + "Host: " + url.encodedHost() + "\r\n" + "\r\n"); + while (socket.bytesToWrite()) + QVERIFY2(socket.waitForBytesWritten(10000), "Timeout writing"); + + while (socket.state() == QAbstractSocket::ConnectedState && !timeout.hasExpired(10000)) { + socket.waitForReadyRead(10000); + byteCounter += socket.readAll().size(); // discard + } + QVERIFY2(!timeout.hasExpired(10000), "Timeout reading"); + + totalBytes += byteCounter; + if (intermediateDebug) { + double rate = (byteCounter * 1.0 / timeout.elapsed()); + qDebug() << i << url << byteCounter << "bytes in" << timeout.elapsed() << "ms:" + << (rate / 1024.0 * 1000) << "kB/s"; + } + } + qDebug() << "Average transfer rate was" << (totalBytes / 1024.0 * 1000 / outerTimer.elapsed()) << "kB/s"; +} + +void tst_QTcpSocket_stresstest::sequentialRemoteHosts() +{ + QFETCH_GLOBAL(bool, isLocalhost); + if (isLocalhost) + return; + + qint64 totalBytes = 0; + QElapsedTimer outerTimer; + outerTimer.start(); + + for (int i = 0; i < httpUrls.size(); ++i) { + const QUrl &url = httpUrls.at(i); + QElapsedTimer timeout; + byteCounter = 0; + timeout.start(); + + QTcpSocket socket; + socket.connectToHost(url.host(), url.port(80)); + + socket.write("GET " + url.toEncoded(QUrl::RemoveScheme | QUrl::RemoveAuthority | QUrl::RemoveFragment) + " HTTP/1.0\r\n" + "Connection: close\r\n" + "User-Agent: tst_QTcpSocket_stresstest/1.0\r\n" + "Host: " + url.encodedHost() + "\r\n" + "\r\n"); + connect(&socket, SIGNAL(readyRead()), SLOT(slotReadAll())); + + QTestEventLoop::instance().connect(&socket, SIGNAL(disconnected()), SLOT(exitLoop())); + QTestEventLoop::instance().enterLoop(30); + QVERIFY2(!QTestEventLoop::instance().timeout(), "Timeout"); + + totalBytes += byteCounter; + if (intermediateDebug) { + double rate = (byteCounter * 1.0 / timeout.elapsed()); + qDebug() << i << url << byteCounter << "bytes in" << timeout.elapsed() << "ms:" + << (rate / 1024.0 * 1000) << "kB/s"; + } + } + qDebug() << "Average transfer rate was" << (totalBytes / 1024.0 * 1000 / outerTimer.elapsed()) << "kB/s"; +} + +void tst_QTcpSocket_stresstest::parallelRemoteHosts_data() +{ + QTest::addColumn<int>("parallelAttempts"); + QTest::newRow("1") << 1; + QTest::newRow("2") << 2; + QTest::newRow("4") << 4; + QTest::newRow("5") << 5; + QTest::newRow("6") << 6; + QTest::newRow("8") << 8; + QTest::newRow("10") << 10; + QTest::newRow("25") << 25; + QTest::newRow("500") << 500; +} + +void tst_QTcpSocket_stresstest::parallelRemoteHosts() +{ + QFETCH_GLOBAL(bool, isLocalhost); + if (isLocalhost) + return; + + QFETCH(int, parallelAttempts); + + qint64 totalBytes = 0; + QElapsedTimer outerTimer; + outerTimer.start(); + + QVector<QUrl>::ConstIterator it = httpUrls.constBegin(); + while (it != httpUrls.constEnd()) { + QElapsedTimer timeout; + byteCounter = 0; + timeout.start(); + + QVector<QSharedPointer<QTcpSocket> > sockets; + sockets.reserve(parallelAttempts); + for (int j = 0; j < parallelAttempts && it != httpUrls.constEnd(); ++j, ++it) { + const QUrl &url = *it; + QTcpSocket *socket = new QTcpSocket; + socket->connectToHost(url.host(), url.port(80)); + + socket->write("GET " + url.toEncoded(QUrl::RemoveScheme | QUrl::RemoveAuthority | QUrl::RemoveFragment) + " HTTP/1.0\r\n" + "Connection: close\r\n" + "User-Agent: tst_QTcpSocket_stresstest/1.0\r\n" + "Host: " + url.encodedHost() + "\r\n" + "\r\n"); + connect(socket, SIGNAL(readyRead()), SLOT(slotReadAll())); + QTestEventLoop::instance().connect(socket, SIGNAL(disconnected()), SLOT(exitLoop())); + + sockets.append(QSharedPointer<QTcpSocket>(socket)); + } + + while (!timeout.hasExpired(30000)) { + QTestEventLoop::instance().enterLoop(10); + int done = 0; + for (int j = 0; j < sockets.size(); ++j) + done += sockets[j]->state() == QAbstractSocket::UnconnectedState ? 1 : 0; + if (done == sockets.size()) + break; + } + + totalBytes += byteCounter; + if (intermediateDebug) { + double rate = (byteCounter * 1.0 / timeout.elapsed()); + qDebug() << byteCounter << "bytes in" << timeout.elapsed() << "ms:" + << (rate / 1024.0 * 1000) << "kB/s"; + } + } + qDebug() << "Average transfer rate was" << (totalBytes / 1024.0 * 1000 / outerTimer.elapsed()) << "kB/s"; +} + +void tst_QTcpSocket_stresstest::namRemoteGet_data() +{ + QTest::addColumn<int>("parallelAttempts"); + QTest::newRow("1") << 1; + QTest::newRow("2") << 2; + QTest::newRow("4") << 4; + QTest::newRow("5") << 5; + QTest::newRow("6") << 6; + QTest::newRow("8") << 8; + QTest::newRow("10") << 10; + QTest::newRow("25") << 25; + QTest::newRow("500") << 500; +} + +void tst_QTcpSocket_stresstest::namRemoteGet() +{ + QFETCH_GLOBAL(bool, isLocalhost); + if (isLocalhost) + return; + + QFETCH(int, parallelAttempts); + bool pipelineAllowed = false;// QFETCH(bool, pipelineAllowed); + + if (parallelAttempts > 100) { + QFETCH_GLOBAL(bool, isLocalhost); + if (!isLocalhost) + QSKIP("Localhost-only test", SkipSingle); + } + + qint64 totalBytes = 0; + QElapsedTimer outerTimer; + outerTimer.start(); + + QVector<QUrl>::ConstIterator it = httpUrls.constBegin(); + while (it != httpUrls.constEnd()) { + QElapsedTimer timeout; + byteCounter = 0; + timeout.start(); + + QNetworkRequest req; + req.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, pipelineAllowed); + + QVector<QSharedPointer<QNetworkReply> > replies; + replies.reserve(parallelAttempts); + for (int j = 0; j < parallelAttempts && it != httpUrls.constEnd(); ++j) { + req.setUrl(*it++); + QNetworkReply *r = manager.get(req); + + connect(r, SIGNAL(readyRead()), SLOT(slotReadAll())); + QTestEventLoop::instance().connect(r, SIGNAL(finished()), SLOT(exitLoop())); + + replies.append(QSharedPointer<QNetworkReply>(r)); + } + + while (!timeout.hasExpired(30000)) { + QTestEventLoop::instance().enterLoop(10); + int done = 0; + for (int j = 0; j < replies.size(); ++j) + done += replies[j]->isFinished() ? 1 : 0; + if (done == replies.size()) + break; + } + replies.clear(); + + QVERIFY2(!timeout.hasExpired(30000), "Timeout"); + totalBytes += byteCounter; + if (intermediateDebug) { + double rate = (byteCounter * 1.0 / timeout.elapsed()); + qDebug() << byteCounter << "bytes in" << timeout.elapsed() << "ms:" + << (rate / 1024.0 * 1000) << "kB/s"; + } + } + qDebug() << "Average transfer rate was" << (totalBytes / 1024.0 * 1000 / outerTimer.elapsed()) << "kB/s"; +} + QTEST_MAIN(tst_QTcpSocket_stresstest); #include "tst_network_stresstest.moc" diff --git a/tests/manual/network_stresstest/url-list.txt b/tests/manual/network_stresstest/url-list.txt new file mode 100644 index 0000000..3d6d7a9 --- /dev/null +++ b/tests/manual/network_stresstest/url-list.txt @@ -0,0 +1,64 @@ +http://www.digicert.com/CACerts/DigiCertAssuredIDRootCA.crt +http://www.digicert.com/CACerts/DigiCertGlobalRootCA.crt +http://www.digicert.com/CACerts/DigiCertHighAssuranceEVRootCA.crt +http://www.quovadis.bm/public/qvrca2.crt +http://www.quovadis.bm/public/qvrca3.crt +https://secure.globalsign.net/cacert/root-r2.crt +http://secure.globalsign.net/cacert/Root-R1.crt +http://www.certplus.com/PC/certplus_class2.pem +https://www.startssl.com/certs/ca.crt +http://www.turktrust.com.tr/sertifikalar/TURKTRUST_Elektronik_Sertifika_Hizmet_Saglayicisi.crt +http://www.turktrust.com.tr/sertifikalar/kok_s2.crt +http://crt.comodoca.com/COMODOCertificationAuthority.crt +http://crt.comodoca.com/COMODOECCCertificationAuthority.crt +https://bugzilla.mozilla.org/attachment.cgi?id=368998 +https://bugzilla.mozilla.org/attachment.cgi?id=335538 +https://bugzilla.mozilla.org/attachment.cgi?id=304810 +https://www.securetrust.com/legal/STCA.txt +https://www.securetrust.com/legal/SGCA.txt +http://www.securetrust.com/legal/XGCA.txt +http://www.diginotar.nl/files/Rootcertificaten/DigiNotar%20root%20CA2007.crt +https://bugzilla.mozilla.org/attachment.cgi?id=294057 +https://bugzilla.mozilla.org/attachment.cgi?id=368997 +https://bugzilla.mozilla.org/attachment.cgi?id=306731 +https://certs.starfieldtech.com/repository/valicert_class2_root.crt +https://certs.godaddy.com/repository/gd-class2-root.crt +https://certs.starfieldtech.com/repository/sf-class2-root.crt +ftp://ftp.networksolutions.com/certs/netsolevroot.crt +https://bugzilla.mozilla.org/attachment.cgi?id=335551 +https://bugzilla.mozilla.org/attachment.cgi?id=369000 +https://bugzilla.mozilla.org/attachment.cgi?id=306736 +https://bugzilla.mozilla.org/attachment.cgi?id=267983 +https://swisssign.net/cgi-bin/authority/download?ca=50AFCC078715476F38C5B465D1DE95AAE9DF9CCC&into=browser +https://swisssign.net/cgi-bin/authority/download?ca=5B257B96A465517EB839F3C078665EE83AE7F0EE&into=browser +https://swisssign.net/cgi-bin/authority/download?ca=17A0CDC1E441B63A5B3BCB459DBD1CC298FA8658&into=browser +http://apps.identrust.com/roots/DSTROOTCAX3.cer +https://bugzilla.mozilla.org/attachment.cgi?id=277051 +http://www.ssi.gouv.fr/IMG/crt/igca-rsa.crt +http://www.e-szigno.hu/RootCA.crt +http://www.s-trust.de/service_support/zertifikatsmanagement/verzeichnisdienste/download_wurzelzertifikate/ordner_crt_dateien/authentication.crt +http://public.wisekey.com/crt/owgrgaca.crt +http://www.trustcenter.de/media/class_2_ii.der +http://www.trustcenter.de/media/class_3_ii.der +http://www.trustcenter.de/media/Universal_CA-I.der +http://www.certigna.fr/ca/ACcertigna.crt +https://repository.secomtrust.net/EV-Root1/EVRoot1ca.cer +http://www.certicamara.com/ac_offline_raiz_certicamara.crt +http://fedir.comsign.co.il/cacert/ComsignCA.crt +http://fedir.comsign.co.il/cacert/ComsignSecuredCA.crt +http://crl.pki.wellsfargo.com/wsprca.crt +http://cacert.omniroot.com/ct_root_ss.crt +http://www.kamusm.gov.tr/BilgiDeposu/KOKSHS.v3.crt +https://bugzilla.mozilla.org/attachment.cgi?id=380381 +http://210.71.154.6/download/ROOTeCA.cer +https://bugzilla.mozilla.org/attachment.cgi?id=359654 +http://www.gpki.go.jp/apcaself/APCAroot.der +https://bugzilla.mozilla.org/attachment.cgi?id=405525 +https://bugzilla.mozilla.org/attachment.cgi?id=361508 +https://bugzilla.mozilla.org/attachment.cgi?id=361508 +http://www.hongkongpost.gov.hk/product/download/root/img/smartid_rt.cacert +http://www.sk.ee/files/JUUR-SK.der +https://bugzilla.mozilla.org/attachment.cgi?id=408102 +http://www.disig.eu/ca/cert/ca_disig.der +https://bugzilla.mozilla.org/attachment.cgi?id=365241 +https://www2.jcsinc.co.jp/repository/certs/SSAD-rca.der diff --git a/tests/manual/network_stresstest/wwwfiles.qrc b/tests/manual/network_stresstest/wwwfiles.qrc index b1d4be6..2290861 100644 --- a/tests/manual/network_stresstest/wwwfiles.qrc +++ b/tests/manual/network_stresstest/wwwfiles.qrc @@ -1,5 +1,6 @@ <RCC> <qresource prefix="/"> - <file>qtest</file> + <file>qtest</file> + <file>url-list.txt</file> </qresource> </RCC> |