diff --git a/tests/testsslsocketlinereader.cpp b/tests/testsslsocketlinereader.cpp index 10e5a1aeb..eb3fbc306 100644 --- a/tests/testsslsocketlinereader.cpp +++ b/tests/testsslsocketlinereader.cpp @@ -123,10 +123,18 @@ void TestSslSocketLineReader::testTrustedDevice() m_clientSocket->setPeerVerifyMode(QSslSocket::VerifyPeer); 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(); 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 QVERIFY2(m_clientSocket->isOpen(), "Client socket already closed"); @@ -183,10 +191,18 @@ void TestSslSocketLineReader::testUntrustedDevice() m_clientSocket->setPeerVerifyName(QStringLiteral("Test Server")); 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(); 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(serverSocket->isOpen(), "Server socket already closed");