func NewRouter(logger lager.Logger, cfg *config.Config, p proxy.Proxy, mbusClient *nats.Conn, r *registry.RouteRegistry, v varz.Varz, logCounter *schema.LogCounter, errChan chan error) (*Router, error) { var host string if cfg.Status.Port != 0 { host = fmt.Sprintf("%s:%d", cfg.Ip, cfg.Status.Port) } varz := &health.Varz{ UniqueVarz: v, GenericVarz: health.GenericVarz{ Type: "Router", Index: cfg.Index, Host: host, Credentials: []string{cfg.Status.User, cfg.Status.Pass}, LogCounts: logCounter, }, } healthz := &health.Healthz{} component := &common.VcapComponent{ Config: cfg, Varz: varz, Healthz: healthz, InfoRoutes: map[string]json.Marshaler{ "/routes": r, }, Logger: logger, } routerErrChan := errChan if routerErrChan == nil { routerErrChan = make(chan error, 2) } router := &Router{ config: cfg, proxy: p, mbusClient: mbusClient, registry: r, varz: v, component: component, serveDone: make(chan struct{}), tlsServeDone: make(chan struct{}), idleConns: make(map[net.Conn]struct{}), activeConns: make(map[net.Conn]struct{}), logger: logger, errChan: routerErrChan, stopping: false, } if err := router.component.Start(); err != nil { return nil, err } router.uptimeMonitor = monitor.NewUptime(emitInterval) return router, nil }
. "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) const ( interval = 100 * time.Millisecond ) var _ = Describe("Uptime", func() { var ( uptime *monitor.Uptime ) BeforeEach(func() { fakeEventEmitter.Reset() uptime = monitor.NewUptime(interval) go uptime.Start() }) Context("stops automatically", func() { AfterEach(func() { uptime.Stop() }) It("returns a value metric containing uptime after specified time", func() { Eventually(fakeEventEmitter.GetMessages).Should(HaveLen(1)) metric := fakeEventEmitter.GetMessages()[0].Event.(*events.ValueMetric) Expect(metric.Name).To(Equal(proto.String("uptime"))) Expect(metric.Unit).To(Equal(proto.String("seconds")))