var answer string Eventually(done).Should(Receive(&answer)) Expect(answer).To(Equal("https")) conn.ReadResponse() }) It("emits HTTP startstop events", func() { ln := registerHandlerWithInstanceId(r, "app", "", func(conn *test_util.HttpConn) { }, "fake-instance-id") defer ln.Close() conn := dialProxy(proxyServer) fakeEmitter := fake.NewFakeEventEmitter("fake") dropsonde.InitializeWithEmitter(fakeEmitter) req := test_util.NewRequest("GET", "app", "/", nil) requestId, err := uuid.NewV4() Expect(err).NotTo(HaveOccurred()) req.Header.Set("X-Vcap-Request-Id", requestId.String()) conn.WriteRequest(req) findStartStopEvent := func() *events.HttpStartStop { for _, event := range fakeEmitter.GetEvents() { startStopEvent, ok := event.(*events.HttpStartStop) if ok { return startStopEvent } }
"github.com/cloudfoundry/sonde-go/events" uuid "github.com/nu7hatch/gouuid" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) var _ = Describe("InstrumentedHandler", func() { var fakeEmitter *fake.FakeEventEmitter var h http.Handler var req *http.Request var origin = "testHandler/41" BeforeEach(func() { fakeEmitter = fake.NewFakeEventEmitter(origin) var err error fh := fakeHandler{} h = instrumented_handler.InstrumentedHandler(fh, fakeEmitter) req, err = http.NewRequest("GET", "http://foo.example.com/", nil) Expect(err).ToNot(HaveOccurred()) req.RemoteAddr = "127.0.0.1" req.Header.Set("User-Agent", "our-testing-client") }) AfterEach(func() { instrumented_handler.GenerateUuid = uuid.NewV4 }) Describe("request ID", func() {
. "github.com/onsi/gomega" "time" ) var ( fakeEventEmitter *fake.FakeEventEmitter uptimeMonitor monitor.Monitor ) const ( interval = 100 * time.Millisecond ) var _ = Describe("UptimeMonitor", func() { BeforeEach(func() { fakeEventEmitter = fake.NewFakeEventEmitter("MonitorTest") sender := metric_sender.NewMetricSender(fakeEventEmitter) batcher := metricbatcher.New(sender, 100*time.Millisecond) metrics.Initialize(sender, batcher) uptimeMonitor = monitor.NewUptimeMonitor(interval) go uptimeMonitor.Start() }) AfterEach(func() { fakeEventEmitter.Close() }) Context("stops automatically", func() {
readMessage := <-buffer.GetOutputChannel() Expect(readMessage.GetLogMessage().GetMessage()).To(ContainSubstring("message 1")) sendLogMessages("message 2", inMessageChan) readMessage2 := <-buffer.GetOutputChannel() Expect(readMessage2.GetLogMessage().GetMessage()).To(ContainSubstring("message 2")) }) Context("tracking dropped messages", func() { var fakeEventEmitter *fake.FakeEventEmitter BeforeEach(func() { fakeEventEmitter = fake.NewFakeEventEmitter("doppler") sender := metric_sender.NewMetricSender(fakeEventEmitter) batcher := metricbatcher.New(sender, 100*time.Millisecond) metrics.Initialize(sender, batcher) fakeEventEmitter.Reset() }) tracksDroppedMessages := func(delta, total int) { It("logs the dropped messages", func() { logMessageNotification := <-buffer.GetOutputChannel() Expect(logMessageNotification.GetEventType()).To(Equal(events.Envelope_LogMessage)) Expect(logMessageNotification.GetLogMessage().GetMessage()).To(ContainSubstring(fmt.Sprintf("Log message output is too high. %d messages dropped (Total %d messages dropped) to test-sink-name.", delta, total))) counterEventNotification := <-buffer.GetOutputChannel() Expect(counterEventNotification.GetEventType()).To(Equal(events.Envelope_CounterEvent))
"github.com/cloudfoundry/dropsonde/emitter/fake" "github.com/cloudfoundry/sonde-go/events" "github.com/gogo/protobuf/proto" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) var _ = Describe("RuntimeStats", func() { var ( fakeEventEmitter *fake.FakeEventEmitter runtimeStats *runtime_stats.RuntimeStats stopChan, runDone chan struct{} ) BeforeEach(func() { fakeEventEmitter = fake.NewFakeEventEmitter("fake-origin") runtimeStats = runtime_stats.NewRuntimeStats(fakeEventEmitter, 10*time.Millisecond) stopChan = make(chan struct{}) runDone = make(chan struct{}) }) AfterEach(func() { close(stopChan) Eventually(runDone).Should(BeClosed()) }) var perform = func() { go func() { runtimeStats.Run(stopChan) close(runDone) }()
"github.com/cloudfoundry/dropsonde/log_sender" "github.com/cloudfoundry/loggregatorlib/loggertesthelper" "io" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) var _ = Describe("LogSender", func() { var ( emitter *fake.FakeEventEmitter sender log_sender.LogSender ) BeforeEach(func() { emitter = fake.NewFakeEventEmitter("origin") sender = log_sender.NewLogSender(emitter, nil) }) Describe("SendAppLog", func() { It("sends a log message event to its emitter", func() { err := sender.SendAppLog("app-id", "custom-log-message", "App", "0") Expect(err).NotTo(HaveOccurred()) Expect(emitter.Messages).To(HaveLen(1)) log := emitter.Messages[0].Event.(*events.LogMessage) Expect(log.GetMessageType()).To(Equal(events.LogMessage_OUT)) Expect(log.GetMessage()).To(BeEquivalentTo("custom-log-message")) Expect(log.GetAppId()).To(Equal("app-id")) Expect(log.GetSourceType()).To(Equal("App")) Expect(log.GetSourceInstance()).To(Equal("0"))