From a37dd93defd91b79fb6730d0ff0515a66a0d3972 Mon Sep 17 00:00:00 2001 From: Kari Oikarinen Date: Tue, 13 Feb 2018 15:10:20 +0200 Subject: [PATCH] Fix crash in tst_QStateMachine::dontProcessSlotsWhenMachineIsNotRunning The test sometimes ended up with: QThread: Destroyed while thread is still running Received a fatal error. This was because as a member variable of the local struct the QThread object was sometimes destructed before the signal connection quitting it was handled. Fix that by making sure that the thread is finished before finishing the test. Also moved connecting to the state machine's signal to be before starting the machine. Because the counting of QStateMachine::finished signal could hit 1 after the first signal is emitted and the test could pass without the code working, check that both of the signals have been emitted. Task-number: QTBUG-66372 Task-number: QTBUG-66216 Change-Id: If14141e39f37541032ddd8c6471daf40a77b0469 Reviewed-by: Frederik Gladhorn --- .../statemachine/qstatemachine/tst_qstatemachine.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp b/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp index b80c6ae8111..17763f31f95 100644 --- a/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp +++ b/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp @@ -6684,10 +6684,13 @@ void tst_QStateMachine::dontProcessSlotsWhenMachineIsNotRunning() machine.addState(&initialState); machine.addState(&finalState); machine.setInitialState(&initialState); - machine.start(); connect(&machine, &QStateMachine::finished, &emitter.thread, &QThread::quit); - QSignalSpy signalSpy(&machine, &QStateMachine::finished); - QTRY_COMPARE_WITH_TIMEOUT(signalSpy.count(), 1, 100); + machine.start(); + QSignalSpy emittedSpy(&emitter, &SignalEmitter::signalWithNoArg); + QSignalSpy finishedSpy(&machine, &QStateMachine::finished); + QTRY_COMPARE_WITH_TIMEOUT(emittedSpy.count(), 2, 100); + QTRY_COMPARE(finishedSpy.count(), 1); + QTRY_VERIFY(emitter.thread.isFinished()); } QTEST_MAIN(tst_QStateMachine)