Adds macro while-timout to avoid test hangs

Some tests have been getting stuck forever while waiting for a particular state in a test cluster.

This change will have tests error after 5 seconds in these situations instead of hanging indefinitely.