Wait for both client and server sockets

Fixes the test
This commit is contained in:
Albert Vaca Cintora 2019-02-12 23:00:42 +01:00
parent 395536b382
commit 4d059af839

View file

@ -123,10 +123,18 @@ void TestSslSocketLineReader::testTrustedDevice()
m_clientSocket->setPeerVerifyMode(QSslSocket::VerifyPeer); m_clientSocket->setPeerVerifyMode(QSslSocket::VerifyPeer);
m_clientSocket->addCaCertificate(serverSocket->localCertificate()); m_clientSocket->addCaCertificate(serverSocket->localCertificate());
connect(m_clientSocket, &QSslSocket::encrypted, &m_loop, &QEventLoop::quit); int connected_sockets = 0;
auto connected_lambda = [&](){
connected_sockets++;
if (connected_sockets >= 2) {
m_loop.quit();
}
};
connect(serverSocket, &QSslSocket::encrypted, connected_lambda);
connect(m_clientSocket, &QSslSocket::encrypted, connected_lambda);
serverSocket->startServerEncryption(); serverSocket->startServerEncryption();
m_clientSocket->startClientEncryption(); m_clientSocket->startClientEncryption();
m_loop.exec(); m_loop.exec(); //Block until QEventLoop::quit gets called by the lambda
// Both client and server socket should be encrypted here and should have remote certificate because VerifyPeer is used // Both client and server socket should be encrypted here and should have remote certificate because VerifyPeer is used
QVERIFY2(m_clientSocket->isOpen(), "Client socket already closed"); QVERIFY2(m_clientSocket->isOpen(), "Client socket already closed");
@ -183,10 +191,18 @@ void TestSslSocketLineReader::testUntrustedDevice()
m_clientSocket->setPeerVerifyName(QStringLiteral("Test Server")); m_clientSocket->setPeerVerifyName(QStringLiteral("Test Server"));
m_clientSocket->setPeerVerifyMode(QSslSocket::QueryPeer); m_clientSocket->setPeerVerifyMode(QSslSocket::QueryPeer);
connect(m_clientSocket, &QSslSocket::encrypted, &m_loop, &QEventLoop::quit); int connected_sockets = 0;
auto connected_lambda = [&](){
connected_sockets++;
if (connected_sockets >= 2) {
m_loop.quit();
}
};
connect(serverSocket, &QSslSocket::encrypted, connected_lambda);
connect(m_clientSocket, &QSslSocket::encrypted, connected_lambda);
serverSocket->startServerEncryption(); serverSocket->startServerEncryption();
m_clientSocket->startClientEncryption(); m_clientSocket->startClientEncryption();
m_loop.exec(); m_loop.exec(); //Block until QEventLoop::quit gets called by the lambda
QVERIFY2(m_clientSocket->isOpen(), "Client socket already closed"); QVERIFY2(m_clientSocket->isOpen(), "Client socket already closed");
QVERIFY2(serverSocket->isOpen(), "Server socket already closed"); QVERIFY2(serverSocket->isOpen(), "Server socket already closed");