code & unit test for spark context hang detection logic