From 5eb91476f15650c1cd443502fca093b21315ea09 Mon Sep 17 00:00:00 2001 From: David Faure Date: Thu, 29 Aug 2013 08:33:37 +0200 Subject: [PATCH] tst_qthreadpool: fix flaky test I introduced in last commit (dacf9961da86) In order to see 2 active threads, we must check activeThreadCount() before the runnable finishes. Change-Id: I1a48b41e0c1fd81a65d915b9bd1e741ff267ed2b Reviewed-by: Olivier Goffart --- tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp b/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp index cdf240d7577..4a9932798c7 100644 --- a/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp +++ b/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp @@ -638,6 +638,7 @@ void tst_QThreadPool::reserveAndStart() // QTBUG-21051 public: QAtomicInt count; QSemaphore waitForStarted; + QSemaphore waitBeforeDone; WaitingTask() { setAutoDelete(false); } @@ -645,6 +646,7 @@ void tst_QThreadPool::reserveAndStart() // QTBUG-21051 { count.ref(); waitForStarted.release(); + waitBeforeDone.acquire(); } }; @@ -663,6 +665,7 @@ void tst_QThreadPool::reserveAndStart() // QTBUG-21051 threadpool->start(task); QCOMPARE(threadpool->activeThreadCount(), 2); task->waitForStarted.acquire(); + task->waitBeforeDone.release(); QTRY_COMPARE(task->count.load(), 1); QTRY_COMPARE(threadpool->activeThreadCount(), 1); @@ -675,6 +678,7 @@ void tst_QThreadPool::reserveAndStart() // QTBUG-21051 threadpool->start(task); QTRY_COMPARE(threadpool->activeThreadCount(), 2); task->waitForStarted.acquire(); + task->waitBeforeDone.release(); QTRY_COMPARE(task->count.load(), 2); QTRY_COMPARE(threadpool->activeThreadCount(), 1);