server: add unit tests

Make test coverage >= 90%

#1019 
it's weird. i will clean `ctx` code in another PR.