Fix haagent test leaking policy thread loop

Fix and investigate why the policy_thread loop is not properly terminating sometimes.