Ejemplo n.º 1
0
		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"

			connection, err := net.Dial("udp", address)

			_, err = connection.Write([]byte(expectedData))
			Expect(err).To(BeNil())

			var received []byte
			Eventually(dataChannel).Should(Receive(&received))
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))
				conn.Close()
			}
		})