9797 function ( t ) {
9898 var mockLog = {
9999 error : function ( log ) {
100- t . equal ( log . op , 'statsd' )
100+ t . equal ( log . op , 'statsd.increment ' )
101101 t . equal ( log . err . message , 'Failed to send message' )
102102 t . end ( )
103103 }
@@ -122,6 +122,64 @@ test(
122122 }
123123)
124124
125+ test (
126+ 'statsd.timing' ,
127+ function ( t ) {
128+ function StatsDMock ( ) {
129+ return {
130+ socket : { } ,
131+ increment : function ( ) {
132+ t . fail ( 'statsd.increment should not be called' )
133+ t . end ( )
134+ } ,
135+ timing : function ( ) {
136+ t . equal ( arguments . length , 5 , 'statsd.timing received the correct number arguments' )
137+ t . equal ( arguments [ 0 ] , 'fxa.auth.foo.time' , 'statsd.timing received the correct name argument' )
138+ t . equal ( arguments [ 1 ] , 1 , 'statsd.timing received the correct timing argument' )
139+ t . equal ( typeof arguments [ 2 ] , 'number' , 'statsd.timing received the correct timing argument' )
140+ t . equal ( arguments [ 3 ] , undefined , 'statsd.timing received the correct tags argument' )
141+ t . equal ( typeof arguments [ 4 ] , 'function' , 'statsd.timing received the correct callback argument' )
142+ t . end ( )
143+ }
144+ }
145+ }
146+
147+ var statsd = new StatsDCollector ( mockLog )
148+ statsd . init ( )
149+ statsd . client = new StatsDMock ( )
150+ var log = require ( '../../lib/log' ) ( 'info' )
151+ log . statsd = statsd
152+ log . timing ( 'foo' , 1 )
153+ }
154+ )
155+
156+ test (
157+ 'statsd.timing error' ,
158+ function ( t ) {
159+ var mockLog = {
160+ error : function ( log ) {
161+ t . equal ( log . op , 'statsd.timing' )
162+ t . equal ( log . err , 'foo' )
163+ t . end ( )
164+ }
165+ }
166+
167+ function StatsDMock ( ) {
168+ return {
169+ socket : { } ,
170+ timing : function ( ) {
171+ arguments [ 4 ] ( 'foo' )
172+ }
173+ }
174+ }
175+
176+ var statsd = new StatsDCollector ( mockLog )
177+ statsd . init ( )
178+ statsd . client = new StatsDMock ( )
179+ statsd . timing ( 'wibble' , 42 )
180+ }
181+ )
182+
125183test (
126184 'statsd close' ,
127185 function ( t ) {
0 commit comments