MCPcopy Create free account
hub / github.com/docker/cli / TestEOFTimeout

Function TestEOFTimeout

cli/connhelper/commandconn/commandconn_unix_test.go:112–139  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

110}
111
112func TestEOFTimeout(t *testing.T) {
113 ctx := context.TODO()
114 done := make(chan struct{})
115 go func() {
116 c, err := New(ctx, "sh", "-c", "sleep 20")
117 assert.NilError(t, err)
118 cmdConn := c.(*commandConn)
119 assert.Check(t, processAlive(cmdConn.cmd.Process.Pid))
120
121 cmdConn.stdout = mockStdoutEOF{}
122
123 b := make([]byte, 32)
124 n, err := c.Read(b)
125 assert.Check(t, is.Equal(0, n))
126 assert.ErrorContains(t, err, "did not exit after EOF")
127
128 done <- struct{}{}
129 }()
130
131 // after receiving an EOF, we try to kill the command
132 // if it doesn't exit after 10s, we throw an error
133 select {
134 case <-time.After(12 * time.Second):
135 t.Error("test did not finish in time")
136 case <-done:
137 break
138 }
139}
140
141type mockStdoutEOF struct{}
142

Callers

nothing calls this directly

Calls 4

processAliveFunction · 0.85
NewFunction · 0.70
ReadMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…