summaryrefslogtreecommitdiffstats
path: root/tests/auto/network/access
diff options
context:
space:
mode:
authorMårten Nordheim <marten.nordheim@qt.io>2020-08-12 16:48:57 +0200
committerMårten Nordheim <marten.nordheim@qt.io>2020-08-24 17:43:30 +0200
commit5283be1f7321ccdcf31e9be4b3353c825a433295 (patch)
tree906816d26c5c8b32087fe714fb7e6961f8fe19ff /tests/auto/network/access
parent45b56d86bb6bdbc96a04b21587b8c9bc24087113 (diff)
tst_qnetworkreply: Extend httpConnectionCount to test HTTP/2 and TLS
HTTP/2 is only used initially before it transitions to using HTTP/1.1, and in this case the amount of connections established should also reach 6. Change-Id: I300e171e46c846df1730c07469ea85a51cecfb63 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Diffstat (limited to 'tests/auto/network/access')
-rw-r--r--tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp53
1 files changed, 46 insertions, 7 deletions
diff --git a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp
index e4dafb58d0..c8be0902ba 100644
--- a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp
+++ b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp
@@ -377,6 +377,7 @@ private Q_SLOTS:
void authorizationError_data();
void authorizationError();
+ void httpConnectionCount_data();
void httpConnectionCount();
void httpReUsingConnectionSequential_data();
@@ -5029,6 +5030,7 @@ public slots:
{
socket = (QSslSocket*) sender();
emit newEncryptedConnection(socket);
+ addPendingConnection(socket);
}
void readyReadSlot()
{
@@ -6110,16 +6112,48 @@ void tst_QNetworkReply::authorizationError()
QCOMPARE(QString(reply->readAll()), httpBody);
}
+void tst_QNetworkReply::httpConnectionCount_data()
+{
+ QTest::addColumn<bool>("http2Enabled");
+ QTest::addColumn<bool>("encrypted");
+ QTest::addRow("http/1.1") << false << false;
+ QTest::addRow("http/2") << true << false;
+#if QT_CONFIG(ssl)
+ QTest::addRow("https/1.1") << false << true;
+ QTest::addRow("https/2") << true << true;
+#endif
+}
+
void tst_QNetworkReply::httpConnectionCount()
{
- QTcpServer server;
- QVERIFY(server.listen());
+ QScopedPointer<QTcpServer> server;
+ QFETCH(bool, encrypted);
+#if QT_CONFIG(ssl)
+ if (encrypted) {
+ server.reset(new SslServer());
+ } else
+#endif
+ {
+ server.reset(new QTcpServer());
+ }
+
+ QVERIFY(server->listen());
QCoreApplication::instance()->processEvents();
+ QUrl url("http://127.0.0.1:" + QString::number(server->serverPort()) + QLatin1Char('/'));
+ if (encrypted)
+ url.setScheme("https");
+
+ QFETCH(bool, http2Enabled);
for (int i = 0; i < 10; i++) {
- QNetworkRequest request (QUrl("http://127.0.0.1:" + QString::number(server.serverPort()) + QLatin1Char('/') + QString::number(i)));
+ QUrl urlCopy = url;
+ urlCopy.setPath(u'/' + QString::number(i)); // Differentiate the requests a bit
+ QNetworkRequest request(urlCopy);
+ request.setAttribute(QNetworkRequest::Http2AllowedAttribute, http2Enabled);
QNetworkReply* reply = manager.get(request);
- reply->setParent(&server);
+ reply->setParent(server.data());
+ if (encrypted)
+ reply->ignoreSslErrors();
}
int pendingConnectionCount = 0;
@@ -6128,11 +6162,16 @@ void tst_QNetworkReply::httpConnectionCount()
while(pendingConnectionCount <= 20) {
QTestEventLoop::instance().enterLoop(1);
- QTcpSocket *socket = server.nextPendingConnection();
+ QTcpSocket *socket = server->nextPendingConnection();
while (socket != 0) {
+ if (pendingConnectionCount == 0) {
+ // respond to the first connection so we know to transition to HTTP/1.1 when using
+ // HTTP/2
+ socket->write(httpEmpty200Response);
+ }
pendingConnectionCount++;
- socket->setParent(&server);
- socket = server.nextPendingConnection();
+ socket->setParent(server.data());
+ socket = server->nextPendingConnection();
}
// at max. wait 10 sec