Add a test for autocompletion and remove deadlock.

* Close socket when user requests client close.
* Add minimal test for autocompletion.