From 9b4999c0cf0cd74ce45a9db2604405d7cbfa6796 Mon Sep 17 00:00:00 2001 From: Jimmy Zelinskie Date: Wed, 25 Feb 2015 21:56:58 -0500 Subject: [PATCH] stats/udp: nop on nil DefaultStats --- stats/stats.go | 12 +++++++++--- udp/udp_test.go | 17 +++++++---------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/stats/stats.go b/stats/stats.go index c94b43c..abe366c 100644 --- a/stats/stats.go +++ b/stats/stats.go @@ -271,15 +271,21 @@ func (s *Stats) handlePeerEvent(ps *PeerStats, event int) { // RecordEvent broadcasts an event to the default stats queue. func RecordEvent(event int) { - DefaultStats.RecordEvent(event) + if DefaultStats != nil { + DefaultStats.RecordEvent(event) + } } // RecordPeerEvent broadcasts a peer event to the default stats queue. func RecordPeerEvent(event int, ipv6 bool) { - DefaultStats.RecordPeerEvent(event, ipv6) + if DefaultStats != nil { + DefaultStats.RecordPeerEvent(event, ipv6) + } } // RecordTiming broadcasts a timing event to the default stats queue. func RecordTiming(event int, duration time.Duration) { - DefaultStats.RecordTiming(event, duration) + if DefaultStats != nil { + DefaultStats.RecordTiming(event, duration) + } } diff --git a/udp/udp_test.go b/udp/udp_test.go index 8a6441f..463f010 100644 --- a/udp/udp_test.go +++ b/udp/udp_test.go @@ -13,21 +13,18 @@ import ( "time" "github.com/chihaya/chihaya/config" - "github.com/chihaya/chihaya/stats" "github.com/chihaya/chihaya/tracker" _ "github.com/chihaya/chihaya/backend/noop" ) -var testPort = "34137" -var connectAction = []byte{0, 0, 0, byte(connectActionID)} -var announceAction = []byte{0, 0, 0, byte(announceActionID)} -var scrapeAction = []byte{0, 0, 0, byte(scrapeActionID)} -var errorAction = []byte{0, 0, 0, byte(errorActionID)} - -func init() { - stats.DefaultStats = stats.New(config.StatsConfig{}) -} +var ( + testPort = "34137" + connectAction = []byte{0, 0, 0, byte(connectActionID)} + announceAction = []byte{0, 0, 0, byte(announceActionID)} + scrapeAction = []byte{0, 0, 0, byte(scrapeActionID)} + errorAction = []byte{0, 0, 0, byte(errorActionID)} +) func setupTracker(cfg *config.Config) (*Server, chan struct{}, error) { tkr, err := tracker.New(cfg)