server: add unit tests

Make test coverage >= 90%

#1019 
can you change it to close(done). move to line 279. we do not need the defer.