func (s *RouterSuite) TestRouterTerminatesLongRequests(c *C) { app := test.NewSlowApp( []route.Uri{"slow-app.vcap.me"}, s.Config.Port, s.mbusClient, 10*time.Second, ) app.Listen() uri := fmt.Sprintf("http://slow-app.vcap.me:%d", s.Config.Port) resp, err := http.Get(uri) c.Assert(err, IsNil) c.Assert(resp.StatusCode, Equals, 502) }
// make third request without errors // even though initial idle timeout was exceeded because // it will have been reset resp, err = client.Do(req) Expect(err).ToNot(HaveOccurred()) Expect(resp).ToNot(BeNil()) resp.Body.Close() Expect(resp.StatusCode).To(Equal(http.StatusOK)) }) It("removes the idle timeout during an active connection", func() { // create an app that takes 3/4 of the deadline to respond // during an active connection app := test.NewSlowApp( []route.Uri{"keepalive.vcap.me"}, config.Port, mbusClient, config.EndpointTimeout/4*3, ) app.Listen() Eventually(func() bool { return appRegistered(registry, app) }).Should(BeTrue()) host := fmt.Sprintf("keepalive.vcap.me:%d", config.Port) uri := fmt.Sprintf("http://%s", host) conn, err := net.Dial("tcp", host) Expect(err).ToNot(HaveOccurred()) client := httputil.NewClientConn(conn, nil) req, _ := http.NewRequest("GET", uri, nil)
Ω(err).ShouldNot(HaveOccurred()) Ω(resp).ShouldNot(BeNil()) Ω(resp.StatusCode).To(Equal(200)) body, err := ioutil.ReadAll(resp.Body) defer resp.Body.Close() Ω(err).ShouldNot(HaveOccurred()) Ω(string(body)).Should(MatchRegexp(".*1\\.2\\.3\\.4:1234.*\n")) }) Context("long requests", func() { Context("http", func() { BeforeEach(func() { app := test.NewSlowApp( []route.Uri{"slow-app.vcap.me"}, config.Port, mbusClient, 1*time.Second, ) app.Listen() }) It("terminates before receiving headers", func() { uri := fmt.Sprintf("http://slow-app.vcap.me:%d", config.Port) req, _ := http.NewRequest("GET", uri, nil) client := http.Client{} resp, err := client.Do(req) Ω(err).ShouldNot(HaveOccurred()) Ω(resp).ShouldNot(BeNil()) Ω(resp.StatusCode).To(Equal(http.StatusBadGateway)) defer resp.Body.Close()