Example #1
0
var _ = bdd.Describe("limiter", func() {
	bdd.BeforeEach(func() {
		reset.Enable()

		timeth.Install()
	})

	bdd.AfterEach(func() {
		reset.Disable()
	})

	bdd.XIt("Accept one", func() {
		l := NewLimiter(1, 10*time.Second)
		assert.True(t(), l.Accept())

		timeth.Tick(time.Second)
		assert.False(t(), l.Accept())

		timeth.Tick(9*time.Second + time.Millisecond)
		assert.True(t(), l.Accept())
	})

	bdd.It("Accept two", func() {
		l := NewLimiter(2, 10*time.Second)
		assert.True(t(), l.Accept())
		assert.True(t(), l.Accept())

		timeth.Tick(time.Second)
		assert.False(t(), l.Accept())

		timeth.Tick(9*time.Second + time.Millisecond)
		assert.True(t(), l.Accept())
Example #2
0
		g.XIt("should handle many UDP senders (by continuing to drop all packets on the floor)", func() {
			g.By("Idling the service")
			_, err := oc.Run("idle").Args("--resource-names-file", idlingFile).Output()
			o.Expect(err).ToNot(o.HaveOccurred())

			g.By("Waiting for the pods to have terminated")
			err = waitForNoPodsAvailable(oc)
			o.Expect(err).ToNot(o.HaveOccurred())

			g.By("Connecting to the service IP many times and checking the echo")
			serviceName := resources["service"][0]
			svc, err := oc.KubeREST().Services(oc.Namespace()).Get(serviceName)
			o.Expect(err).ToNot(o.HaveOccurred())

			connectionsToStart := 100
			errors := make([]error, connectionsToStart)
			var connWG sync.WaitGroup
			// spawn many connectors
			for i := 0; i < connectionsToStart; i++ {
				connWG.Add(1)
				go func(ind int) {
					defer g.GinkgoRecover()
					defer connWG.Done()
					err = tryEchoUDP(svc)
					errors[ind] = err
				}(i)
			}

			connWG.Wait()

			// all of the echoers should eventually succeed
			errCount := 0
			for _, err := range errors {
				if err != nil {
					errCount++
				}
			}
			o.Expect(errCount).To(o.Equal(0))

			g.By("Waiting until we have endpoints")
			err = waitForEndpointsAvailable(oc, serviceName)
			o.Expect(err).ToNot(o.HaveOccurred())

			endpoints, err := oc.KubeREST().Endpoints(oc.Namespace()).Get(serviceName)
			o.Expect(err).ToNot(o.HaveOccurred())

			g.By("Making sure the endpoints are no longer marked as idled")
			o.Expect(endpoints.Annotations).NotTo(o.HaveKey(unidlingapi.IdledAtAnnotation))
			o.Expect(endpoints.Annotations).NotTo(o.HaveKey(unidlingapi.UnidleTargetAnnotation))
		})