@@ -34,12 +34,13 @@ describe(__filename, function(){
3434 . get ( '/computeMetadata/v1/project/numeric-project-id' )
3535 . reply ( 404 ) ;
3636
37- debuglet . on ( 'error' , function ( err ) {
37+ debuglet . once ( 'error' , function ( err ) {
3838 assert ( err ) ;
39+ debuglet . stop ( ) ;
3940 scope . done ( ) ;
4041 done ( ) ;
4142 } ) ;
42- debuglet . on ( 'started' , function ( ) {
43+ debuglet . once ( 'started' , function ( ) {
4344 assert . fail ( ) ;
4445 } ) ;
4546 debuglet . start ( ) ;
@@ -51,12 +52,13 @@ describe(__filename, function(){
5152
5253 process . env . GCLOUD_PROJECT_NUM = '11020304f2934' ;
5354
54- debuglet . on ( 'error' , function ( err ) {
55+ debuglet . once ( 'error' , function ( err ) {
5556 assert ( err ) ;
5657 assert ( err . message . indexOf ( 'should be numeric' ) !== - 1 ) ;
58+ debuglet . stop ( ) ;
5759 done ( ) ;
5860 } ) ;
59- debuglet . on ( 'started' , function ( ) {
61+ debuglet . once ( 'started' , function ( ) {
6062 assert . fail ( ) ;
6163 } ) ;
6264 debuglet . start ( ) ;
@@ -80,11 +82,12 @@ describe(__filename, function(){
8082 }
8183 } ) ;
8284
83- debuglet . on ( 'started' , function ( ) {
85+ debuglet . once ( 'started' , function ( ) {
8486 debuglet . debugletApi_ . request_ = request ; // Avoid authing.
8587 } ) ;
86- debuglet . on ( 'registered' , function ( id ) {
88+ debuglet . once ( 'registered' , function ( id ) {
8789 assert ( id === 'foo' ) ;
90+ debuglet . stop ( ) ;
8891 scope . done ( ) ;
8992 done ( ) ;
9093 } ) ;
@@ -98,10 +101,111 @@ describe(__filename, function(){
98101
99102 it ( 'should fetch breakpoints' ) ;
100103
101- it ( 'should re-fetch breakpoints' ) ;
104+ it ( 'should re-fetch breakpoints on error' , function ( done ) {
105+ this . timeout ( 6000 ) ;
106+ var debuglet = new Debuglet (
107+ config , logger . create ( config . logLevel , '@google/cloud-debug' ) ) ;
108+
109+ process . env . GCLOUD_PROJECT_NUM = 0 ;
110+
111+ var API = 'https://clouddebugger.googleapis.com' ;
112+
113+ var scope = nock ( API )
114+ . post ( '/v2/controller/debuggees/register' )
115+ . reply ( 200 , {
116+ debuggee : {
117+ id : 'bar'
118+ }
119+ } )
120+ . post ( '/v2/controller/debuggees/register' )
121+ . reply ( 200 , {
122+ debuggee : {
123+ id : 'bar'
124+ }
125+ } )
126+ . get ( '/v2/controller/debuggees/bar/breakpoints' )
127+ . reply ( 404 )
128+ . get ( '/v2/controller/debuggees/bar/breakpoints' )
129+ . reply ( 409 )
130+ . get ( '/v2/controller/debuggees/bar/breakpoints' )
131+ . reply ( 200 , {
132+ breakpoints : [ {
133+ id : 'test' ,
134+ location : { path : 'fixtures/foo.js' , line : 2 }
135+ } ]
136+ } ) ;
137+
138+ debuglet . once ( 'started' , function ( ) {
139+ debuglet . debugletApi_ . request_ = request ; // Avoid authing.
140+ } ) ;
141+ debuglet . once ( 'registered' , function reg ( id ) {
142+ assert ( id === 'bar' ) ;
143+ setTimeout ( function ( ) {
144+ assert . deepEqual ( debuglet . activeBreakpointMap_ . test , {
145+ id : 'test' ,
146+ location : { path : 'fixtures/foo.js' , line : 2 }
147+ } ) ;
148+ debuglet . stop ( ) ;
149+ scope . done ( ) ;
150+ done ( ) ;
151+ } , 1000 ) ;
152+ } ) ;
153+
154+ debuglet . start ( ) ;
155+ } ) ;
102156
103157 it ( 'should add a breakpoint' ) ;
104158
105- it ( 'should expire stale breakpoints' ) ;
159+ it ( 'should expire stale breakpoints' , function ( done ) {
160+ var oldTimeout = config . breakpointExpirationSec ;
161+ config . breakpointExpirationSec = 1 ;
162+ this . timeout ( 6000 ) ;
163+ var debuglet = new Debuglet (
164+ config , logger . create ( config . logLevel , '@google/cloud-debug' ) ) ;
165+
166+ process . env . GCLOUD_PROJECT_NUM = 0 ;
167+
168+ var bp = {
169+ id : 'test' ,
170+ location : { path : 'fixtures/foo.js' , line : 2 }
171+ } ;
172+
173+ var API = 'https://clouddebugger.googleapis.com' ;
174+
175+ var scope = nock ( API )
176+ . post ( '/v2/controller/debuggees/register' )
177+ . reply ( 200 , {
178+ debuggee : {
179+ id : 'bar'
180+ }
181+ } )
182+ . get ( '/v2/controller/debuggees/bar/breakpoints' )
183+ . reply ( 200 , {
184+ breakpoints : [ bp ]
185+ } )
186+ . put ( '/v2/controller/debuggees/bar/breakpoints/test' , function ( body ) {
187+ return body . breakpoint . status . description . format === 'The snapshot has expired' ;
188+ } )
189+ . reply ( 200 ) ;
190+
191+ debuglet . once ( 'started' , function ( ) {
192+ debuglet . debugletApi_ . request_ = request ; // Avoid authing.
193+ } ) ;
194+ debuglet . once ( 'registered' , function ( id ) {
195+ assert ( id === 'bar' ) ;
196+ setTimeout ( function ( ) {
197+ assert . deepEqual ( debuglet . activeBreakpointMap_ . test , bp ) ;
198+ setTimeout ( function ( ) {
199+ assert ( ! debuglet . activeBreakpointMap_ . test ) ;
200+ debuglet . stop ( ) ;
201+ scope . done ( ) ;
202+ config . breakpointExpirationSec = oldTimeout ;
203+ done ( ) ;
204+ } , 1100 ) ;
205+ } , 500 ) ;
206+ } ) ;
207+
208+ debuglet . start ( ) ;
209+ } ) ;
106210} ) ;
107211
0 commit comments