@@ -81,33 +81,42 @@ describe('Standalone ASM', () => {
8181 } )
8282 } )
8383
84- it ( 'should keep second req because RateLimiter allows 1 req/min and discard the next' , async ( ) => {
85- // 1st req kept because waf init
86- // 2nd req kept because it's the first one hitting RateLimiter
87- // next in the first minute are dropped
88- await doWarmupRequests ( proc )
89-
90- return curlAndAssertMessage ( agent , proc , ( { headers, payload } ) => {
84+ it ( 'should keep fifth req because RateLimiter allows 1 req/min' , async ( ) => {
85+ const promise = curlAndAssertMessage ( agent , proc , ( { headers, payload } ) => {
9186 assert . propertyVal ( headers , 'datadog-client-computed-stats' , 'yes' )
9287 assert . isArray ( payload )
93- assert . strictEqual ( payload . length , 4 )
94-
95- const secondReq = payload [ 1 ]
96- assert . isArray ( secondReq )
97- assert . strictEqual ( secondReq . length , 5 )
88+ if ( payload . length === 4 ) {
89+ assertKeep ( payload [ 0 ] [ 0 ] )
90+ assertDrop ( payload [ 1 ] [ 0 ] )
91+ assertDrop ( payload [ 2 ] [ 0 ] )
92+ assertDrop ( payload [ 3 ] [ 0 ] )
93+
94+ // req after a minute
95+ } else {
96+ const fifthReq = payload [ 0 ]
97+ assert . isArray ( fifthReq )
98+ assert . strictEqual ( fifthReq . length , 5 )
99+
100+ const { meta, metrics } = fifthReq [ 0 ]
101+ assert . notProperty ( meta , 'manual.keep' )
102+ assert . notProperty ( meta , '_dd.p.appsec' )
103+
104+ assert . propertyVal ( metrics , '_sampling_priority_v1' , AUTO_KEEP )
105+ assert . propertyVal ( metrics , '_dd.apm.enabled' , 0 )
106+ }
107+ } , 70000 , 2 )
98108
99- const { meta, metrics } = secondReq [ 0 ]
100- assert . notProperty ( meta , 'manual.keep' )
101- assert . notProperty ( meta , '_dd.p.appsec' )
109+ // 1st req kept because waf init
110+ // next in the first minute are dropped
111+ // 5nd req kept because RateLimiter allows 1 req/min
112+ await doWarmupRequests ( proc )
102113
103- assert . propertyVal ( metrics , '_sampling_priority_v1' , AUTO_KEEP )
104- assert . propertyVal ( metrics , '_dd.apm.enabled' , 0 )
114+ await new Promise ( resolve => setTimeout ( resolve , 60000 ) )
105115
106- assertDrop ( payload [ 2 ] [ 0 ] )
116+ await curl ( proc )
107117
108- assertDrop ( payload [ 3 ] [ 0 ] )
109- } )
110- } )
118+ return promise
119+ } ) . timeout ( 70000 )
111120
112121 it ( 'should keep attack requests' , async ( ) => {
113122 await doWarmupRequests ( proc )
0 commit comments