tests/auto/network: Avoid unconditional qWait()s
Replace with QSignalSpy or QTRY_COMPARE when possible. Task-number: QTBUG-63992 Change-Id: I18dc8837301424855487a12ee62451a5aeb21bf0 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
This commit is contained in:
parent
09d4faa008
commit
c580644fe9
@ -2078,8 +2078,6 @@ void tst_QFtp::doneSignal()
|
||||
if (QTestEventLoop::instance().timeout())
|
||||
QFAIL("Network operation timed out");
|
||||
|
||||
QTest::qWait(200);
|
||||
|
||||
QCOMPARE(spy.count(), 1);
|
||||
QCOMPARE(spy.first().first().toBool(), false);
|
||||
}
|
||||
|
@ -7816,13 +7816,14 @@ void tst_QNetworkReply::closeDuringDownload()
|
||||
QFETCH(QUrl, url);
|
||||
QNetworkRequest request(url);
|
||||
QNetworkReply* reply = manager.get(request);
|
||||
connect(reply, SIGNAL(readyRead()), &QTestEventLoop::instance(), SLOT(exitLoop()));
|
||||
QTestEventLoop::instance().enterLoop(10);
|
||||
QVERIFY(!QTestEventLoop::instance().timeout());
|
||||
connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()));
|
||||
QSignalSpy readyReadSpy(reply, &QNetworkReply::readyRead);
|
||||
QVERIFY(readyReadSpy.wait(10000));
|
||||
QSignalSpy destroySpy(reply, &QObject::destroyed);
|
||||
reply->close();
|
||||
reply->deleteLater();
|
||||
QTest::qWait(1000); //cancelling ftp takes some time, this avoids a warning caused by test's cleanup() destroying the connection cache before the abort is finished
|
||||
// Wait for destruction to avoid a warning caused by test's cleanup()
|
||||
// destroying the connection cache before the abort is finished
|
||||
QVERIFY(destroySpy.wait());
|
||||
}
|
||||
|
||||
void tst_QNetworkReply::ftpAuthentication_data()
|
||||
|
@ -1225,12 +1225,13 @@ public:
|
||||
socket.write("testing\n");
|
||||
exec();
|
||||
}
|
||||
signals:
|
||||
void bytesWrittenReceived();
|
||||
public slots:
|
||||
void bytesWritten(qint64) {
|
||||
void bytesWritten(qint64) {
|
||||
emit bytesWrittenReceived();
|
||||
exit();
|
||||
}
|
||||
|
||||
private:
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
@ -1248,11 +1249,12 @@ void tst_QLocalSocket::bytesWrittenSignal()
|
||||
QLocalServer server;
|
||||
QVERIFY(server.listen("qlocalsocket_readyread"));
|
||||
WriteThread writeThread;
|
||||
QSignalSpy receivedSpy(&writeThread, &WriteThread::bytesWrittenReceived);
|
||||
writeThread.start();
|
||||
bool timedOut = false;
|
||||
QVERIFY(server.waitForNewConnection(3000, &timedOut));
|
||||
QVERIFY(!timedOut);
|
||||
QTest::qWait(2000);
|
||||
QVERIFY(receivedSpy.wait(2000));
|
||||
QVERIFY(writeThread.wait(2000));
|
||||
}
|
||||
|
||||
|
@ -2048,11 +2048,7 @@ void tst_QTcpSocket::connectToLocalHostNoService()
|
||||
// port with no service listening.
|
||||
QTcpSocket *socket = newSocket();
|
||||
socket->connectToHost("localhost", 31415); // no service running here, one suspects
|
||||
|
||||
while(socket->state() == QTcpSocket::HostLookupState || socket->state() == QTcpSocket::ConnectingState) {
|
||||
QTest::qWait(100);
|
||||
}
|
||||
QCOMPARE(socket->state(), QTcpSocket::UnconnectedState);
|
||||
QTRY_COMPARE(socket->state(), QTcpSocket::UnconnectedState);
|
||||
delete socket;
|
||||
}
|
||||
#endif
|
||||
|
@ -2908,10 +2908,7 @@ void tst_QSslSocket::qtbug18498_peek2()
|
||||
QScopedPointer<QSslSocket> server(listener.socket);
|
||||
|
||||
QVERIFY(server->write("HELLO\r\n", 7));
|
||||
QElapsedTimer stopwatch;
|
||||
stopwatch.start();
|
||||
while (client->bytesAvailable() < 7 && stopwatch.elapsed() < 5000)
|
||||
QTest::qWait(100);
|
||||
QTRY_COMPARE(client->bytesAvailable(), 7);
|
||||
char c;
|
||||
QCOMPARE(client->peek(&c,1), 1);
|
||||
QCOMPARE(c, 'H');
|
||||
@ -2930,8 +2927,7 @@ void tst_QSslSocket::qtbug18498_peek2()
|
||||
bigblock.fill('#', QIODEVICE_BUFFERSIZE + 1024);
|
||||
QVERIFY(client->write(QByteArray("head")));
|
||||
QVERIFY(client->write(bigblock));
|
||||
while (server->bytesAvailable() < bigblock.length() + 4 && stopwatch.elapsed() < 5000)
|
||||
QTest::qWait(100);
|
||||
QTRY_COMPARE(server->bytesAvailable(), bigblock.length() + 4);
|
||||
QCOMPARE(server->read(4), QByteArray("head"));
|
||||
QCOMPARE(server->peek(bigblock.length()), bigblock);
|
||||
b.reserve(bigblock.length());
|
||||
@ -2947,10 +2943,7 @@ void tst_QSslSocket::qtbug18498_peek2()
|
||||
QCOMPARE(server->readAll(), bigblock);
|
||||
|
||||
QVERIFY(client->write("STARTTLS\r\n"));
|
||||
stopwatch.start();
|
||||
// ### Qt5 use QTRY_VERIFY
|
||||
while (server->bytesAvailable() < 10 && stopwatch.elapsed() < 5000)
|
||||
QTest::qWait(100);
|
||||
QTRY_COMPARE(server->bytesAvailable(), 10);
|
||||
QCOMPARE(server->peek(&c,1), 1);
|
||||
QCOMPARE(c, 'S');
|
||||
b = server->peek(3);
|
||||
@ -2983,9 +2976,7 @@ void tst_QSslSocket::qtbug18498_peek2()
|
||||
client->startClientEncryption();
|
||||
|
||||
QVERIFY(server->write("hello\r\n", 7));
|
||||
stopwatch.start();
|
||||
while (client->bytesAvailable() < 7 && stopwatch.elapsed() < 5000)
|
||||
QTest::qWait(100);
|
||||
QTRY_COMPARE(client->bytesAvailable(), 7);
|
||||
QVERIFY(server->mode() == QSslSocket::SslServerMode && client->mode() == QSslSocket::SslClientMode);
|
||||
QCOMPARE(client->peek(&c,1), 1);
|
||||
QCOMPARE(c, 'h');
|
||||
@ -2996,9 +2987,7 @@ void tst_QSslSocket::qtbug18498_peek2()
|
||||
QCOMPARE(client->readAll(), QByteArray("ello\r\n"));
|
||||
|
||||
QVERIFY(client->write("goodbye\r\n"));
|
||||
stopwatch.start();
|
||||
while (server->bytesAvailable() < 9 && stopwatch.elapsed() < 5000)
|
||||
QTest::qWait(100);
|
||||
QTRY_COMPARE(server->bytesAvailable(), 9);
|
||||
QCOMPARE(server->peek(&c,1), 1);
|
||||
QCOMPARE(c, 'g');
|
||||
QCOMPARE(server->readAll(), QByteArray("goodbye\r\n"));
|
||||
|
Loading…
Reference in New Issue
Block a user