Exemplo n.º 1
0
var _ = Describe("EndpointIterator", func() {
	var pool *route.Pool

	BeforeEach(func() {
		pool = route.NewPool(2*time.Minute, "")
	})

	Describe("Next", func() {
		It("performs round-robin through the endpoints", func() {
			e1 := route.NewEndpoint("", "1.2.3.4", 5678, "", nil, -1, "")
			e2 := route.NewEndpoint("", "5.6.7.8", 1234, "", nil, -1, "")
			e3 := route.NewEndpoint("", "1.2.7.8", 1234, "", nil, -1, "")
			endpoints := []*route.Endpoint{e1, e2, e3}

			for _, e := range endpoints {
				pool.Put(e)
			}

			counts := make([]int, len(endpoints))

			iter := pool.Endpoints("")

			loops := 50
			for i := 0; i < len(endpoints)*loops; i += 1 {
				n := iter.Next()
				for j, e := range endpoints {
					if e == n {
						counts[j]++
						break
					}
				}
Exemplo n.º 2
0
)

var _ = Describe("Pool", func() {
	var pool *route.Pool
	var modTag models.ModificationTag

	BeforeEach(func() {
		pool = route.NewPool(2*time.Minute, "")
		modTag = models.ModificationTag{}
	})

	Context("Put", func() {
		It("adds endpoints", func() {
			endpoint := &route.Endpoint{}

			b := pool.Put(endpoint)
			Expect(b).To(BeTrue())
		})

		It("handles duplicate endpoints", func() {
			endpoint := &route.Endpoint{}

			pool.Put(endpoint)
			b := pool.Put(endpoint)
			Expect(b).To(BeFalse())
		})

		It("handles equivalent (duplicate) endpoints", func() {
			endpoint1 := route.NewEndpoint("", "1.2.3.4", 5678, "", nil, -1, "", modTag)
			endpoint2 := route.NewEndpoint("", "1.2.3.4", 5678, "", nil, -1, "", modTag)