Merge branch '8284-fix-slurm-queue-timestamp-check' closes #8284
[arvados.git] / services / crunchstat / crunchstat_test.go
index fe922e99eefb47ca62af90bad7bf33676a8730ee..69f31afbc9589ce6cd6c9de2a731d5093e2c80cd 100644 (file)
@@ -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,18 +75,33 @@ 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" {
-               t.Fatal("\"after\n\" not received (got \"%s\", %s)", after, err)
+               t.Fatalf("\"after\n\" not received (got \"%s\", %s)", after, err)
        }
 
        select {
@@ -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)