Add tests for TimeoutStalled (frontend and backend) cases, and fixed related
bugs.