@@ -43,7 +43,12 @@ describe("Proxy Tests", function () {
43
43
path : "/" ,
44
44
} )
45
45
) ;
46
- done ( ) ;
46
+
47
+ // check last_activity was updated
48
+ return proxy . _routes . get ( "/" ) . then ( ( route ) => {
49
+ expect ( route . last_activity ) . toBeGreaterThan ( proxy . _setup_timestamp ) ;
50
+ done ( ) ;
51
+ } ) ;
47
52
} ) ;
48
53
} ) ;
49
54
@@ -66,8 +71,12 @@ describe("Proxy Tests", function () {
66
71
message : "hi" ,
67
72
} )
68
73
) ;
69
- ws . close ( ) ;
70
- done ( ) ;
74
+ // check last_activity was updated
75
+ return proxy . _routes . get ( "/" ) . then ( ( route ) => {
76
+ expect ( route . last_activity ) . toBeGreaterThan ( proxy . _setup_timestamp ) ;
77
+ ws . close ( ) ;
78
+ done ( ) ;
79
+ } ) ;
71
80
}
72
81
nmsgs ++ ;
73
82
} ) ;
@@ -269,6 +278,50 @@ describe("Proxy Tests", function () {
269
278
. then ( done ) ;
270
279
} ) ;
271
280
281
+ it ( "last_activity not updated on errors" , function ( done ) {
282
+ let now = new Date ( ) ;
283
+ // mock timestamp in the past
284
+ let firstActivity = new Date ( now . getTime ( ) - 60000 ) ;
285
+
286
+ function expectNoActivity ( ) {
287
+ return proxy . _routes . get ( "/missing" , ( route ) => {
288
+ expect ( route . last_activity ) . toEqual ( proxy . _setup_timestamp ) ;
289
+ } ) ;
290
+ }
291
+
292
+ proxy
293
+ . removeRoute ( "/" )
294
+ // add a route to nowhere
295
+ . then ( ( ) => proxy . addRoute ( "/missing" , { target : "https://127.0.0.1:54321" } ) )
296
+ . then ( ( ) => {
297
+ // set last_activity into the past
298
+ proxy . _routes . update ( "/missing" , { last_activity : firstActivity } ) ;
299
+ } )
300
+ // fail a web request
301
+ . then ( ( ) => r ( hostUrl + "/missing/prefix" ) )
302
+ . then ( ( body ) => done . fail ( "Expected 503" ) )
303
+ . catch ( ( err ) => {
304
+ expect ( err . statusCode ) . toEqual ( 503 ) ;
305
+ } )
306
+ // check that activity was not updated
307
+ . then ( expectNoActivity )
308
+ // fail a websocket request
309
+ . then ( ( ) => {
310
+ var ws = new WebSocket ( "ws://127.0.0.1:" + port + "/missing/ws" ) ;
311
+ ws . on ( "error" , ( ) => {
312
+ // expect this, since there is no websocket handler
313
+ // check last_activity was not updated
314
+ expectNoActivity ( ) . then ( ( route ) => {
315
+ ws . close ( ) ;
316
+ done ( ) ;
317
+ } ) ;
318
+ } ) ;
319
+ ws . on ( "open" , ( ) => {
320
+ done . fail ( "Expected websocket error" ) ;
321
+ } ) ;
322
+ } ) ;
323
+ } ) ;
324
+
272
325
it ( "custom error target" , function ( done ) {
273
326
var proxyPort = 55550 ;
274
327
util
0 commit comments