github.com/pachyderm/pachyderm@v1.13.4/etc/testing/spout/main.go (about) 1 package main 2 3 import ( 4 "archive/tar" 5 "fmt" 6 "os" 7 "strings" 8 "time" 9 ) 10 11 func main() { 12 // test is just to rapidly open and close the pipe to make sure the spout handles this situation well 13 for x := 0; x < 1000; x++ { 14 if err := func() error { 15 16 // Open the /pfs/out pipe with write only permissons (the pachyderm spout will be reading at the other end of this) 17 // Note: it won't work if you try to open this with read, or read/write permissions 18 out, err := os.OpenFile("/pfs/out", os.O_WRONLY, 0644) 19 if err != nil { 20 panic(err) 21 } 22 defer out.Close() 23 24 tw := tar.NewWriter(out) 25 defer tw.Close() 26 27 name := fmt.Sprintf("test%v", x) 28 // write the header 29 for err = tw.WriteHeader(&tar.Header{ 30 Name: name, 31 Mode: 0600, 32 Size: int64(len(name)), 33 }); err != nil; { 34 if !strings.Contains(err.Error(), "broken pipe") { 35 return err 36 } 37 // if there's a broken pipe, just give it some time to get ready for the next message 38 time.Sleep(5 * time.Millisecond) 39 } 40 // and the message 41 for _, err = tw.Write([]byte(name)); err != nil; { 42 if !strings.Contains(err.Error(), "broken pipe") { 43 return err 44 } 45 // if there's a broken pipe, just give it some time to get ready for the next message 46 time.Sleep(5 * time.Millisecond) 47 } 48 return nil 49 }(); err != nil { 50 panic(err) 51 } 52 } 53 }