MCPcopy
hub / github.com/github/git-sizer / TestPipelineReadFromSlowly

Function TestPipelineReadFromSlowly

internal/pipe/pipeline_test.go:99–127  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

97}
98
99func TestPipelineReadFromSlowly(t *testing.T) {
100 t.Parallel()
101 ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
102 defer cancel()
103
104 r, w := io.Pipe()
105
106 var buf []byte
107 readErr := make(chan error, 1)
108
109 go func() {
110 time.Sleep(200 * time.Millisecond)
111 var err error
112 buf, err = io.ReadAll(r)
113 readErr <- err
114 }()
115
116 p := pipe.New(pipe.WithStdout(w))
117 p.Add(pipe.Command("echo", "hello world"))
118 assert.NoError(t, p.Run(ctx))
119
120 time.Sleep(100 * time.Millisecond)
121 // It's not super-intuitive, but `w` has to be closed here so that
122 // the `ioutil.ReadAll()` call above knows that it's done:
123 _ = w.Close()
124
125 assert.NoError(t, <-readErr)
126 assert.Equal(t, "hello world\n", string(buf))
127}
128
129func TestPipelineReadFromSlowly2(t *testing.T) {
130 if runtime.GOOS == "windows" {

Callers

nothing calls this directly

Calls 6

NewFunction · 0.92
WithStdoutFunction · 0.92
CommandFunction · 0.92
RunMethod · 0.80
AddMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected