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

Function TestCloseRunningCommand

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

Source from the content-addressed store, hash-verified

48}
49
50func TestCloseRunningCommand(t *testing.T) {
51 ctx := context.TODO()
52 done := make(chan struct{})
53 defer close(done)
54
55 go func() {
56 c, err := New(ctx, "sh", "-c", "while true; do sleep 1; done")
57 assert.NilError(t, err)
58 cmdConn := c.(*commandConn)
59 assert.Check(t, processAlive(cmdConn.cmd.Process.Pid))
60
61 n, err := c.Write([]byte("hello"))
62 assert.Check(t, is.Equal(len("hello"), n))
63 assert.NilError(t, err)
64 assert.Check(t, processAlive(cmdConn.cmd.Process.Pid))
65
66 err = cmdConn.Close()
67 assert.NilError(t, err)
68 assert.Check(t, !processAlive(cmdConn.cmd.Process.Pid))
69 done <- struct{}{}
70 }()
71
72 select {
73 case <-time.After(5 * time.Second):
74 t.Error("test did not finish in time")
75 case <-done:
76 break
77 }
78}
79
80func TestCloseTwice(t *testing.T) {
81 ctx := context.TODO()

Callers

nothing calls this directly

Calls 5

processAliveFunction · 0.85
NewFunction · 0.70
WriteMethod · 0.45
CloseMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…