MCPcopy
hub / github.com/dropbox/godropbox / TestClose

Method TestClose

net2/http2/simple_pool_test.go:282–340  ·  view source on GitHub ↗
(c *C)

Source from the content-addressed store, hash-verified

280}
281
282func (s *SimplePoolSuite) TestClose(c *C) {
283 server, addr := test_utils.SetupTestServer(false)
284 defer server.Close()
285
286 // do single request
287 params := ConnectionParams{
288 MaxIdle: 1,
289 }
290 pool := NewSimplePool(addr, params)
291 pool.closeWait = 100 * time.Millisecond
292
293 // do 10 requests concurrently
294 origMaxProcs := runtime.GOMAXPROCS(runtime.NumCPU())
295 defer func() { runtime.GOMAXPROCS(origMaxProcs) }()
296
297 const count = 10
298 finished := make(chan bool)
299 for i := 0; i < count; i++ {
300 go func() {
301 req, err := http.NewRequest("GET", "/", nil)
302 c.Assert(err, IsNil)
303
304 _, err = pool.Do(req)
305 c.Assert(err, IsNil)
306 finished <- true
307 }()
308 }
309
310 for i := 0; i < count; i++ {
311 select {
312 case <-finished:
313 // cool
314
315 case <-time.After(5 * time.Second):
316 c.FailNow()
317 }
318 }
319
320 c.Assert(pool.conns.NumAlive() > 0, IsTrue)
321
322 pool.Close()
323
324 failCount := 0
325 for ; failCount < 100; failCount++ {
326 time.Sleep(10 * time.Millisecond)
327 if pool.conns.NumAlive() == 0 {
328 break
329 }
330 }
331
332 c.Assert(failCount < 100, IsTrue)
333
334 req, err := http.NewRequest("GET", "/connection_refused", nil)
335 c.Assert(err, IsNil)
336 _, err = pool.Do(req)
337 c.Assert(err, NotNil)
338 _, ok := err.(DialError)
339 c.Assert(ok, IsTrue)

Callers

nothing calls this directly

Calls 8

DoMethod · 0.95
CloseMethod · 0.95
SetupTestServerFunction · 0.92
NewSimplePoolFunction · 0.85
NumAliveMethod · 0.80
CloseMethod · 0.65
AfterMethod · 0.65
SleepMethod · 0.65

Tested by

no test coverage detected