Make --test mode work properly with a running daemon. fix #2376