@@ -304,6 +304,68 @@ describe("Sticky", function()
304
304
it (" returns the correct endpoint for the client" , function () test_correct_endpoint (sticky_balanced ) end )
305
305
it (" returns the correct endpoint for the client" , function () test_correct_endpoint (sticky_persistent ) end )
306
306
end )
307
+
308
+ -- Note below that endpoints are only marked this way when persistent
309
+ describe (" when an endpoint is draining" , function ()
310
+ it (" persists client with cookie to endpoint" , function ()
311
+ local s = {}
312
+ local cookie_jar = {}
313
+ cookie .new = function (self )
314
+ local cookie_instance = {
315
+ set = function (self , ck )
316
+ cookie_jar [ck .key ] = ck .value
317
+ return true , nil
318
+ end ,
319
+ get = function (self , k ) return cookie_jar [k ] end ,
320
+ }
321
+ s = spy .on (cookie_instance , " set" )
322
+ return cookie_instance , false
323
+ end
324
+
325
+ local b = get_test_backend ()
326
+ b .sessionAffinityConfig .cookieSessionAffinity .locations = {}
327
+ b .sessionAffinityConfig .cookieSessionAffinity .locations [" test.com" ] = {" /" }
328
+
329
+ local expectedPeer = b .endpoints [1 ]
330
+
331
+ local sticky_balancer_instance = sticky_persistent :new (b )
332
+ local peer = sticky_balancer_instance :balance ()
333
+ assert .equal (peer , test_backend_endpoint )
334
+
335
+ expectedPeer .isDraining = true
336
+ sticky_balancer_instance :sync (b )
337
+ sticky_balancer_instance .TESTING = true
338
+ peer = sticky_balancer_instance :balance ()
339
+ assert .equal (peer , test_backend_endpoint )
340
+ end )
341
+
342
+ it (" does not route client without cookie to endpoint" , function ()
343
+ local s = {}
344
+ local cookie_jar = {}
345
+ cookie .new = function (self )
346
+ local cookie_instance = {
347
+ set = function (self , ck )
348
+ cookie_jar [ck .key ] = ck .value
349
+ return true , nil
350
+ end ,
351
+ get = function (self , k ) return cookie_jar [k ] end ,
352
+ }
353
+ s = spy .on (cookie_instance , " set" )
354
+ return cookie_instance , false
355
+ end
356
+
357
+ local b = get_test_backend ()
358
+ b .sessionAffinityConfig .cookieSessionAffinity .locations = {}
359
+ b .sessionAffinityConfig .cookieSessionAffinity .locations [" test.com" ] = {" /" }
360
+
361
+ local expectedPeer = b .endpoints [1 ]
362
+ expectedPeer .isDraining = true
363
+
364
+ local sticky_balancer_instance = sticky_persistent :new (b )
365
+ local peer = sticky_balancer_instance :balance ()
366
+ assert .equal (peer , nil )
367
+ end )
368
+ end )
307
369
end )
308
370
309
371
local function get_several_test_backends (change_on_failure )
0 commit comments