From 74a6fe79d999178de9d16befe7547af2d2f9f698 Mon Sep 17 00:00:00 2001 From: David Faure Date: Thu, 21 Jul 2011 16:56:55 +0200 Subject: Speed up tst_qcoreapplication It was emitting signals from a thread for 15 seconds. Doing this 10 times should be enough, and way faster. Also a race made it sometimes wait 15 seconds while nothing was happening, and then it would still succeed; the new code prevents this from happening. Change-Id: Ib36785dd8090047c760ddcca44fc805efaef1bd8 Merge-request: 4 Reviewed-by: Olivier Goffart Reviewed-on: http://codereview.qt.nokia.com/1989 Reviewed-by: Qt Sanity Bot --- .../auto/qcoreapplication/tst_qcoreapplication.cpp | 45 +++++++++++++--------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/tests/auto/qcoreapplication/tst_qcoreapplication.cpp b/tests/auto/qcoreapplication/tst_qcoreapplication.cpp index 0b581af77b..99f0941ac2 100644 --- a/tests/auto/qcoreapplication/tst_qcoreapplication.cpp +++ b/tests/auto/qcoreapplication/tst_qcoreapplication.cpp @@ -361,26 +361,25 @@ class DeliverInDefinedOrderObject : public QObject QPointer thread; int count; + int startCount; + int loopLevel; public: DeliverInDefinedOrderObject(QObject *parent) - : QObject(parent), thread(0), count(0) + : QObject(parent), thread(0), count(0), startCount(0), loopLevel(0) { } - ~DeliverInDefinedOrderObject() - { - if (!thread.isNull()) - thread->wait(); - } + +signals: + void done(); public slots: - void start() + void startThread() { QVERIFY(!thread); thread = new DeliverInDefinedOrderThread(); connect(thread, SIGNAL(progress(int)), this, SLOT(threadProgress(int))); connect(thread, SIGNAL(finished()), this, SLOT(threadFinished())); - connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); - connect(thread, SIGNAL(destroyed()), this, SLOT(start())); + connect(thread, SIGNAL(destroyed()), this, SLOT(threadDestroyed())); thread->start(); QCoreApplication::postEvent(this, new QEvent(QEvent::MaxUser), -1); @@ -398,21 +397,34 @@ public slots: { QVERIFY(count == 7); count = 0; + thread->deleteLater(); QCoreApplication::postEvent(this, new QEvent(QEvent::MaxUser), -1); } + void threadDestroyed() + { + if (++startCount < 20) + startThread(); + else + emit done(); + } + public: bool event(QEvent *event) { switch (event->type()) { case QEvent::User: - { - (void) QEventLoop().exec(); - break; + { + ++loopLevel; + if (loopLevel == 2) { + // Ready. Starts a thread that emits (queued) signals, which should be handled in order + startThread(); } - case QEvent::User + 1: + QCoreApplication::postEvent(this, new QEvent(QEvent::MaxUser), -1); + (void) QEventLoop().exec(); break; + } default: break; } @@ -430,11 +442,8 @@ void tst_QCoreApplication::deliverInDefinedOrder() // causes sendPostedEvents() to recurse twice QCoreApplication::postEvent(&obj, new QEvent(QEvent::User)); QCoreApplication::postEvent(&obj, new QEvent(QEvent::User)); - // starts a thread that emits (queued) signals, which should be handled in order - obj.start(); - // run for 15 seconds - QTimer::singleShot(15000, &app, SLOT(quit())); + QObject::connect(&obj, SIGNAL(done()), &app, SLOT(quit())); app.exec(); } #endif // QT_NO_QTHREAD @@ -524,7 +533,7 @@ void tst_QCoreApplication::processEventsAlwaysSendsPostedEvents() QCoreApplication::processEvents(); QCOMPARE(object.counter, i); ++i; - } while (t.elapsed() < 3000); + } while (t.elapsed() < 1000); } void tst_QCoreApplication::reexec() -- cgit v1.2.3