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>
This commit is contained in:
parent
e0a1bbc1d3
commit
a37dd93def
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user