From e9f4c0bb0ed8e1a177bae5d0f4f04e8b819cbe9f Mon Sep 17 00:00:00 2001 From: s-shirayama Date: Tue, 11 Jun 2019 22:21:03 +0900 Subject: [PATCH] Add unit test case for canary by weight --- rootfs/etc/nginx/lua/test/balancer_test.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/rootfs/etc/nginx/lua/test/balancer_test.lua b/rootfs/etc/nginx/lua/test/balancer_test.lua index e9ef12d10..29ec7d791 100644 --- a/rootfs/etc/nginx/lua/test/balancer_test.lua +++ b/rootfs/etc/nginx/lua/test/balancer_test.lua @@ -117,6 +117,20 @@ describe("Balancer", function() _balancer.alternative_backends[1] = "nonExistingBackend" assert.equal(false, balancer.route_to_alternative_balancer(_balancer)) end) + + context("canary by weight", function() + it("returns true when weight is 100", function() + backend.trafficShapingPolicy.weight = 100 + balancer.sync_backend(backend) + assert.equal(true, balancer.route_to_alternative_balancer(_balancer)) + end) + + it("returns false when weight is 0", function() + backend.trafficShapingPolicy.weight = 0 + balancer.sync_backend(backend) + assert.equal(false, balancer.route_to_alternative_balancer(_balancer)) + end) + end) end) describe("sync_backend()", function()