"net/http"
	"os"
	"sync"
)

// these tests need to be invoked individually from an external script,
// since environment variables need to be set/unset before starting the tests
var _ = Describe("Autowire End-to-End", func() {
	Context("with DROPSONDE_ORIGIN set", func() {
		var oldEnv string

		BeforeEach(func() {
			oldEnv = os.Getenv("DROPSONDE_ORIGIN")
			os.Setenv("DROPSONDE_ORIGIN", "test-origin")
			emitter, _ := autowire.CreateDefaultEmitter()
			autowire.Initialize(emitter)
			metrics.Initialize(metric_sender.NewMetricSender(autowire.AutowiredEmitter()))
		})

		AfterEach(func() {
			os.Setenv("DROPSONDE_ORIGIN", oldEnv)
		})

		It("emits HTTP client/server events and heartbeats", func() {
			udpListener, err := net.ListenPacket("udp4", ":3457")
			Expect(err).ToNot(HaveOccurred())
			defer udpListener.Close()
			udpDataChan := make(chan []byte, 16)

			receivedEvents := make(map[string]bool)
			lock := sync.RWMutex{}
Example #2
0
	var oldOrigin string

	BeforeEach(func() {
		oldDestination = os.Getenv("DROPSONDE_DESTINATION")
		oldOrigin = os.Getenv("DROPSONDE_ORIGIN")
	})

	AfterEach(func() {
		os.Setenv("DROPSONDE_DESTINATION", oldDestination)
		os.Setenv("DROPSONDE_ORIGIN", oldOrigin)
	})

	Describe("Initialize", func() {
		Context("with a non-nil emitter", func() {
			It("instruments the HTTP default transport", func() {
				autowire.Initialize(emitter.NewEventEmitter(nil, ""))
				Expect(reflect.TypeOf(http.DefaultTransport).Elem().Name()).ToNot(Equal("Transport"))
			})
		})

		Context("with a nil-emitter", func() {
			It("resets the HTTP default transport to not be instrumented", func() {
				autowire.Initialize(nil)
				Expect(reflect.TypeOf(http.DefaultTransport).Elem().Name()).To(Equal("Transport"))
			})
		})
	})

	Describe("CreateDefaultEmitter", func() {
		Context("with DROPSONDE_ORIGIN set", func() {
			BeforeEach(func() {
	"net"
	"net/http"
	"os"
	"sync"
)

// these tests need to be invoked individually from an external script,
// since environment variables need to be set/unset before starting the tests
var _ = Describe("Autowire End-to-End", func() {
	Context("with DROPSONDE_ORIGIN set", func() {
		var oldEnv string

		BeforeEach(func() {
			oldEnv = os.Getenv("DROPSONDE_ORIGIN")
			os.Setenv("DROPSONDE_ORIGIN", "test-origin")
			autowire.Initialize()
			metrics.Initialize(metric_sender.NewMetricSender(autowire.AutowiredEmitter()))
		})

		AfterEach(func() {
			os.Setenv("DROPSONDE_ORIGIN", oldEnv)
		})

		It("emits HTTP client/server events and heartbeats", func() {
			udpListener, err := net.ListenPacket("udp4", ":3457")
			Expect(err).ToNot(HaveOccurred())
			defer udpListener.Close()
			udpDataChan := make(chan []byte, 16)

			receivedEvents := make(map[string]bool)
			lock := sync.RWMutex{}