github.com/pf-qiu/concourse/v6@v6.7.3-0.20201207032516-1f455d73275f/atc/worker/gclient/client_stream_timeout_test.go (about) 1 package gclient_test 2 3 import ( 4 "context" 5 "net/http" 6 "time" 7 8 "code.cloudfoundry.org/garden" 9 "code.cloudfoundry.org/lager" 10 "github.com/pf-qiu/concourse/v6/atc/worker/gclient" 11 "github.com/pf-qiu/concourse/v6/atc/worker/transport/transportfakes" 12 "github.com/concourse/retryhttp" 13 . "github.com/onsi/ginkgo" 14 . "github.com/onsi/gomega" 15 "github.com/onsi/gomega/ghttp" 16 ) 17 18 var _ = Describe("stream http client", func() { 19 var ( 20 gServer *ghttp.Server 21 ctx context.Context 22 cancelFunc context.CancelFunc 23 ) 24 25 BeforeEach(func() { 26 gServer = ghttp.NewServer() 27 ctx, cancelFunc = context.WithCancel(context.Background()) 28 }) 29 30 AfterEach(func() { 31 cancelFunc() 32 gServer.Close() 33 }) 34 35 Context("blocking forever", func() { 36 BeforeEach(func() { 37 gServer.Reset() 38 gServer.AppendHandlers(func(w http.ResponseWriter, r *http.Request) { 39 <-ctx.Done() 40 }) 41 }) 42 43 It("fails once context expires", func() { 44 fakeTransport := new(transportfakes.FakeTransportDB) 45 fakeLogger := lager.NewLogger("test") 46 hostname := new(string) 47 *hostname = gServer.Addr() 48 49 clientFactory := gclient.NewGardenClientFactory( 50 fakeTransport, 51 fakeLogger, 52 "wont-talk-to-you", 53 hostname, 54 retryhttp.NewExponentialBackOffFactory(1*time.Second), 55 1*time.Second, 56 ) 57 58 client := clientFactory.NewClient() 59 _, err := client.Create(garden.ContainerSpec{}) 60 Expect(err).To(HaveOccurred()) 61 Expect(err.Error()).To(ContainSubstring("Client.Timeout")) 62 }) 63 }) 64 })