Fix asynchronous problem with test

Moving all clean-up work to the callback function.

Signed-off-by: Chen, Yiqun