@@ -57,7 +57,12 @@ describe('The http.Server.prototype wrapper module', function () {
5757 serverReceive : this . sandbox . spy ( ) ,
5858 bind : function ( ) {
5959 return this . sandbox . spy ( )
60- } . bind ( this )
60+ } . bind ( this ) ,
61+ clearTransaction : this . sandbox . spy ( ) ,
62+ rpmMetrics : {
63+ addResponseTime : this . sandbox . spy ( ) ,
64+ addStatusCode : this . sandbox . spy ( )
65+ }
6166 }
6267 } )
6368
@@ -97,6 +102,48 @@ describe('The http.Server.prototype wrapper module', function () {
97102 } )
98103 } )
99104
105+ it ( 'skips the request if the statusCode is a match' , function ( ) {
106+ config . ignoreStatusCodes = [
107+ 401
108+ ]
109+ var s = server ( original , agent , mustCollectStore )
110+ var writeHeadSpy = this . sandbox . spy ( )
111+ var setHeaderSpy = this . sandbox . spy ( )
112+ var cb
113+
114+ var request = {
115+ headers : {
116+ host : 'localhost'
117+ } ,
118+ pathname : '/' ,
119+ url : '/healthcheck' ,
120+ method : 'POST'
121+ }
122+ var response = {
123+ writeHead : writeHeadSpy ,
124+ // it is ugly, let's make it better later
125+ once : function ( name , _cb ) {
126+ if ( name === 'finish' ) {
127+ cb = _cb
128+ }
129+ } ,
130+ setHeader : setHeaderSpy ,
131+ statusCode : 401
132+ }
133+
134+ this . sandbox . stub ( microtime , 'now' ) . returns ( 12345678 )
135+
136+ s ( request , response )
137+
138+ response . writeHead ( )
139+ cb ( )
140+
141+ expect ( agent . clearTransaction ) . to . be . calledWith ( transactionId )
142+ expect ( agent . rpmMetrics . addResponseTime ) . to . be . calledWith ( 0 )
143+ expect ( agent . rpmMetrics . addStatusCode ) . to . be . calledWith ( 401 )
144+ expect ( agent . serverSend ) . not . to . have . been . called
145+ } )
146+
100147 it ( 'skips requests if there is an *' , function ( ) {
101148 config . ignoreHeaders = {
102149 'user-agent' : '*'
@@ -177,6 +224,8 @@ describe('The http.Server.prototype wrapper module', function () {
177224
178225 expect ( setHeaderSpy ) . to . be . calledWith ( 'x-server-send' , 12345678 )
179226 expect ( setHeaderSpy ) . to . be . calledWith ( 'x-parent' , 0 )
227+ expect ( agent . rpmMetrics . addResponseTime ) . to . be . calledWith ( 0 )
228+ expect ( agent . rpmMetrics . addStatusCode ) . to . be . calledWith ( statusCode )
180229 expect ( writeHeadSpy ) . to . be . calledOnce
181230 } )
182231
@@ -244,6 +293,8 @@ describe('The http.Server.prototype wrapper module', function () {
244293 expect ( setHeaderSpy ) . to . be . calledWith ( 'x-parent' , 0 )
245294 expect ( setHeaderSpy ) . to . be . calledWith ( 'x-span-id' , spanId )
246295 expect ( setHeaderSpy ) . to . be . calledWith ( 'x-must-collect' , '1' )
296+ expect ( agent . rpmMetrics . addResponseTime ) . to . be . calledWith ( 0 )
297+ expect ( agent . rpmMetrics . addStatusCode ) . to . be . calledWith ( statusCode )
247298 expect ( writeHeadSpy ) . to . be . calledOnce
248299 } )
249300 } )
0 commit comments