QTest cleanupTestCase not calling (QueuedConnection) slot
-
I am using QTest to test an application which uploads data to a SQL database. The application manages an independent thread for the classes involved in collecting the data and uploading them.
In my test case, I instatiate a class to access the data and download it, to compare against the original values. This class is moved to the database thread managed by the application.
After the tests have run, I want to DROP the database table. To do this, I need to invoke a slot in my test class which is running on the database thread.
QSignalSpy DropSpy( &m_DBConnector, &CDBConnector::TableDropped ); QVERIFY(DropSpy.isValid()); QMetaObject::invokeMethod( &m_DBConnector, "DropTable", Q_ARG(QString, CPerfusionDatabase::VariablesTable()) ); QVERIFY( DropSpy.wait(m_DBWait) ); QVERIFY( DropSpy.constLast().at(0).toBool() );
However, it seems not to work when called from the cleanupTestCase function - the DropTable slot is not invoked (I place a breakpoint in DEBUG, and this is not hit).
It does work if this code is invoked from a "regular" test slot.
I presume that there is some kind of QTest/MOC magic which makes queuing a slot in another thread infeasible.
Does anyone have any insight as to how to make this work ?
[At present my best workaround idea is to run a DropTable test slot (within the test case exe being run), and try to ensure that this is the last test, but it doesn't sound very robust]
-
Hi,
Are you sure your database connection is still opened when arriving in the cleanup function ?