Extract test helper method wait_on_event_or_timeout