While porting our source code from Qt 5.6 to Qt 5.9.1 an issue has come up when testing with CppUnit 1.13.2: DllPluginTester.exe
hangs when having successfully performed all unit tests on finishing. When debugging into the process the stack shows that
CppUnit::DynamicLibraryManager::doReleaseLibrary()
gets stuck calling ::FreeLibrary
, and further up the stack hangs in QThread::wait()
, i.e. WaitForSingleObject
waits forever.
Has anybody an idea what can cause such a behavior?
I have found the cause of that issue: c.f. QTBUG-34460. I don't know why the issue did not discover before moving from Qt version 5.6 to 5.9.1, since the bug was reported already for version 5.1.1. So investigation took some time.
For the affected tests - which all of them were involved in some kind of multithreading, e.g. by calling QtConcurrent::run()
somewhere - I inserted the following lines at the end of each affected test as my solution:
void UnitTestClass::testWithMultithreadingInside
{
...
constexpr auto MAX_WAIT_MS = 5000;
auto pool = QThreadPool::globalInstance();
if (pool)
{
pool->clear();
pool->waitForDone(MAX_WAIT_MS);
}
}