Fix tst_QTcpServer::maxPendingConnections flakiness

Task-number: QTBUG-63152
Change-Id: I5ccd07f31d47048d81e85f69e1327f4f7c760257
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
This commit is contained in:
Sami Nurmenniemi 2018-02-02 16:46:03 +02:00 committed by Thiago Macieira
parent 9ac09dcc68
commit c19d532393

View File

@ -420,13 +420,20 @@ void tst_QTcpServer::maxPendingConnections()
QTcpSocket socket2;
QTcpSocket socket3;
QSignalSpy spy(&server, SIGNAL(newConnection()));
QVERIFY(server.listen());
socket1.connectToHost(QHostAddress::LocalHost, server.serverPort());
socket2.connectToHost(QHostAddress::LocalHost, server.serverPort());
socket3.connectToHost(QHostAddress::LocalHost, server.serverPort());
QVERIFY(server.waitForNewConnection(5000));
// We must have two and only two connections. First compare waits until
// two connections have been made. The second compare makes sure no
// more are accepted. Creating connections happens multithreaded so
// qWait must be used for that.
QTRY_COMPARE(spy.count(), 2);
QTest::qWait(100);
QCOMPARE(spy.count(), 2);
QVERIFY(server.hasPendingConnections());
QVERIFY(server.nextPendingConnection());