MCPcopy Index your code
hub / github.com/cloudflare/tableflip / TestFilesAreNonblocking

Function TestFilesAreNonblocking

process_test.go:14–57  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func TestFilesAreNonblocking(t *testing.T) {
15 pipe := func() (r, w *os.File) {
16 r, w, err := os.Pipe()
17 if err != nil {
18 t.Fatal(err)
19 }
20 t.Cleanup(func() {
21 r.Close()
22 w.Close()
23 })
24 return r, w
25 }
26
27 // Set up our own blocking stdin since CI runs tests with stdin closed.
28 rStdin, _ := pipe()
29 rStdin.Fd()
30
31 r, _ := pipe()
32 if !isNonblock(t, r) {
33 t.Fatal("Read pipe is blocking")
34 }
35
36 proc, err := newOSProcess("cat", nil, []*os.File{rStdin, os.Stdout, os.Stderr, r}, nil)
37 if err != nil {
38 t.Fatal(err)
39 }
40
41 if err := proc.Signal(os.Kill); err != nil {
42 t.Fatal("Can't signal:", err)
43 }
44
45 var exitErr *exec.ExitError
46 if err := proc.Wait(); !errors.As(err, &exitErr) {
47 t.Fatalf("Wait should return an ExitError after sending os.Kill, have %T: %s", err, err)
48 }
49
50 if err := proc.Wait(); err == nil {
51 t.Fatal("Waiting a second time should return an error")
52 }
53
54 if !isNonblock(t, r) {
55 t.Fatal("Read pipe is blocking after newOSProcess")
56 }
57}
58
59func TestArgumentsArePassedCorrectly(t *testing.T) {
60 proc, err := newOSProcess("printf", []string{""}, []*os.File{os.Stdin, os.Stdout, os.Stderr}, nil)

Callers

nothing calls this directly

Calls 4

isNonblockFunction · 0.85
newOSProcessFunction · 0.85
SignalMethod · 0.65
WaitMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…