1 // Copyright 2015 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // +build darwin dragonfly freebsd linux netbsd openbsd
25 func TestFifoEOF(t *testing.T) {
28 t.Skip("skipping on Android; mkfifo syscall not available")
30 // On OpenBSD 6.2 this test just hangs for some reason.
31 t.Skip("skipping on OpenBSD; issue 25877")
34 dir, err := ioutil.TempDir("", "TestFifoEOF")
38 defer os.RemoveAll(dir)
40 fifoName := filepath.Join(dir, "fifo")
41 if err := syscall.Mkfifo(fifoName, 0600); err != nil {
50 w, err := os.OpenFile(fifoName, os.O_WRONLY, 0)
57 if err := w.Close(); err != nil {
58 t.Errorf("error closing writer: %v", err)
62 for i := 0; i < 3; i++ {
63 time.Sleep(10 * time.Millisecond)
64 _, err := fmt.Fprintf(w, "line %d\n", i)
66 t.Errorf("error writing to fifo: %v", err)
70 time.Sleep(10 * time.Millisecond)
75 r, err := os.Open(fifoName)
80 done := make(chan bool)
85 if err := r.Close(); err != nil {
86 t.Errorf("error closing reader: %v", err)
90 rbuf := bufio.NewReader(r)
92 b, err := rbuf.ReadBytes('\n')
100 t.Logf("%s\n", bytes.TrimSpace(b))
107 case <-time.After(time.Second):
108 t.Error("timed out waiting for read")
109 // Close the reader to force the read to complete.