Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
client: do cleanup after UT stop mock server
Browse files Browse the repository at this point in the history
Remove /tmp/agentserver.socker when test case is done and output
firendly error message when remove the file failed.

Fixes #418

Signed-off-by: NingBo <[email protected]>
  • Loading branch information
NingBo committed Nov 29, 2018
1 parent 0ff3006 commit 4eca13b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion protocols/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ const (
)

func startMockServer(t *testing.T, enableYamux bool) (*grpc.Server, chan error, error) {
os.Remove(mockSockAddr)
err := os.RemoveAll(mockSockAddr)
assert.Nil(t, err, "Remove %s failed", mockSockAddr)
if err != nil {
assert.FailNow(t, err.Error(), "Failed to start mock server")
}

l, err := net.Listen("unix", mockSockAddr)
assert.Nil(t, err, "Listen on %s failed: %s", mockSockAddr, err)
Expand Down Expand Up @@ -114,6 +118,7 @@ func agentClientTest(t *testing.T, sock string, success, enableYamux bool, expec
func TestNewAgentClient(t *testing.T) {
mock, waitCh, err := startMockServer(t, false)
assert.Nil(t, err, "failed to start mock server: %s", err)
defer os.Remove(mockSockAddr)

cliFunc := func(sock string, success bool, expect string) {
agentClientTest(t, sock, success, false, expect)
Expand All @@ -137,6 +142,7 @@ func TestNewAgentClient(t *testing.T) {
func TestNewAgentClientWithYamux(t *testing.T) {
mock, waitCh, err := startMockServer(t, true)
assert.Nil(t, err, "failed to start mock server: %s", err)
defer os.Remove(mockSockAddr)

cliFunc := func(sock string, success bool, expect string) {
agentClientTest(t, sock, success, true, expect)
Expand Down

0 comments on commit 4eca13b

Please sign in to comment.