summaryrefslogtreecommitdiffstats
path: root/tests/auto/qlocalsocket
diff options
context:
space:
mode:
authorJoerg Bornemann <joerg.bornemann@nokia.com>2010-06-10 12:37:47 +0200
committerJoerg Bornemann <joerg.bornemann@nokia.com>2010-06-10 15:31:17 +0200
commit6c8b980a8ea8009a7b80fcce419e331df778a989 (patch)
tree5c94604fe23961a8497dd340f8807d01c5bafed4 /tests/auto/qlocalsocket
parent90518a59df46312d56e4c6bc7080415b44b928f4 (diff)
tst_QLocalSocket::threadedConnection autotest stabilized
Fixed race condition on connection. Done-with: ossi Reviewed-by: ossi
Diffstat (limited to 'tests/auto/qlocalsocket')
-rw-r--r--tests/auto/qlocalsocket/tst_qlocalsocket.cpp38
1 files changed, 12 insertions, 26 deletions
diff --git a/tests/auto/qlocalsocket/tst_qlocalsocket.cpp b/tests/auto/qlocalsocket/tst_qlocalsocket.cpp
index 44f3c12a83..dbb58c19cb 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();
}
}