4889: improve error message, unit test
authorTim Pierce <twp@unchi.org>
Thu, 22 Jan 2015 22:05:36 +0000 (17:05 -0500)
committerTim Pierce <twp@unchi.org>
Thu, 22 Jan 2015 22:05:36 +0000 (17:05 -0500)
Per review in #4889-17:

Updated the CopyPipeToChan error message to be more descriptive, for the
benefit of anyone reading log output.

Corrected the test to confirm that the error message is received even if
the child process does not close the stderr log (which matches the usage
patterns in production).

services/crunchstat/crunchstat.go
services/crunchstat/crunchstat_test.go

index 29a9cdce84ef2427e72c5f94549223d4c303f2d8..e35e98aa59dedba5848d2a6cc1013fd322c15f09 100644 (file)
@@ -45,7 +45,7 @@ func CopyPipeToChan(in io.ReadCloser, out chan string, done chan<- bool) {
                out <- s.Text()
        }
        if s.Err() != nil {
-               out <- fmt.Sprintf("CopyPipeToChan: %s", s.Err())
+               out <- fmt.Sprintf("crunchstat: line buffering error: %s", s.Err())
        }
        done <- true
 }
index 70caf26430ba6cb064a2e88c20a3f02af169cbb8..e3c3a597eacb640557e0e9fdd789a017ab35a8c8 100644 (file)
@@ -66,13 +66,12 @@ func TestCopyPipeToChanLongLines(t *testing.T) {
                        long_line[i] = byte('x')
                }
                pipeOut.Write(long_line)
-               pipeOut.Close()
        }()
 
        // Expect error message from logChan.
 
        errmsg := <-logChan
-       if matched, err := regexp.MatchString("^CopyPipeToChan:.*token too long", errmsg); err != nil || !matched {
+       if matched, err := regexp.MatchString("^crunchstat: line buffering error:.*token too long", errmsg); err != nil || !matched {
                t.Fatalf("expected CopyPipeToChan error, got %s", errmsg)
        }