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

Method TestMaxConnTimeoutFails

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

Source from the content-addressed store, hash-verified

169}
170
171func (s *SimplePoolSuite) TestMaxConnTimeoutFails(c *C) {
172 server, addr := test_utils.SetupTestServer(false)
173 defer server.Close()
174
175 params := ConnectionParams{
176 MaxConns: 2,
177 MaxIdle: 1,
178 ConnectionAcquireTimeout: 1 * time.Second,
179 }
180 pool := NewSimplePool(addr, params)
181 pool.closeWait = 100 * time.Millisecond
182
183 // do 10 requests concurrently
184 origMaxProcs := runtime.GOMAXPROCS(runtime.NumCPU())
185 defer func() { runtime.GOMAXPROCS(origMaxProcs) }()
186
187 tooManyConn := make(chan int)
188
189 const count = 5
190 for i := 0; i < count; i++ {
191 go func() {
192 // /slow_request takes about 500ms. With 5 requests in parallel and 2 connections
193 // we should finish within 1.5 seconds. Since ConnectionAcquireTimeout is 1 second
194 // the last request will fail
195 req, err := http.NewRequest("GET", "/slow_request", nil)
196 c.Assert(err, IsNil)
197
198 _, err = pool.Do(req)
199 if err == nil {
200 tooManyConn <- 0
201 } else {
202 _, ok := err.(DialError)
203 c.Assert(ok, IsTrue)
204 c.Log(err)
205 c.Assert(
206 strings.HasPrefix(
207 err.Error(),
208 "Dial Error: Reached maximum active requests for connection pool"),
209 IsTrue)
210 tooManyConn <- 1
211 }
212 }()
213 }
214
215 tooManyConnCount := 0
216 for i := 0; i < count; i++ {
217 select {
218 case cnt := <-tooManyConn:
219 tooManyConnCount += cnt
220 case <-time.After(5 * time.Second):
221 c.FailNow()
222 }
223 }
224
225 c.Assert(tooManyConnCount, Equals, 1)
226}
227
228func (s *SimplePoolSuite) TestMaxConn(c *C) {

Callers

nothing calls this directly

Calls 6

DoMethod · 0.95
SetupTestServerFunction · 0.92
NewSimplePoolFunction · 0.85
CloseMethod · 0.65
ErrorMethod · 0.65
AfterMethod · 0.65

Tested by

no test coverage detected