QSocketNotifier: firm up the ordering in unexpectedDisconnection()
The test was relying on the fact that, having written 1 byte to both writeEnd1 and writeEnd2 (and ensured those bytes were written with waitForBytesWritten()), both read ends would be activated by the next event loop. It turns out that this was an unreliable assumption, because the processing of that 1 byte on the second socket may not have happened yet. So firm up by waiting that both read ends are readable before even creating the QSocketNotifiers we will read on. I'm not entirely sure what this test is attempting to test. Its documentation says it's testing a QAbstractSocket condition, but the read ends aren't QAbstractSocket (this test should have been in tst_QAbstractSocket if so). It may be testing the condition that caused that QAbstractSocket behavior, but that wouldn't be a good test. Drive-by remove redundant flush()-after-waitForBytesWritten() calls. Fixes: QTBUG-115154 Change-Id: I61b74deaf2514644a24efffd17708f8071f707ed Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> (cherry picked from commit 93b87b5cbfae3c50e539f6ec37bd7b95e89e455e) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
8d86ae9f90
commit
91a3ba1496
@ -1,2 +0,0 @@
|
||||
[unexpectedDisconnection]
|
||||
macos ci # QTBUG-115154
|
@ -132,11 +132,11 @@ public slots:
|
||||
++sequence;
|
||||
if (sequence == 1) {
|
||||
// read from both ends
|
||||
(void) readEnd1->read(data1, sizeof(data1));
|
||||
(void) readEnd2->read(data2, sizeof(data2));
|
||||
QCOMPARE(readEnd1->read(data1, sizeof(data1)), 1);
|
||||
QCOMPARE(readEnd2->read(data2, sizeof(data2)), 1);
|
||||
emit finished();
|
||||
} else if (sequence == 2) {
|
||||
// we should never get here
|
||||
// check that we can't read now because we've read our byte
|
||||
QCOMPARE(readEnd2->read(data2, sizeof(data2)), qint64(-2));
|
||||
QVERIFY(readEnd2->isValid());
|
||||
}
|
||||
@ -152,7 +152,7 @@ void tst_QSocketNotifier::unexpectedDisconnection()
|
||||
Given two sockets and two QSocketNotifiers registered on each
|
||||
their socket. If both sockets receive data, and the first slot
|
||||
invoked by one of the socket notifiers empties both sockets, the
|
||||
other notifier will also emit activated(). This results in
|
||||
other notifier will also emit activated(). This was causing an
|
||||
unexpected disconnection in QAbstractSocket.
|
||||
|
||||
The use case is that somebody calls one of the
|
||||
@ -188,8 +188,9 @@ void tst_QSocketNotifier::unexpectedDisconnection()
|
||||
writeEnd1->waitForBytesWritten();
|
||||
writeEnd2->waitForBytesWritten();
|
||||
|
||||
writeEnd1->flush();
|
||||
writeEnd2->flush();
|
||||
// ensure both read ends are ready for reading, before the event loop
|
||||
QVERIFY(readEnd1.waitForRead(5000));
|
||||
QVERIFY(readEnd2.waitForRead(5000));
|
||||
|
||||
UnexpectedDisconnectTester tester(&readEnd1, &readEnd2);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user