Skip to content

Commit

Permalink
command: fix TestHelpers_LineLimitReader_TimeLimit() goroutine (#6678)
Browse files Browse the repository at this point in the history
  • Loading branch information
alrs authored and tgross committed Nov 12, 2019
1 parent 33ba439 commit 2784f16
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions command/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,25 +174,32 @@ func TestHelpers_LineLimitReader_TimeLimit(t *testing.T) {

expected := []byte("hello world")

resultCh := make(chan struct{})
errCh := make(chan error)
resultCh := make(chan []byte)
go func() {
defer close(resultCh)
defer close(errCh)
outBytes, err := ioutil.ReadAll(limit)
if err != nil {
t.Fatalf("ReadAll failed: %v", err)
}

if reflect.DeepEqual(outBytes, expected) {
close(resultCh)
errCh <- fmt.Errorf("ReadAll failed: %v", err)
return
}
resultCh <- outBytes
}()

// Send the data
in.data <- expected
in.Close()

select {
case <-resultCh:
case err := <-errCh:
if err != nil {
t.Fatalf("ReadAll: %v", err)
}
case outBytes := <-resultCh:
if !reflect.DeepEqual(outBytes, expected) {
t.Fatalf("got:%s, expected,%s", string(outBytes), string(expected))
}
case <-time.After(1 * time.Second):
t.Fatalf("did not exit by time limit")
}
Expand Down

0 comments on commit 2784f16

Please sign in to comment.