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

Function TestConnectAndWait

cli-plugins/socket/socket_test.go:150–216  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

148}
149
150func TestConnectAndWait(t *testing.T) {
151 t.Run("calls cancel func on EOF", func(t *testing.T) {
152 srv, err := NewPluginServer(nil)
153 assert.NilError(t, err, "failed to setup server")
154 defer srv.Close()
155
156 done := make(chan struct{})
157 t.Setenv(EnvKey, srv.Addr().String())
158 cancelFunc := func() {
159 done <- struct{}{}
160 }
161 ConnectAndWait(cancelFunc)
162
163 select {
164 case <-done:
165 t.Fatal("unexpectedly done")
166 default:
167 }
168
169 srv.Close()
170
171 select {
172 case <-done:
173 case <-time.After(10 * time.Millisecond):
174 t.Fatal("cancel function not closed after 10ms")
175 }
176 })
177
178 // TODO: this test cannot be executed with `t.Parallel()`, due to
179 // relying on goroutine numbers to ensure correct behaviour
180 t.Run("connect goroutine exits after EOF", func(t *testing.T) {
181 runtime.LockOSThread()
182 defer runtime.UnlockOSThread()
183 srv, err := NewPluginServer(nil)
184 assert.NilError(t, err, "failed to setup server")
185
186 defer srv.Close()
187
188 t.Setenv(EnvKey, srv.Addr().String())
189
190 runtime.Gosched()
191 numGoroutines := runtime.NumGoroutine()
192
193 ConnectAndWait(func() {})
194
195 runtime.Gosched()
196 poll.WaitOn(t, func(t poll.LogT) poll.Result {
197 // +1 goroutine for the poll.WaitOn
198 // +1 goroutine for the connect goroutine
199 if runtime.NumGoroutine() < numGoroutines+1+1 {
200 return poll.Continue("waiting for connect goroutine to spawn")
201 }
202 return poll.Success()
203 }, poll.WithDelay(1*time.Millisecond), poll.WithTimeout(500*time.Millisecond))
204
205 srv.Close()
206
207 runtime.Gosched()

Callers

nothing calls this directly

Calls 5

CloseMethod · 0.95
AddrMethod · 0.95
NewPluginServerFunction · 0.85
ConnectAndWaitFunction · 0.85
StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…