MCPcopy Index your code
hub / github.com/docker/cli / TestRunReadAfterContainerExit

Function TestRunReadAfterContainerExit

e2e/container/run_test.go:219–269  ·  view source on GitHub ↗

Adapted from https://github.com/docker/for-mac/issues/7632#issue-2932169772 Thanks [@almet](https://github.com/almet)!

(t *testing.T)

Source from the content-addressed store, hash-verified

217// Adapted from https://github.com/docker/for-mac/issues/7632#issue-2932169772
218// Thanks [@almet](https://github.com/almet)!
219func TestRunReadAfterContainerExit(t *testing.T) {
220 skip.If(t, environment.RemoteDaemon())
221
222 r := rand.New(rand.NewSource(0x123456))
223
224 const size = 18933764
225 cmd := exec.Command("docker", "run",
226 "--rm", "-i",
227 "alpine",
228 "sh", "-c", "cat -",
229 )
230
231 cmd.Stdin = io.LimitReader(r, size)
232
233 var stderr bytes.Buffer
234 cmd.Stderr = &stderr
235
236 stdout, err := cmd.StdoutPipe()
237 assert.NilError(t, err)
238
239 err = cmd.Start()
240 assert.NilError(t, err)
241
242 buffer := make([]byte, 1000)
243 counter := 0
244 totalRead := 0
245
246 for {
247 n, err := stdout.Read(buffer)
248 if n > 0 {
249 totalRead += n
250 }
251
252 // Wait 0.1s every megabyte (approx.)
253 if counter%1000 == 0 {
254 time.Sleep(100 * time.Millisecond)
255 }
256
257 if err != nil || n == 0 {
258 break
259 }
260
261 counter++
262 }
263
264 err = cmd.Wait()
265 t.Logf("Error: %v", err)
266 t.Logf("Stderr: %s", stderr.String())
267 assert.Check(t, err == nil)
268 assert.Check(t, is.Equal(totalRead, size))
269}

Callers

nothing calls this directly

Calls 3

StringMethod · 0.65
CommandMethod · 0.45
ReadMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…