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>
This commit is contained in:
Edward Welbourne 2020-07-23 13:47:19 +02:00
parent d6537b7aa5
commit f144507829

View File

@ -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,6 +119,7 @@ void tst_NetworkStressTest::initTestCase_data()
QTest::addColumn<int>("port");
QTest::newRow("localhost") << true << "localhost" << server.port();
if (QtNetworkSettings::verifyTestNetworkSettings()) // emits its own warnings if not
QTest::newRow("remote") << false << QtNetworkSettings::serverName() << 80;
}
@ -260,9 +262,10 @@ void tst_NetworkStressTest::nativeBlockingConnectDisconnect()
QFAIL("Timeout");
} else if (ret == 0) {
break; // EOF
}
} else {
byteCounter += ret;
}
}
::close(fd);
totalBytes += byteCounter;
@ -379,6 +382,7 @@ void tst_NetworkStressTest::nativeNonBlockingConnectDisconnect()
} else if (ret == 0) {
break; // EOF
}
if (ret != -1)
byteCounter += ret;
}
::close(fd);
@ -543,9 +547,11 @@ void tst_NetworkStressTest::blockingMultipleRequests()
while (socket.state() == QAbstractSocket::ConnectedState && !timeout.hasExpired(10000) && bytesExpected > bytesRead) {
socket.waitForReadyRead();
int blocklen = socket.read(bytesExpected - bytesRead).length(); // discard
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());