[Utils] Fix a problem in which the callback function is invoked synchronously in a condition.

This patch also fixes the test that is depending on the wrong behaivor.