MCPcopy Index your code
hub / github.com/coder/coder / Test_Start_cancel_context

Function Test_Start_cancel_context

pty/start_test.go:115–141  ·  view source on GitHub ↗

Test_Start_cancel_context tests that we can cancel the command context and kill the process.

(t *testing.T)

Source from the content-addressed store, hash-verified

113
114// Test_Start_cancel_context tests that we can cancel the command context and kill the process.
115func Test_Start_cancel_context(t *testing.T) {
116 t.Parallel()
117
118 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitMedium)
119 defer cancel()
120 cmdCtx, cmdCancel := context.WithCancel(ctx)
121
122 pc, cmd, err := pty.Start(pty.CommandContext(cmdCtx, cmdSleep, argSleep...))
123 require.NoError(t, err)
124 defer func() {
125 _ = pc.Close()
126 }()
127 cmdCancel()
128
129 cmdDone := make(chan struct{})
130 go func() {
131 defer close(cmdDone)
132 _ = cmd.Wait()
133 }()
134
135 select {
136 case <-cmdDone:
137 // OK!
138 case <-ctx.Done():
139 t.Error("cmd.Wait() timed out")
140 }
141}

Callers

nothing calls this directly

Calls 7

StartFunction · 0.92
CommandContextFunction · 0.92
CloseMethod · 0.65
WaitMethod · 0.65
cmdCancelFunction · 0.50
DoneMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected