Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add balancer unit tests #2410

Merged
merged 1 commit into from
Apr 24, 2018
Merged

Conversation

zrdaley
Copy link
Contributor

@zrdaley zrdaley commented Apr 23, 2018

What this PR does / why we need it:

Currently no unit tests exist for ingress-nginx/rootfs/etc/nginx/lua/balancer.lua. This PR adds unit tests for the file.

Which issue this PR fixes: N/A

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 23, 2018
@aledbf
Copy link
Member

aledbf commented Apr 23, 2018

/approve

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 23, 2018
@aledbf
Copy link
Member

aledbf commented Apr 23, 2018

@zrdaley thank you for doing this

@@ -164,6 +167,9 @@ function _M.call()
ngx_balancer.set_more_tries(1)

local host, port = balance()
if not host then
return error("balancer did not return a host")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of returning error please set the ngx.status to ngx.HTTP_SERVICE_UNAVAILABLE and log the error - this function is not expected to return anything

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm it actually does return something - but still when we can not find any upstream to proxy to we should return HTTP 503(ngx.HTTP_SERVICE_UNAVAILABLE)

local ewma_after_balance_spy = spy.on(mock_ewma, "after_balance")

assert.has_no_errors(balancer.call)
assert.spy(backend_get_spy).was_called_with(match.is_table(), "mock_ewma_backend")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not add any value IMHO and is leaking internal knowledge about implementation.

local ewma_after_balance_spy = spy.on(mock_ewma, "after_balance")

assert.has_no_errors(balancer.call)
assert.spy(backend_get_spy).was_called_with(match.is_table(), "mock_rr_backend")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

mock_backends._vals = {}

local backend_get_spy = spy.on(mock_backends, "get")
local ngx_spy = spy.on(_G.ngx, "log")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this does not seem to be used anywhere

Copy link
Member

@ElvinEfendi ElvinEfendi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great first step toward Lua unit test coverage! @zrdaley had just a few small comments, let's address them then it is good to merge.

@zrdaley zrdaley force-pushed the balancer-tests branch 2 times, most recently from b416ec9 to 9c6bae0 Compare April 24, 2018 13:37
@zrdaley
Copy link
Contributor Author

zrdaley commented Apr 24, 2018

@ElvinEfendi I addressed all of your concerns. I was slightly confused about your comments in balancer.lua, so I set ngx.status to HTTP_SERVICE_UNAVAILABLE and also returned an error message.

@codecov-io
Copy link

codecov-io commented Apr 24, 2018

Codecov Report

Merging #2410 into master will decrease coverage by 0.05%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2410      +/-   ##
==========================================
- Coverage   40.97%   40.91%   -0.06%     
==========================================
  Files          74       74              
  Lines        5252     5252              
==========================================
- Hits         2152     2149       -3     
- Misses       2807     2809       +2     
- Partials      293      294       +1
Impacted Files Coverage Δ
internal/file/bindata.go 60.17% <ø> (ø) ⬆️
cmd/nginx/main.go 21.37% <0%> (-2.07%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 97d7119...0d0d33a. Read the comment docs.

@@ -164,6 +167,10 @@ function _M.call()
ngx_balancer.set_more_tries(1)

local host, port = balance()
if not host then
ngx.status = ngx.HTTP_SERVICE_UNAVAILABLE
return error(ngx.HTTP_SERVICE_UNAVAILABLE .. ": service unavailable")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just return without anything

@ElvinEfendi
Copy link
Member

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 24, 2018
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: aledbf, ElvinEfendi, zrdaley

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot merged commit 3615583 into kubernetes:master Apr 24, 2018
@ElvinEfendi ElvinEfendi deleted the balancer-tests branch April 24, 2018 21:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants