Fix race condition in state_machine_test

Change-Id: I79b76936cc51f916b7096ffe44482990bf422126
Merge "Fix race condition in state_machine_test"