Example #1
0
				A: make(chan int32, 100),
				B: make(chan string, 100),
			}

			invalid = invalidStruct{
				A: make(chan int, 100),
			}
		})

		Context("proper args", func() {
			BeforeEach(func() {
				args = eachers.With(99, "some-arg")
			})

			It("keeps all the channels populated with the given arguments", func() {
				testhelpers.AlwaysReturn(receiver, args...)

				Eventually(receiver.A).Should(HaveLen(cap(receiver.A)))
				Eventually(receiver.B).Should(HaveLen(cap(receiver.B)))
			})

			It("sends the expected argument", func() {
				testhelpers.AlwaysReturn(receiver, args...)

				Eventually(receiver.A).Should(Receive(BeEquivalentTo(args[0])))
				Eventually(receiver.B).Should(Receive(Equal(args[1])))
			})
		})

		DescribeTable("invalid args", func(rx interface{}, args ...interface{}) {
			f := func() {
Example #2
0
	"sync/atomic"

	"github.com/apoydence/eachers/testhelpers"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"

	"github.com/cloudfoundry/loggregatorlib/loggertesthelper"
)

var _ = Describe("Monitor", func() {
	It("sends uptime metrics", func() {
		logger := loggertesthelper.Logger()
		writer := &fakeWriter{}

		mockBatcher := newMockEventBatcher()
		mockChainer := newMockBatchCounterChainer()
		testhelpers.AlwaysReturn(mockBatcher.BatchCounterOutput, mockChainer)
		testhelpers.AlwaysReturn(mockChainer.SetTagOutput, mockChainer)

		var err error
		dropsondeUnmarshaller := eventunmarshaller.New(writer, mockBatcher, logger)
		dropsondeReader, err := networkreader.New("127.0.0.1:37474", "dropsondeAgentListener", dropsondeUnmarshaller, logger)
		Expect(err).NotTo(HaveOccurred())

		go dropsondeReader.Start()
		defer dropsondeReader.Stop()

		Eventually(func() uint64 { return atomic.LoadUint64(&writer.lastUptime) }, 3).Should(BeNumerically(">", 1))
	})
})
		sentLength := len(message) - 3
		client.WriteOutput.SentLength <- sentLength
		client.WriteOutput.Err <- nil

		err := udpWrapper.Write(client, message)
		Expect(err).NotTo(HaveOccurred())
		Eventually(mockBatcher.BatchAddCounterInput).Should(BeCalled(
			With("udp.sentByteCount", uint64(sentLength)),
		))
	})

	It("counts the number of messages sent", func() {
		client.WriteOutput.SentLength <- len(message)
		client.WriteOutput.Err <- nil
		mockChainer := newMockBatchCounterChainer()
		testhelpers.AlwaysReturn(mockChainer.SetTagOutput, mockChainer)

		err := udpWrapper.Write(client, message, mockChainer)
		Expect(err).NotTo(HaveOccurred())
		Eventually(mockBatcher.BatchIncrementCounterInput).Should(BeCalled(
			With("udp.sentMessageCount"),
		))
		Eventually(mockBatcher.BatchIncrementCounterInput).Should(BeCalled(
			With("DopplerForwarder.sentMessages"),
		))
		Eventually(mockChainer.SetTagInput).Should(BeCalled(
			With("protocol", "udp"),
		))
		Eventually(mockChainer.IncrementCalled).Should(BeCalled())
	})