summaryrefslogtreecommitdiffstats
path: root/tests/auto/network
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2022-03-11 14:41:22 +0100
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2022-03-11 20:32:08 +0100
commit8ccf1080fcb131940939369271e6828b178b8e9e (patch)
tree007ed885eae1952760a14746c0ea22d228b394cb /tests/auto/network
parentd5b3238def66419e1a79c79748251230d4c947cd (diff)
tst_QLocalSocket: Clean up leftover local sockets before listening
If a test crashes it might leave local sockets, causing test failures on subsequent runs due to the socket already being "in use". Pick-to: 6.3 Change-Id: Ie1107c414f4819026907071c7b8281b2e27b8541 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'tests/auto/network')
-rw-r--r--tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp52
1 files changed, 32 insertions, 20 deletions
diff --git a/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp b/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp
index a46c02c56c..b018348be0 100644
--- a/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp
+++ b/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp
@@ -162,14 +162,13 @@ tst_QLocalSocket::tst_QLocalSocket()
qRegisterMetaType<QFile::Permissions>("QFile::Permissions");
}
-class LocalServer : public QLocalServer
+class CrashSafeLocalServer : public QLocalServer
{
Q_OBJECT
public:
- LocalServer() : QLocalServer()
+ CrashSafeLocalServer() : QLocalServer()
{
- connect(this, SIGNAL(newConnection()), this, SLOT(slotNewConnection()));
}
bool listen(const QString &name)
@@ -178,6 +177,19 @@ public:
return QLocalServer::listen(name);
}
+ bool listen(qintptr socketDescriptor) { return QLocalServer::listen(socketDescriptor); }
+};
+
+class LocalServer : public CrashSafeLocalServer
+{
+ Q_OBJECT
+
+public:
+ LocalServer() : CrashSafeLocalServer()
+ {
+ connect(this, SIGNAL(newConnection()), this, SLOT(slotNewConnection()));
+ }
+
QList<int> hits;
protected:
@@ -946,7 +958,7 @@ static QVariant readCommand(QIODevice *ioDevice, int *readCommandCounter, bool r
void tst_QLocalSocket::simpleCommandProtocol1()
{
- QLocalServer server;
+ CrashSafeLocalServer server;
server.listen(QStringLiteral("simpleProtocol"));
QLocalSocket localSocketWrite;
@@ -972,7 +984,7 @@ void tst_QLocalSocket::simpleCommandProtocol1()
void tst_QLocalSocket::simpleCommandProtocol2()
{
- QLocalServer server;
+ CrashSafeLocalServer server;
server.listen(QStringLiteral("simpleProtocol"));
QLocalSocket localSocketWrite;
@@ -1029,7 +1041,7 @@ void tst_QLocalSocket::simpleCommandProtocol2()
// QLocalSocket/Server can take a name or path, check that it works as expected
void tst_QLocalSocket::fullPath()
{
- QLocalServer server;
+ CrashSafeLocalServer server;
QString name = "qlocalsocket_pathtest";
#if defined(QT_LOCALSOCKET_TCP)
QString path = "QLocalServer";
@@ -1392,7 +1404,9 @@ void tst_QLocalSocket::delayedDisconnect()
void tst_QLocalSocket::removeServer()
{
// this is a hostile takeover, but recovering from a crash results in the same
+ // Note: Explicitly not a CrashSafeLocalServer
QLocalServer server, server2;
+
QVERIFY(QLocalServer::removeServer("cleanuptest"));
QVERIFY2(server.listen("cleanuptest"), qUtf8Printable(server.errorString()));
#ifndef Q_OS_WIN
@@ -1406,7 +1420,7 @@ void tst_QLocalSocket::removeServer()
void tst_QLocalSocket::recycleServer()
{
- QLocalServer server;
+ CrashSafeLocalServer server;
QLocalSocket client;
QVERIFY2(server.listen("recycletest1"), qUtf8Printable(server.errorString()));
@@ -1431,7 +1445,7 @@ void tst_QLocalSocket::recycleClientSocket()
const QByteArrayList lines = QByteArrayList() << "Have you heard of that new band"
<< "\"1023 Megabytes\"?"
<< "They haven't made it to a gig yet.";
- QLocalServer server;
+ CrashSafeLocalServer server;
const QString serverName = QStringLiteral("recycleClientSocket");
QVERIFY2(server.listen(serverName), qUtf8Printable(server.errorString()));
QLocalSocket client;
@@ -1456,7 +1470,7 @@ void tst_QLocalSocket::recycleClientSocket()
void tst_QLocalSocket::multiConnect()
{
- QLocalServer server;
+ CrashSafeLocalServer server;
QLocalSocket client1;
QLocalSocket client2;
QLocalSocket client3;
@@ -1481,7 +1495,7 @@ void tst_QLocalSocket::multiConnect()
void tst_QLocalSocket::writeOnlySocket()
{
- QLocalServer server;
+ CrashSafeLocalServer server;
QVERIFY2(server.listen("writeOnlySocket"), qUtf8Printable(server.errorString()));
QLocalSocket client;
@@ -1512,7 +1526,7 @@ void tst_QLocalSocket::writeToClientAndDisconnect_data()
void tst_QLocalSocket::writeToClientAndDisconnect()
{
QFETCH(int, chunks);
- QLocalServer server;
+ CrashSafeLocalServer server;
QLocalSocket client;
QSignalSpy readChannelFinishedSpy(&client, SIGNAL(readChannelFinished()));
@@ -1540,7 +1554,7 @@ void tst_QLocalSocket::writeToClientAndDisconnect()
void tst_QLocalSocket::writeToDisconnected()
{
- QLocalServer server;
+ CrashSafeLocalServer server;
QVERIFY2(server.listen("writeToDisconnected"), qUtf8Printable(server.errorString()));
QLocalSocket client;
@@ -1611,7 +1625,7 @@ public slots:
*/
void tst_QLocalSocket::bytesWrittenSignal()
{
- QLocalServer server;
+ CrashSafeLocalServer server;
QVERIFY2(server.listen("qlocalsocket_readyread"), qUtf8Printable(server.errorString()));
WriteThread writeThread;
QSignalSpy receivedSpy(&writeThread, &WriteThread::bytesWrittenReceived);
@@ -1632,7 +1646,7 @@ void tst_QLocalSocket::socketClosedSlot()
void tst_QLocalSocket::syncDisconnectNotify()
{
- QLocalServer server;
+ CrashSafeLocalServer server;
QVERIFY2(server.listen("syncDisconnectNotify"), qUtf8Printable(server.errorString()));
QLocalSocket client;
connect(&client, &QLocalSocket::disconnected,
@@ -1651,7 +1665,7 @@ void tst_QLocalSocket::syncDisconnectNotify()
void tst_QLocalSocket::asyncDisconnectNotify()
{
- QLocalServer server;
+ CrashSafeLocalServer server;
QVERIFY2(server.listen("asyncDisconnectNotify"), qUtf8Printable(server.errorString()));
QLocalSocket client;
QSignalSpy disconnectedSpy(&client, SIGNAL(disconnected()));
@@ -1703,9 +1717,7 @@ void tst_QLocalSocket::verifySocketOptions()
QFETCH(QLocalServer::SocketOption, opts);
QFETCH(QFile::Permissions, perms);
-
- QLocalServer::removeServer(service);
- QLocalServer server;
+ CrashSafeLocalServer server;
server.setSocketOptions(opts);
QVERIFY2(server.listen(service), qUtf8Printable(server.errorString()));
@@ -1762,7 +1774,7 @@ void tst_QLocalSocket::verifyListenWithDescriptor()
close(fds[1]);
}
- QLocalServer server;
+ CrashSafeLocalServer server;
QVERIFY2(server.listen(listenSocket), qUtf8Printable(server.errorString()));
#if defined(Q_OS_LINUX) || defined(Q_OS_QNX)
@@ -1818,7 +1830,7 @@ void tst_QLocalSocket::verifyListenWithDescriptor_data()
void tst_QLocalSocket::serverBindingsAndProperties()
{
- QLocalServer server;
+ CrashSafeLocalServer server;
QProperty<QLocalServer::SocketOptions> sockOpts;
server.bindableSocketOptions().setBinding(Qt::makePropertyBinding(sockOpts));