loggertesthelper.TestLoggerSink.Clear() fakeMetricSender = fake.NewFakeMetricSender() metricBatcher := metricbatcher.New(fakeMetricSender, time.Millisecond) metrics.Initialize(fakeMetricSender, metricBatcher) go func() { reader.Start() close(readerStopped) }() expectedLog := fmt.Sprintf("Listening on port %s", address) Eventually(loggertesthelper.TestLoggerSink.LogContents).Should(ContainSubstring(expectedLog)) }) AfterEach(func() { reader.Stop() <-readerStopped }) It("sends data recieved on UDP socket to its writer", func() { expectedData := "Some Data" otherData := "More stuff" connection, err := net.Dial("udp", address) _, err = connection.Write([]byte(expectedData)) Expect(err).NotTo(HaveOccurred()) Eventually(writer.Data).Should(HaveLen(1)) data := string(writer.Data()[0]) Expect(data).To(Equal(expectedData))
var ( writer *fakeWriter dropsondeReader *networkreader.NetworkReader ) BeforeEach(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()) }) Context("LinuxFileDescriptor", func() { It("sends open file descriptor metrics", func() { defer dropsondeReader.Stop() go dropsondeReader.Start() Eventually(func() uint64 { return atomic.LoadUint64(&writer.openFileDescriptors) }, 3).Should(BeNumerically("~", 15, 3)) }) }) })