예제 #1
0
var _ = Describe("AgentListener", func() {
	var listener agentlistener.Listener
	var dataChannel <-chan []byte
	var listenerStopped chan struct{}
	var address string

	BeforeEach(func() {
		listenerStopped = make(chan struct{})
		loggertesthelper.TestLoggerSink.Clear()

		port := 3456 + config.GinkgoConfig.ParallelNode
		address = net.JoinHostPort("127.0.0.1", strconv.Itoa(port))
		listener, dataChannel = agentlistener.NewAgentListener(address, loggertesthelper.Logger(), "agentListener")
		go func() {
			listener.Start()
			close(listenerStopped)
		}()

		Eventually(loggertesthelper.TestLoggerSink.LogContents).Should(ContainSubstring("Listening on port " + address))
	})

	AfterEach(func() {
		listener.Stop()
		Eventually(listenerStopped).Should(BeClosed())
	})

	Context("with a listner running", func() {
		It("listens to the socket and forwards log lines", func() {
			expectedData := "Some Data"
			otherData := "More stuff"
	"github.com/gogo/protobuf/proto"
	"github.com/nu7hatch/gouuid"
)

const address = "127.0.0.1:4567"

var _ = Describe("Tcplistener", func() {

	Context("dropsonde metric emission", func() {
		var envelopeChan chan *events.Envelope
		var tlsListener agentlistener.Listener

		BeforeEach(func() {
			envelopeChan = make(chan *events.Envelope)
			tlsListener = tlslistener.New(address, config, envelopeChan, loggertesthelper.Logger())
			go tlsListener.Start()
		})

		AfterEach(func() {
			tlsListener.Stop()
		})

		It("sends all types of messages as a gob", func() {
			for name, eventType := range events.Envelope_EventType_value {
				envelope := createEnvelope(events.Envelope_EventType(eventType))
				conn := openTLSConnection()

				err := writeGob(conn, envelope)
				Expect(err).ToNot(HaveOccurred())

				Eventually(envelopeChan).Should(Receive(Equal(envelope)), fmt.Sprintf("did not receive expected event: %s", name))