@@ -311,6 +311,65 @@ describe(__filename, function(){
311311 debuglet . start ( ) ;
312312 } ) ;
313313
314+ // This test catches regressions in a bug where the agent would
315+ // re-schedule an already expired breakpoint to expire if the
316+ // server listed the breakpoint as active (which it may do depending
317+ // on how quickly the expiry is processed).
318+ // The test expires a breakpoint and then has the api respond with
319+ // the breakpoint listed as active. It validates that the breakpoint
320+ // is only expired with the server once.
321+ it ( 'should not update expired breakpoints' , function ( done ) {
322+ var oldTimeout = config . breakpointExpirationSec ;
323+ var oldFetchRate = config . breakpointUpdateIntervalSec ;
324+ config . breakpointExpirationSec = 1 ;
325+ config . breakpointUpdateIntervalSec = 1 ;
326+ this . timeout ( 6000 ) ;
327+ var debuglet = new Debuglet (
328+ config , logger . create ( config . logLevel , '@google/cloud-debug' ) ) ;
329+
330+ var scope = nock ( API )
331+ . post ( REGISTER_PATH )
332+ . reply ( 200 , {
333+ debuggee : {
334+ id : DEBUGGEE_ID
335+ }
336+ } )
337+ . get ( BPS_PATH + '?success_on_timeout=true' )
338+ . reply ( 200 , {
339+ breakpoints : [ bp ]
340+ } )
341+ . put ( BPS_PATH + '/test' , function ( body ) {
342+ return body . breakpoint . status . description . format ===
343+ 'The snapshot has expired' ;
344+ } )
345+ . reply ( 200 )
346+ . get ( BPS_PATH + '?success_on_timeout=true' ) . times ( 4 )
347+ . reply ( 200 , {
348+ breakpoints : [ bp ]
349+ } ) ;
350+
351+ debuglet . once ( 'started' , function ( ) {
352+ debuglet . debugletApi_ . request_ = request ; // Avoid authing.
353+ } ) ;
354+ debuglet . once ( 'registered' , function ( id ) {
355+ assert ( id === DEBUGGEE_ID ) ;
356+ setTimeout ( function ( ) {
357+ assert . deepEqual ( debuglet . activeBreakpointMap_ . test , bp ) ;
358+ setTimeout ( function ( ) {
359+ assert ( ! debuglet . activeBreakpointMap_ . test ) ;
360+ // Fetcher disables if we re-update since endpoint isn't mocked twice
361+ assert ( debuglet . fetcherActive_ ) ;
362+ scope . done ( ) ;
363+ config . breakpointExpirationSec = oldTimeout ;
364+ config . breakpointUpdateIntervalSec = oldFetchRate ;
365+ done ( ) ;
366+ } , 4500 ) ;
367+ } , 500 ) ;
368+ } ) ;
369+
370+ debuglet . start ( ) ;
371+ } ) ;
372+
314373 describe ( 'map subtract' , function ( ) {
315374 it ( 'should be correct' , function ( ) {
316375 var a = { a : 1 , b : 2 } ;
0 commit comments