summaryrefslogtreecommitdiffstats
path: root/tests/auto/qlocalsocket/tst_qlocalsocket.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/qlocalsocket/tst_qlocalsocket.cpp')
-rw-r--r--tests/auto/qlocalsocket/tst_qlocalsocket.cpp54
1 files changed, 25 insertions, 29 deletions
diff --git a/tests/auto/qlocalsocket/tst_qlocalsocket.cpp b/tests/auto/qlocalsocket/tst_qlocalsocket.cpp
index 44f3c12..d2cba6e 100644
--- a/tests/auto/qlocalsocket/tst_qlocalsocket.cpp
+++ b/tests/auto/qlocalsocket/tst_qlocalsocket.cpp
@@ -683,25 +683,11 @@ public:
QString testLine = "test";
LocalSocket socket;
QSignalSpy spyReadyRead(&socket, SIGNAL(readyRead()));
- int tries = 0;
- do {
- socket.connectToServer("qlocalsocket_threadtest");
- if (socket.error() != QLocalSocket::ServerNotFoundError
- && socket.error() != QLocalSocket::ConnectionRefusedError)
- break;
- QTest::qWait(100);
- ++tries;
- } while ((socket.error() == QLocalSocket::ServerNotFoundError
- || socket.error() == QLocalSocket::ConnectionRefusedError)
- && tries < 1000);
- if (tries == 0 && socket.state() != QLocalSocket::ConnectedState) {
- QVERIFY(socket.waitForConnected(7000));
- QVERIFY(socket.state() == QLocalSocket::ConnectedState);
- }
+ socket.connectToServer("qlocalsocket_threadtest");
+ QVERIFY(socket.waitForConnected(1000));
// We should *not* have this signal yet!
- if (tries == 0)
- QCOMPARE(spyReadyRead.count(), 0);
+ QCOMPARE(spyReadyRead.count(), 0);
socket.waitForReadyRead();
QCOMPARE(spyReadyRead.count(), 1);
QTextStream in(&socket);
@@ -715,6 +701,8 @@ class Server : public QThread
public:
int clients;
+ QMutex mutex;
+ QWaitCondition wc;
void run()
{
QString testLine = "test";
@@ -722,6 +710,9 @@ public:
server.setMaxPendingConnections(10);
QVERIFY2(server.listen("qlocalsocket_threadtest"),
server.errorString().toLatin1().constData());
+ mutex.lock();
+ wc.wakeAll();
+ mutex.unlock();
int done = clients;
while (done > 0) {
bool timedOut = true;
@@ -746,14 +737,9 @@ void tst_QLocalSocket::threadedConnection_data()
QTest::addColumn<int>("threads");
QTest::newRow("1 client") << 1;
QTest::newRow("2 clients") << 2;
-#ifdef Q_OS_WINCE
- QTest::newRow("4 clients") << 4;
-#endif
-#ifndef Q_OS_WIN
QTest::newRow("5 clients") << 5;
- QTest::newRow("10 clients") << 10;
-#endif
#ifndef Q_OS_WINCE
+ QTest::newRow("10 clients") << 10;
QTest::newRow("20 clients") << 20;
#endif
}
@@ -770,7 +756,9 @@ void tst_QLocalSocket::threadedConnection()
server.setStackSize(0x14000);
#endif
server.clients = threads;
+ server.mutex.lock();
server.start();
+ server.wc.wait(&server.mutex);
QList<Client*> clients;
for (int i = 0; i < threads; ++i) {
@@ -784,9 +772,7 @@ void tst_QLocalSocket::threadedConnection()
server.wait();
while (!clients.isEmpty()) {
QVERIFY(clients.first()->wait(3000));
- Client *client =clients.takeFirst();
- client->terminate();
- delete client;
+ delete clients.takeFirst();
}
}
@@ -994,6 +980,7 @@ void tst_QLocalSocket::writeToClientAndDisconnect()
QLocalServer server;
QLocalSocket client;
+ QSignalSpy readChannelFinishedSpy(&client, SIGNAL(readChannelFinished()));
QVERIFY(server.listen("writeAndDisconnectServer"));
client.connectToServer("writeAndDisconnectServer");
@@ -1006,10 +993,19 @@ void tst_QLocalSocket::writeToClientAndDisconnect()
memset(buffer, 0, sizeof(buffer));
QCOMPARE(clientSocket->write(buffer, sizeof(buffer)), (qint64)sizeof(buffer));
clientSocket->waitForBytesWritten();
- clientSocket->disconnectFromServer();
- QVERIFY(client.waitForReadyRead());
+ clientSocket->close();
+ server.close();
+
+ // Wait for the client to notice the broken connection.
+ int timeout = 5000;
+ do {
+ const int timestep = 100;
+ QTest::qWait(timestep);
+ timeout -= timestep;
+ } while (!readChannelFinishedSpy.count() && timeout > 0);
+
+ QCOMPARE(readChannelFinishedSpy.count(), 1);
QCOMPARE(client.read(buffer, sizeof(buffer)), (qint64)sizeof(buffer));
- QVERIFY(client.waitForDisconnected());
QCOMPARE(client.state(), QLocalSocket::UnconnectedState);
}