Skip to content

Commit

Permalink
Fix TestWriteCoalescing (apache#1188)
Browse files Browse the repository at this point in the history
  • Loading branch information
beltran authored and Zariel committed Sep 13, 2018
1 parent 4563d9e commit 5a139e8
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -758,33 +758,34 @@ func TestWriteCoalescing(t *testing.T) {
cond: sync.NewCond(&sync.Mutex{}),
}

var wg sync.WaitGroup

wg.Add(1)
go func() {
wg.Done()
if _, err := w.Write([]byte("one")); err != nil {
t.Error(err)
}
}()
wg.Wait()

wg.Add(1)
go func() {
wg.Done()
if _, err := w.Write([]byte("two")); err != nil {
t.Error(err)
}
}()
wg.Wait()

if buf.Len() != 0 {
t.Fatalf("expected buffer to be empty have: %v", buf.String())
}

for true {
w.cond.L.Lock()
if len(w.buffers) == 2 {
w.cond.L.Unlock()
break
}
w.cond.L.Unlock()
}

w.flush()
if got := buf.String(); got != "onetwo" {
t.Fatalf("expected to get %q got %q", "onetwo", got)
if got := buf.String(); got != "onetwo" && got != "twoone" {
t.Fatalf("expected to get %q got %q", "onetwo or twoone", got)
}
}

Expand Down

0 comments on commit 5a139e8

Please sign in to comment.