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:
parent
d6537b7aa5
commit
f144507829
@ -1,6 +1,6 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
**
|
**
|
||||||
** Copyright (C) 2016 The Qt Company Ltd.
|
** Copyright (C) 2020 The Qt Company Ltd.
|
||||||
** Contact: https://www.qt.io/licensing/
|
** Contact: https://www.qt.io/licensing/
|
||||||
**
|
**
|
||||||
** This file is part of the test suite of the Qt Toolkit.
|
** This file is part of the test suite of the Qt Toolkit.
|
||||||
@ -42,6 +42,7 @@
|
|||||||
|
|
||||||
#include "minihttpserver.h"
|
#include "minihttpserver.h"
|
||||||
#include "../../auto/network-settings.h"
|
#include "../../auto/network-settings.h"
|
||||||
|
#include "private/qurl_p.h"
|
||||||
|
|
||||||
#include <qplatformdefs.h>
|
#include <qplatformdefs.h>
|
||||||
#ifdef Q_OS_UNIX
|
#ifdef Q_OS_UNIX
|
||||||
@ -118,7 +119,8 @@ void tst_NetworkStressTest::initTestCase_data()
|
|||||||
QTest::addColumn<int>("port");
|
QTest::addColumn<int>("port");
|
||||||
|
|
||||||
QTest::newRow("localhost") << true << "localhost" << server.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()
|
void tst_NetworkStressTest::initTestCase()
|
||||||
@ -260,8 +262,9 @@ void tst_NetworkStressTest::nativeBlockingConnectDisconnect()
|
|||||||
QFAIL("Timeout");
|
QFAIL("Timeout");
|
||||||
} else if (ret == 0) {
|
} else if (ret == 0) {
|
||||||
break; // EOF
|
break; // EOF
|
||||||
|
} else {
|
||||||
|
byteCounter += ret;
|
||||||
}
|
}
|
||||||
byteCounter += ret;
|
|
||||||
}
|
}
|
||||||
::close(fd);
|
::close(fd);
|
||||||
|
|
||||||
@ -379,7 +382,8 @@ void tst_NetworkStressTest::nativeNonBlockingConnectDisconnect()
|
|||||||
} else if (ret == 0) {
|
} else if (ret == 0) {
|
||||||
break; // EOF
|
break; // EOF
|
||||||
}
|
}
|
||||||
byteCounter += ret;
|
if (ret != -1)
|
||||||
|
byteCounter += ret;
|
||||||
}
|
}
|
||||||
::close(fd);
|
::close(fd);
|
||||||
|
|
||||||
@ -543,8 +547,10 @@ void tst_NetworkStressTest::blockingMultipleRequests()
|
|||||||
while (socket.state() == QAbstractSocket::ConnectedState && !timeout.hasExpired(10000) && bytesExpected > bytesRead) {
|
while (socket.state() == QAbstractSocket::ConnectedState && !timeout.hasExpired(10000) && bytesExpected > bytesRead) {
|
||||||
socket.waitForReadyRead();
|
socket.waitForReadyRead();
|
||||||
int blocklen = socket.read(bytesExpected - bytesRead).length(); // discard
|
int blocklen = socket.read(bytesExpected - bytesRead).length(); // discard
|
||||||
bytesRead += blocklen;
|
if (blocklen >= 0) {
|
||||||
byteCounter += blocklen;
|
bytesRead += blocklen;
|
||||||
|
byteCounter += blocklen;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
QVERIFY2(!timeout.hasExpired(10000), "Timeout");
|
QVERIFY2(!timeout.hasExpired(10000), "Timeout");
|
||||||
QCOMPARE(bytesRead, bytesExpected);
|
QCOMPARE(bytesRead, bytesExpected);
|
||||||
@ -712,6 +718,7 @@ void tst_NetworkStressTest::namGet()
|
|||||||
QSKIP("Localhost-only test");
|
QSKIP("Localhost-only test");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const int halfMinute = 30000;
|
||||||
qint64 totalBytes = 0;
|
qint64 totalBytes = 0;
|
||||||
QElapsedTimer outerTimer;
|
QElapsedTimer outerTimer;
|
||||||
outerTimer.start();
|
outerTimer.start();
|
||||||
@ -722,10 +729,10 @@ void tst_NetworkStressTest::namGet()
|
|||||||
timeout.start();
|
timeout.start();
|
||||||
|
|
||||||
QUrl url;
|
QUrl url;
|
||||||
url.setScheme("http");
|
url.setScheme(QStringLiteral("http"));
|
||||||
url.setHost(hostname);
|
url.setHost(hostname);
|
||||||
url.setPort(port);
|
url.setPort(port);
|
||||||
url.setEncodedPath("/qtest/bigfile");
|
url.setPath(QStringLiteral("/qtest/bigfile"));
|
||||||
QNetworkRequest req(url);
|
QNetworkRequest req(url);
|
||||||
req.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, pipelineAllowed);
|
req.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, pipelineAllowed);
|
||||||
|
|
||||||
@ -740,7 +747,7 @@ void tst_NetworkStressTest::namGet()
|
|||||||
replies[j] = QSharedPointer<QNetworkReply>(r);
|
replies[j] = QSharedPointer<QNetworkReply>(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!timeout.hasExpired(30000)) {
|
while (!timeout.hasExpired(halfMinute)) {
|
||||||
QTestEventLoop::instance().enterLoop(10);
|
QTestEventLoop::instance().enterLoop(10);
|
||||||
int done = 0;
|
int done = 0;
|
||||||
for (int j = 0; j < parallelAttempts; ++j)
|
for (int j = 0; j < parallelAttempts; ++j)
|
||||||
@ -750,7 +757,7 @@ void tst_NetworkStressTest::namGet()
|
|||||||
}
|
}
|
||||||
replies.clear();
|
replies.clear();
|
||||||
|
|
||||||
QVERIFY2(!timeout.hasExpired(30000), "Timeout");
|
QVERIFY2(!timeout.hasExpired(halfMinute), "Timeout");
|
||||||
totalBytes += byteCounter;
|
totalBytes += byteCounter;
|
||||||
if (intermediateDebug) {
|
if (intermediateDebug) {
|
||||||
double rate = (byteCounter * 1.0 / timeout.elapsed());
|
double rate = (byteCounter * 1.0 / timeout.elapsed());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user