X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/46558e7be9da2099ccb12497230ad81ed1d35889..1cecdfb6fabf47c921e7f422063368621619dcfb:/services/crunchstat/crunchstat_test.go diff --git a/services/crunchstat/crunchstat_test.go b/services/crunchstat/crunchstat_test.go index fe922e99ee..13f4dc60f7 100644 --- a/services/crunchstat/crunchstat_test.go +++ b/services/crunchstat/crunchstat_test.go @@ -57,7 +57,7 @@ func TestCopyPipeToChildLogLongLines(t *testing.T) { pipeIn, pipeOut := io.Pipe() go CopyPipeToChildLog(pipeIn, control) - sentBytes := make([]byte, bufio.MaxScanTokenSize + (1 << 22)) + sentBytes := make([]byte, bufio.MaxScanTokenSize+MaxLogLine+(1<<22)) go func() { pipeOut.Write([]byte("before\n")) @@ -75,14 +75,29 @@ func TestCopyPipeToChildLogLongLines(t *testing.T) { if before, err := rcv.ReadBytes('\n'); err != nil || string(before) != "before\n" { t.Fatalf("\"before\n\" not received (got \"%s\", %s)", before, err) } - - receivedString, err := rcv.ReadBytes('\n') - if err != nil { - t.Fatal(err) + + var receivedBytes []byte + done := false + for !done { + line, err := rcv.ReadBytes('\n') + if err != nil { + t.Fatal(err) + } + if len(line) >= 5 && string(line[0:5]) == "[...]" { + if receivedBytes == nil { + t.Fatal("Beginning of line reported as continuation") + } + line = line[5:] + } + if len(line) >= 6 && string(line[len(line)-6:len(line)]) == "[...]\n" { + line = line[:len(line)-6] + } else { + done = true + } + receivedBytes = append(receivedBytes, line...) } - receivedBytes := []byte(receivedString) if bytes.Compare(receivedBytes, sentBytes) != 0 { - t.Fatalf("sent %d bytes, got %d different bytes", len(sentBytes)+1, len(receivedBytes)) + t.Fatalf("sent %d bytes, got %d different bytes", len(sentBytes), len(receivedBytes)) } if after, err := rcv.ReadBytes('\n'); err != nil || string(after) != "after\n" { @@ -97,7 +112,7 @@ func TestCopyPipeToChildLogLongLines(t *testing.T) { } } -func captureLogs() (*bufio.Reader) { +func captureLogs() *bufio.Reader { // Send childLog to our bufio reader instead of stderr stderrIn, stderrOut := io.Pipe() childLog = log.New(stderrOut, "", 0)