Merge branch 'master' into 4232-slow-pipes-n-jobs
[arvados.git] / services / crunchstat / crunchstat_test.go
index 48988a136743d63a352a0eda0a38895a9e8a797c..e3c3a597eacb640557e0e9fdd789a017ab35a8c8 100644 (file)
@@ -1,6 +1,8 @@
 package main
 
 import (
+       "bufio"
+       "io"
        "os"
        "regexp"
        "testing"
@@ -48,3 +50,30 @@ func TestReadAllOrWarnSuccess(t *testing.T) {
                t.Fatalf("Expected channel to close, got %s", msg)
        }
 }
+
+// Test that if CopyPipeToChan reads a line longer than
+// bufio.MaxScanTokenSize, it emits an error to the output channel.
+func TestCopyPipeToChanLongLines(t *testing.T) {
+       logChan := make(chan string)
+       control := make(chan bool)
+
+       pipeIn, pipeOut := io.Pipe()
+       go CopyPipeToChan(pipeIn, logChan, control)
+
+       go func() {
+               long_line := make([]byte, bufio.MaxScanTokenSize+1)
+               for i := range long_line {
+                       long_line[i] = byte('x')
+               }
+               pipeOut.Write(long_line)
+       }()
+
+       // Expect error message from logChan.
+
+       errmsg := <-logChan
+       if matched, err := regexp.MatchString("^crunchstat: line buffering error:.*token too long", errmsg); err != nil || !matched {
+               t.Fatalf("expected CopyPipeToChan error, got %s", errmsg)
+       }
+
+       <-control
+}