<commit_before>package gateway_test

import (
	"errors"
	"fmt"
	"net/http"
	"net/http/httptest"

	"code.cloudfoundry.org/lager/lagertest"
	"github.com/apihub/apihub/gateway"
	"github.com/apihub/apihub/gateway/gatewayfakes"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Gateway", func() {
	var (
		port                    string
		gw                      *gateway.Gateway
		logger                  *lagertest.TestLogger
		fakeReverseProxyCreator *gatewayfakes.FakeReverseProxyCreator
		fakeReverseProxy        *gatewayfakes.FakeReverseProxy
	)

	BeforeEach(func() {
		logger = lagertest.NewTestLogger("test-gateway")
		port = fmt.Sprintf(":909%d", GinkgoParallelNode())
		fakeReverseProxyCreator = new(gatewayfakes.FakeReverseProxyCreator)
		fakeReverseProxy = new(gatewayfakes.FakeReverseProxy)

		gw = gateway.New(port, fakeReverseProxyCreator)
	})

	var spec gateway.ReverseProxySpec

	BeforeEach(func() {
		spec = gateway.ReverseProxySpec{
			Host:     "my-host.apihub.dev",
			Backends: []string{},
		}

		fakeReverseProxyCreator.CreateReturns(fakeReverseProxy, nil)
	})

	Describe("Stop", func() {
		var (
			client *http.Client
		)

		BeforeEach(func() {
			go gw.Start(logger)
			client = &http.Client{}
		})

		It("stops accepting new connections", func() {
			_, err := http.Get(fmt.Sprintf("http://localhost%s", port))
			Expect(err).NotTo(HaveOccurred())

			Expect(gw.Stop()).To(BeTrue())

			_, err = http.Get(fmt.Sprintf("http://localhost%s", port))
			Expect(err).To(HaveOccurred())
		})

		It("does not stop twice", func() {
			Expect(gw.Stop()).To(BeTrue())
			Expect(gw.Stop()).To(BeFalse())
		})<commit_msg>Eventually stops accepting new connections<commit_after>package gateway_test

import (
	"errors"
	"fmt"
	"net/http"
	"net/http/httptest"

	"code.cloudfoundry.org/lager/lagertest"
	"github.com/apihub/apihub/gateway"
	"github.com/apihub/apihub/gateway/gatewayfakes"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Gateway", func() {
	var (
		port                    string
		gw                      *gateway.Gateway
		logger                  *lagertest.TestLogger
		fakeReverseProxyCreator *gatewayfakes.FakeReverseProxyCreator
		fakeReverseProxy        *gatewayfakes.FakeReverseProxy
	)

	BeforeEach(func() {
		logger = lagertest.NewTestLogger("test-gateway")
		port = fmt.Sprintf(":909%d", GinkgoParallelNode())
		fakeReverseProxyCreator = new(gatewayfakes.FakeReverseProxyCreator)
		fakeReverseProxy = new(gatewayfakes.FakeReverseProxy)

		gw = gateway.New(port, fakeReverseProxyCreator)
	})

	var spec gateway.ReverseProxySpec

	BeforeEach(func() {
		spec = gateway.ReverseProxySpec{
			Host:     "my-host.apihub.dev",
			Backends: []string{},
		}

		fakeReverseProxyCreator.CreateReturns(fakeReverseProxy, nil)
	})

	Describe("Stop", func() {
		var (
			client *http.Client
		)

		BeforeEach(func() {
			go gw.Start(logger)
			client = &http.Client{}
		})

		It("stops accepting new connections", func() {
			Eventually(func() error {
				_, err := http.Get(fmt.Sprintf("http://localhost%s", port))
				return err
			}).ShouldNot(HaveOccurred())

			Expect(gw.Stop()).To(BeTrue())

			Eventually(func() error {
				_, err := http.Get(fmt.Sprintf("http://localhost%s", port))
				return err
			}).Should(HaveOccurred())
		})

		It("does not stop twice", func() {
			Expect(gw.Stop()).To(BeTrue())
			Expect(gw.Stop()).To(BeFalse())
		})
{'fraction_non_alphanumeric': 0.14748831775700935, 'fraction_numerical': 0.0017523364485981308, 'mean_word_length': 3.6725784447476126, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7212867', 'n_tokens_mistral': 1378, 'n_tokens_neox': 1220, 'n_words': 176}