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

Function TestCloseTwice

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

Source from the content-addressed store, hash-verified

78}
79
80func TestCloseTwice(t *testing.T) {
81 ctx := context.TODO()
82 done := make(chan struct{})
83 go func() {
84 c, err := New(ctx, "sh", "-c", "echo hello; sleep 1; exit 0")
85 assert.NilError(t, err)
86 cmdConn := c.(*commandConn)
87 assert.Check(t, processAlive(cmdConn.cmd.Process.Pid))
88
89 b := make([]byte, 32)
90 n, err := c.Read(b)
91 assert.Check(t, is.Equal(len("hello\n"), n))
92 assert.NilError(t, err)
93
94 err = cmdConn.Close()
95 assert.NilError(t, err)
96 assert.Check(t, !processAlive(cmdConn.cmd.Process.Pid))
97
98 err = cmdConn.Close()
99 assert.NilError(t, err)
100 assert.Check(t, !processAlive(cmdConn.cmd.Process.Pid))
101 done <- struct{}{}
102 }()
103
104 select {
105 case <-time.After(10 * time.Second):
106 t.Error("test did not finish in time")
107 case <-done:
108 break
109 }
110}
111
112func TestEOFTimeout(t *testing.T) {
113 ctx := context.TODO()

Callers

nothing calls this directly

Calls 5

processAliveFunction · 0.85
NewFunction · 0.70
ReadMethod · 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…