summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2020-07-23 13:47:19 +0200
committerEdward Welbourne <edward.welbourne@qt.io>2020-07-27 11:25:11 +0200
commitf144507829a39f9327ac1abe99c18e5f79e7ebcf (patch)
tree843b66b4d735f8d829cfb390fc0ec084c952dbde /tests
parentd6537b7aa58693cf19f1a5bfd9d260d8f9f05e5e (diff)
Clean up manual network stress-test
Don't attempt the remote test if we don't have a remote server. Don't add error returns from read to byteCounter. Don't cast from ASCII to QString in URL components. Don't waste time encoding a path for which it's a no-op (especially as I recently deleted the method used to do it). Name the time-out, both for clarity and to give anyone who needs to debug the test only one line to edit so as to increase the time-out enough to make debugging practical. Change-Id: I378aa96c0501f7033ca4abb82734b03b8c807f08 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/manual/network_stresstest/tst_network_stresstest.cpp27
1 files changed, 17 insertions, 10 deletions
diff --git a/tests/manual/network_stresstest/tst_network_stresstest.cpp b/tests/manual/network_stresstest/tst_network_stresstest.cpp
index 46ad56758d..330a52c3e3 100644
--- a/tests/manual/network_stresstest/tst_network_stresstest.cpp
+++ b/tests/manual/network_stresstest/tst_network_stresstest.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2020 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
@@ -42,6 +42,7 @@
#include "minihttpserver.h"
#include "../../auto/network-settings.h"
+#include "private/qurl_p.h"
#include <qplatformdefs.h>
#ifdef Q_OS_UNIX
@@ -118,7 +119,8 @@ void tst_NetworkStressTest::initTestCase_data()
QTest::addColumn<int>("port");
QTest::newRow("localhost") << true << "localhost" << server.port();
- QTest::newRow("remote") << false << QtNetworkSettings::serverName() << 80;
+ if (QtNetworkSettings::verifyTestNetworkSettings()) // emits its own warnings if not
+ QTest::newRow("remote") << false << QtNetworkSettings::serverName() << 80;
}
void tst_NetworkStressTest::initTestCase()
@@ -260,8 +262,9 @@ void tst_NetworkStressTest::nativeBlockingConnectDisconnect()
QFAIL("Timeout");
} else if (ret == 0) {
break; // EOF
+ } else {
+ byteCounter += ret;
}
- byteCounter += ret;
}
::close(fd);
@@ -379,7 +382,8 @@ void tst_NetworkStressTest::nativeNonBlockingConnectDisconnect()
} else if (ret == 0) {
break; // EOF
}
- byteCounter += ret;
+ if (ret != -1)
+ byteCounter += ret;
}
::close(fd);
@@ -543,8 +547,10 @@ void tst_NetworkStressTest::blockingMultipleRequests()
while (socket.state() == QAbstractSocket::ConnectedState && !timeout.hasExpired(10000) && bytesExpected > bytesRead) {
socket.waitForReadyRead();
int blocklen = socket.read(bytesExpected - bytesRead).length(); // discard
- bytesRead += blocklen;
- byteCounter += blocklen;
+ if (blocklen >= 0) {
+ bytesRead += blocklen;
+ byteCounter += blocklen;
+ }
}
QVERIFY2(!timeout.hasExpired(10000), "Timeout");
QCOMPARE(bytesRead, bytesExpected);
@@ -712,6 +718,7 @@ void tst_NetworkStressTest::namGet()
QSKIP("Localhost-only test");
}
+ const int halfMinute = 30000;
qint64 totalBytes = 0;
QElapsedTimer outerTimer;
outerTimer.start();
@@ -722,10 +729,10 @@ void tst_NetworkStressTest::namGet()
timeout.start();
QUrl url;
- url.setScheme("http");
+ url.setScheme(QStringLiteral("http"));
url.setHost(hostname);
url.setPort(port);
- url.setEncodedPath("/qtest/bigfile");
+ url.setPath(QStringLiteral("/qtest/bigfile"));
QNetworkRequest req(url);
req.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, pipelineAllowed);
@@ -740,7 +747,7 @@ void tst_NetworkStressTest::namGet()
replies[j] = QSharedPointer<QNetworkReply>(r);
}
- while (!timeout.hasExpired(30000)) {
+ while (!timeout.hasExpired(halfMinute)) {
QTestEventLoop::instance().enterLoop(10);
int done = 0;
for (int j = 0; j < parallelAttempts; ++j)
@@ -750,7 +757,7 @@ void tst_NetworkStressTest::namGet()
}
replies.clear();
- QVERIFY2(!timeout.hasExpired(30000), "Timeout");
+ QVERIFY2(!timeout.hasExpired(halfMinute), "Timeout");
totalBytes += byteCounter;
if (intermediateDebug) {
double rate = (byteCounter * 1.0 / timeout.elapsed());