Fix deadlock of test case when expected exception is thrown.