summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@nokia.com>2010-04-14 15:30:14 (GMT)
committerThiago Macieira <thiago.macieira@nokia.com>2010-04-16 11:31:35 (GMT)
commit3f0a30213925932acbff0db697378ca2135f0998 (patch)
tree1e98cf18bb1aecd43a28eba8f0c4ff41cbfa428b /tests
parent46faa5d37e2dbe30f7683ae9e4f70b1c8723da96 (diff)
downloadQt-3f0a30213925932acbff0db697378ca2135f0998.zip
Qt-3f0a30213925932acbff0db697378ca2135f0998.tar.gz
Qt-3f0a30213925932acbff0db697378ca2135f0998.tar.bz2
Add an event-loop based test that does parallel fetches
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qtcpsocket_stresstest/tst_qtcpsocket_stresstest.cpp39
1 files changed, 36 insertions, 3 deletions
diff --git a/tests/auto/qtcpsocket_stresstest/tst_qtcpsocket_stresstest.cpp b/tests/auto/qtcpsocket_stresstest/tst_qtcpsocket_stresstest.cpp
index 6a57d20..b706b7f 100644
--- a/tests/auto/qtcpsocket_stresstest/tst_qtcpsocket_stresstest.cpp
+++ b/tests/auto/qtcpsocket_stresstest/tst_qtcpsocket_stresstest.cpp
@@ -64,6 +64,7 @@ private Q_SLOTS:
void blockingPipelined();
void blockingMultipleRequests();
void connectDisconnect();
+ void parallelConnectDisconnect();
};
tst_QTcpSocket_stresstest::tst_QTcpSocket_stresstest()
@@ -211,9 +212,6 @@ void tst_QTcpSocket_stresstest::connectDisconnect()
qDebug("Attempt %d", i);
QTcpSocket socket;
socket.connectToHost(hostname, port);
- QTestEventLoop::instance().connect(&socket, SIGNAL(connected()), SLOT(exitLoop()));
- QTestEventLoop::instance().enterLoop(30);
- QVERIFY2(!QTestEventLoop::instance().timeout(), "Timeout");
socket.write("GET /qtest/bigfile HTTP/1.1\r\n"
"Connection: close\r\n"
@@ -227,6 +225,41 @@ void tst_QTcpSocket_stresstest::connectDisconnect()
}
}
+void tst_QTcpSocket_stresstest::parallelConnectDisconnect()
+{
+ QFETCH_GLOBAL(QString, hostname);
+ QFETCH_GLOBAL(int, port);
+
+ for (int i = 0; i < AttemptCount/4; ++i) {
+ qDebug("Attempt %d", i);
+ const int parallelAttempts = 6;
+ QTcpSocket socket[parallelAttempts];
+ for (int j = 0; j < parallelAttempts; ++j) {
+ socket[j].connectToHost(hostname, port);
+
+ socket[j].write("GET /qtest/bigfile HTTP/1.1\r\n"
+ "Connection: close\r\n"
+ "User-Agent: tst_QTcpSocket_stresstest/1.0\r\n"
+ "Host: " + hostname.toLatin1() + "\r\n"
+ "\r\n");
+
+ QTestEventLoop::instance().connect(&socket[j], SIGNAL(disconnected()), SLOT(exitLoop()));
+ }
+
+ QElapsedTimer timeout;
+ timeout.start();
+ while (!timeout.hasExpired(10000)) {
+ QTestEventLoop::instance().enterLoop(10);
+ int done = 0;
+ for (int j = 0; j < parallelAttempts; ++j)
+ done += socket[j].state() == QAbstractSocket::UnconnectedState ? 1 : 0;
+ if (done == parallelAttempts)
+ break;
+ }
+ QVERIFY2(!timeout.hasExpired(10000), "Timeout");
+ }
+}
+
QTEST_MAIN(tst_QTcpSocket_stresstest);
#include "tst_qtcpsocket_stresstest.moc"