-
Notifications
You must be signed in to change notification settings - Fork 25
Conversation
c05f004
to
47c4376
Compare
|
||
describe("balance()", function() | ||
setup(function() | ||
util.sha1_digest = function(msg) return msg, false end -- Don't hash for simplification |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment is not adding any value here imo
} | ||
end | ||
local sticky_balancer_instance = sticky:new(test_backend) | ||
local s = spy.on(sticky_balancer_instance.instance, "next") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we avoid this? This test should not know the implementation details of balance
function. Why don't you assert on the return value of :balance
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, it currently feels a bit hacky. I like the approach you suggested 👍
end | ||
local sticky_balancer_instance = sticky:new(get_test_backend()) | ||
assert.has_no.errors(function() sticky_balancer_instance:balance() end) | ||
assert.spy(s).was_called() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also assert on the parameters of cookie? i.e what key, value, path, domain it is setting.
end) | ||
end) | ||
|
||
context("when client has a cookie set", function() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are missing a crucial test here. We should make sure :balance
returns the correct endpoint for given cookie value.
@ElvinEfendi Addressed your comments |
local sticky_balancer_instance = sticky:new(test_backend) | ||
local ip, port = sticky_balancer_instance:balance() | ||
assert.equal(ip .. ":" .. port, test_backend_endpoint) | ||
end) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test isn't covering the logic properly:
> ingress (add-sticky-module-unit-tests)$ git diff
diff --git a/rootfs/etc/nginx/lua/balancer/sticky.lua b/rootfs/etc/nginx/lua/balancer/sticky.lua
index 8af93a98..348cb94b 100644
--- a/rootfs/etc/nginx/lua/balancer/sticky.lua
+++ b/rootfs/etc/nginx/lua/balancer/sticky.lua
@@ -70,7 +70,8 @@ local function sticky_endpoint_string(self)
set_cookie(self, key)
end
- return self.instance:find(key)
+ return key
+ --return self.instance:find(key)
end
function _M.balance(self)
> ingress (add-sticky-module-unit-tests)$ make lua-test
Makefile:160: warning: overriding commands for target `verify-all'
Makefile:156: warning: ignoring old commands for target `verify-all'
●●●●●●●●●●●●●●●●●●●●●
21 successes / 0 failures / 0 errors / 0 pending : 0.02952 seconds
|
||
it("should return the correct endpoint for the client", function() | ||
local cookie = require("resty.cookie") | ||
local s = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this variable is unused
06e6cf2
to
4bcc9e6
Compare
4bcc9e6
to
15cad2a
Compare
@ElvinEfendi Updated the tests. Removed |
6e77f19
to
d9bed56
Compare
d411ccd
to
5085291
Compare
5085291
to
a570797
Compare
this was completed at kubernetes#2966 |
What this PR does / why we need it:
This PR adds unit tests to
sticky
lua module. We need this because we don't have unit test coverage for this module.Issue: https://github.com/Shopify/edgescale/issues/435