Test longpoller server termination and fix timeout bug