Skip to content

Commit

Permalink
Fix races in TestClient_Get tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vcabbage committed May 10, 2016
1 parent ccd74ee commit 667ae84
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,11 @@ func TestClient_Get(t *testing.T) {
continue
}

var mu sync.Mutex

ip, port, close := newTestServer(t, singlePort, func(w ReadRequest) {
mu.Lock()
defer mu.Unlock()
if c.sendServerError {
w.WriteError(ErrCodeAccessViolation, "server error")
return
Expand All @@ -432,10 +436,14 @@ func TestClient_Get(t *testing.T) {
if match, _ := regexp.MatchString(c.expectedError, ErrorCause(err).Error()); !match {
t.Errorf("%s: expected error %q, got %q", label, c.expectedError, ErrorCause(err).Error())
}
mu.Lock()
mu.Unlock()
continue
}

response, err := ioutil.ReadAll(file)
mu.Lock()
mu.Unlock()
if err != nil {
t.Fatal(label, err)
}
Expand Down

0 comments on commit 667ae84

Please sign in to comment.