Add UT for Timer.

Also fix the bug in Task cancelling.