use non-blocking channel to prevent dead-lock and add test for server
Add tests for the api