Fix bugs in leader detection
Fix state (shutdown) bugs in server_test