summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/statemachine
diff options
context:
space:
mode:
authorKari Oikarinen <kari.oikarinen@qt.io>2018-02-13 15:10:20 +0200
committerKari Oikarinen <kari.oikarinen@qt.io>2018-02-14 08:12:20 +0000
commita37dd93defd91b79fb6730d0ff0515a66a0d3972 (patch)
tree06172e6692ae85e33dd69366e51473a46697cff2 /tests/auto/corelib/statemachine
parente0a1bbc1d3cd8a1dd9e9825b6040885e0e455823 (diff)
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 <frederik.gladhorn@qt.io>
Diffstat (limited to 'tests/auto/corelib/statemachine')
-rw-r--r--tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp9
1 files 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 b80c6ae811..17763f31f9 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)