tst_QTcpServer: Output useful more useful info for addressReusable

To try to figure out why QProcess::waitForReadyRead is returning false
so quickly. Though we know it's going to be "Address in use".

FAIL  : tst_QTcpServer::addressReusable(WithoutProxy) 'process.waitForReadyRead(5000)' returned FALSE. (Failed to listen: The bound address is already in use
Netid State  Recv-Q Send-Q Local Address:Port  Peer Address:PortProcess
tcp   LISTEN 0      50         127.0.0.1:49199      0.0.0.0:*    users:(("crashingServer",pid=40529,fd=4))
)

Pick-to: 6.4 6.2
Change-Id: Ic43a460bfc7c7eb6379405b7a1a064e502b6fef3
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
Thiago Macieira 2022-10-10 12:56:24 -07:00
parent 49e62c51f2
commit 742584b0f2
2 changed files with 16 additions and 2 deletions

View File

@ -7,6 +7,9 @@
#if defined(Q_OS_WIN) && defined(Q_CC_MSVC)
# include <crtdbg.h>
#endif
#ifdef Q_OS_UNIX
# include <unistd.h>
#endif
int main(int argc, char *argv[])
{
@ -18,7 +21,18 @@ int main(int argc, char *argv[])
QTcpServer server;
if (!server.listen(QHostAddress::LocalHost, 49199)) {
qDebug("Failed to listen: %s", server.errorString().toLatin1().constData());
fprintf(stderr, "Failed to listen: %s\n", server.errorString().toLatin1().constData());
if (server.serverError() == QTcpSocket::AddressInUseError) {
// let's see if we can find the process that would be holding this
// still open
#ifdef Q_OS_LINUX
static const char *ss_args[] = {
"ss", "-nap", "sport", "=", ":49199", nullptr
};
dup2(STDERR_FILENO, STDOUT_FILENO);
execvp(ss_args[0], const_cast<char **>(ss_args));
#endif
}
return 1;
}

View File

@ -594,7 +594,7 @@ void tst_QTcpServer::addressReusable()
process.start(processExe);
QVERIFY2(process.waitForStarted(), qPrintable(
QString::fromLatin1("Could not start %1: %2").arg(processExe, process.errorString())));
QVERIFY(process.waitForReadyRead(5000));
QVERIFY2(process.waitForReadyRead(5000), qPrintable(process.readAllStandardError()));
QTcpSocket socket;
socket.connectToHost(QHostAddress::LocalHost, 49199);