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)