CppUnit测试与Qt 5.9挂起

时间:2022-04-10 22:47:10

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

在将源代码从Qt 5.6移植到Qt 5.9.1时,在使用CppUnit 1.13.2进行测试时出现了问题:DllPluginTester.exe在完成所有单元测试后成功挂起。在调试进程时,堆栈会显示出来

CppUnit::DynamicLibraryManager::doReleaseLibrary()

gets stuck calling ::FreeLibrary, and further up the stack hangs in QThread::wait(), i.e. WaitForSingleObject waits forever.

调用:: FreeLibrary,并在QThread :: wait()中挂起堆栈,即WaitForSingleObject永远等待。

Has anybody an idea what can cause such a behavior?

有谁知道什么会导致这样的行为?

1 个解决方案

#1


0  

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.

我找到了这个问题的原因:c.f。 QTBUG-34460。我不知道为什么在从Qt版本5.6迁移到5.9.1之前没有发现该问题,因为已经报告了版本5.1.1的错误。所以调查花了一些时间。

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:

对于受影响的测试 - 所有这些测试都涉及某种多线程,例如,通过在某处调用QtConcurrent :: run() - 我在每个受影响的测试结束时插入以下行作为我的解决方案:

void UnitTestClass::testWithMultithreadingInside
{
  ...
  constexpr auto MAX_WAIT_MS = 5000;
  auto pool = QThreadPool::globalInstance();
  if (pool)
  {
    pool->clear();
    pool->waitForDone(MAX_WAIT_MS);
  }
}

#1


0  

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.

我找到了这个问题的原因:c.f。 QTBUG-34460。我不知道为什么在从Qt版本5.6迁移到5.9.1之前没有发现该问题,因为已经报告了版本5.1.1的错误。所以调查花了一些时间。

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:

对于受影响的测试 - 所有这些测试都涉及某种多线程,例如,通过在某处调用QtConcurrent :: run() - 我在每个受影响的测试结束时插入以下行作为我的解决方案:

void UnitTestClass::testWithMultithreadingInside
{
  ...
  constexpr auto MAX_WAIT_MS = 5000;
  auto pool = QThreadPool::globalInstance();
  if (pool)
  {
    pool->clear();
    pool->waitForDone(MAX_WAIT_MS);
  }
}