How to test that a function doesn't infinite loop