server: add unit tests

Make test coverage >= 90%

#1019 
It helps to verify that it is closed because of cancel and returns the correct error.