summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorBradley T. Hughes <bradley.hughes@nokia.com>2012-02-08 12:26:09 +0100
committerQt by Nokia <qt-info@nokia.com>2012-02-13 22:16:17 +0100
commit3f74aea9bb67bcd2ec463792ee111402f10825d5 (patch)
tree6de93571383c040a5e80e07c7796b12adcf904d6 /tests/auto
parent7bf37d966e062790ff04a51a860a16eb52d46838 (diff)
Fix tst_QSocketNotifier on Mac OS X
Socket notifier behavior is very OS-dependent. QtNetwork uses non- immediately (it will return -1 w/ errno=EINPROGRESS). We have to wait with select(2) to indicate that the connection is ready, then call connect(2) again. When this happens, we need another call to select(2) to get notification on the listening socket so that we can call accept(2) to complete the connection. The mixingWithTimers() failure happens due to the test expecting a single processEvents() call to be able to completely connect a TCP socket. But as described above, this may not happen. The test should QTRY_COMPARE() to give the test a chance to let all this happen. The posixSockets() test can fail due to the same connect() behavior. The test already has a comment about the write notifier behavior being very OS dependent. This caused the first enterLoop() to return too early, before the read notifier fired (which is what the test is checking for, that the read notifier fired). Move creation of the write notifier to where we expect it to fire, just before writing to the posix socket. In the same test, the read notifier inside QTcpSocket may not fire after the write notifier on the posix socket. Use the waitForReadyRead() function to give the socket a chance to read the data written to the posix socket. Change-Id: I541e6ee9a39a92ce3acf6b9ffee51079febe43e4 Reviewed-by: Jonas Gastal <jgastal@profusion.mobi> Reviewed-by: Shane Kearns <ext-shane.2.kearns@nokia.com>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/corelib/kernel/qsocketnotifier/qsocketnotifier.pro2
-rw-r--r--tests/auto/corelib/kernel/qsocketnotifier/tst_qsocketnotifier.cpp19
2 files changed, 12 insertions, 9 deletions
diff --git a/tests/auto/corelib/kernel/qsocketnotifier/qsocketnotifier.pro b/tests/auto/corelib/kernel/qsocketnotifier/qsocketnotifier.pro
index 55f6934fc9..58e4b98af7 100644
--- a/tests/auto/corelib/kernel/qsocketnotifier/qsocketnotifier.pro
+++ b/tests/auto/corelib/kernel/qsocketnotifier/qsocketnotifier.pro
@@ -6,5 +6,3 @@ SOURCES = tst_qsocketnotifier.cpp
requires(contains(QT_CONFIG,private_tests))
include(../../../network/socket/platformsocketengine/platformsocketengine.pri)
-
-mac: CONFIG += insignificant_test # QTBUG-22746
diff --git a/tests/auto/corelib/kernel/qsocketnotifier/tst_qsocketnotifier.cpp b/tests/auto/corelib/kernel/qsocketnotifier/tst_qsocketnotifier.cpp
index e3bfe3bc6d..5442303e7e 100644
--- a/tests/auto/corelib/kernel/qsocketnotifier/tst_qsocketnotifier.cpp
+++ b/tests/auto/corelib/kernel/qsocketnotifier/tst_qsocketnotifier.cpp
@@ -237,7 +237,7 @@ void tst_QSocketNotifier::mixingWithTimers()
QCoreApplication::processEvents();
QCOMPARE(helper.timerActivated, true);
- QCOMPARE(helper.socketActivated, true);
+ QTRY_COMPARE(helper.socketActivated, true);
}
void tst_QSocketNotifier::posixSockets()
@@ -264,10 +264,7 @@ void tst_QSocketNotifier::posixSockets()
connect(&rn, SIGNAL(activated(int)), &QTestEventLoop::instance(), SLOT(exitLoop()));
QSignalSpy readSpy(&rn, SIGNAL(activated(int)));
QVERIFY(readSpy.isValid());
- QSocketNotifier wn(posixSocket, QSocketNotifier::Write);
- connect(&wn, SIGNAL(activated(int)), &QTestEventLoop::instance(), SLOT(exitLoop()));
- QSignalSpy writeSpy(&wn, SIGNAL(activated(int)));
- QVERIFY(writeSpy.isValid());
+ // No write notifier, some systems trigger write notification on socket creation, but not all
QSocketNotifier en(posixSocket, QSocketNotifier::Exception);
connect(&en, SIGNAL(activated(int)), &QTestEventLoop::instance(), SLOT(exitLoop()));
QSignalSpy errorSpy(&en, SIGNAL(activated(int)));
@@ -278,19 +275,27 @@ void tst_QSocketNotifier::posixSockets()
QTestEventLoop::instance().enterLoop(3);
QCOMPARE(readSpy.count(), 1);
- writeSpy.clear(); //depending on OS, write notifier triggers on creation or not.
QCOMPARE(errorSpy.count(), 0);
char buffer[100];
- qt_safe_read(posixSocket, buffer, 100);
+ int r = qt_safe_read(posixSocket, buffer, 100);
+ QCOMPARE(r, 6);
QCOMPARE(buffer, "hello");
+ QSocketNotifier wn(posixSocket, QSocketNotifier::Write);
+ connect(&wn, SIGNAL(activated(int)), &QTestEventLoop::instance(), SLOT(exitLoop()));
+ QSignalSpy writeSpy(&wn, SIGNAL(activated(int)));
+ QVERIFY(writeSpy.isValid());
qt_safe_write(posixSocket, "goodbye", 8);
QTestEventLoop::instance().enterLoop(3);
QCOMPARE(readSpy.count(), 1);
QCOMPARE(writeSpy.count(), 1);
QCOMPARE(errorSpy.count(), 0);
+
+ // Write notifier may have fired before the read notifier inside
+ // QTcpSocket, give QTcpSocket a chance to see the incoming data
+ passive->waitForReadyRead(100);
QCOMPARE(passive->readAll(), QByteArray("goodbye",8));
}
qt_safe_close(posixSocket);