From 1e70781e7f0b012fcfbf85f86c24f3b46e362d4e Mon Sep 17 00:00:00 2001 From: Milian Wolff Date: Fri, 22 Mar 2019 11:18:14 +0100 Subject: 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) Reviewed-by: Kari Oikarinen --- .../auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/auto/corelib/statemachine') diff --git a/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp b/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp index 810698fb4e..55a672aae1 100644 --- a/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp +++ b/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp @@ -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); -- cgit v1.2.3