Stabilize tst_QStateMachine::dontProcessSlotsWhenMachineIsNotRunning
The test is flaky which was uncovered by the upcoming QTimer::singleShot optimization patches: When the Emitter's thread is started and executes the timout functor before the state machine is started, then the state machine will never see the emitSignalWithNoArg signal and thus never transition to the final state and finish. This patch ensures that the code in the background thread is only run after the state machine was started to fix this flakyness. Change-Id: I6f91a2420165662ece75e550a6d73fe098137d4c Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com> Reviewed-by: Kari Oikarinen <kari.oikarinen@qt.io>
This commit is contained in:
parent
68d75aef76
commit
1e70781e7f
@ -6680,13 +6680,13 @@ void tst_QStateMachine::dontProcessSlotsWhenMachineIsNotRunning()
|
||||
} emitter;
|
||||
|
||||
initialState.addTransition(&emitter, &Emitter::signalWithNoArg, &finalState);
|
||||
QTimer::singleShot(0, [&]() {
|
||||
metaObject()->invokeMethod(&emitter, "emitSignalWithNoArg");
|
||||
metaObject()->invokeMethod(&emitter, "emitSignalWithNoArg");
|
||||
});
|
||||
machine.addState(&initialState);
|
||||
machine.addState(&finalState);
|
||||
machine.setInitialState(&initialState);
|
||||
connect(&machine, &QStateMachine::started, &emitter, [&]() {
|
||||
metaObject()->invokeMethod(&emitter, "emitSignalWithNoArg");
|
||||
metaObject()->invokeMethod(&emitter, "emitSignalWithNoArg");
|
||||
});
|
||||
connect(&machine, &QStateMachine::finished, &emitter.thread, &QThread::quit);
|
||||
machine.start();
|
||||
QSignalSpy emittedSpy(&emitter, &SignalEmitter::signalWithNoArg);
|
||||
|
Loading…
Reference in New Issue
Block a user