Fixed example tests to properly wait for the scheduler process to
terminate.

Review: https://reviews.apache.org/r/14640