Skip to content

Commit

Permalink
chore(deps) bump resty.worker.events from 1.0 to 2.0 (and fix tests) (#…
Browse files Browse the repository at this point in the history
…53)

* BREAKING: Bump lua-resty-worker-events dependency to 2.0.0. This makes
  a lot of the APIs in this library asynchronous as the worker events post
  and post_local won't anymore call poll on a running worker automatically,
  for more information, see: https://github.com/Kong/lua-resty-worker-events#200-16-september-2020

Co-authored-by: Aapo Talvensaari <aapo.talvensaari@gmail.com>
  • Loading branch information
Tieske and bungle committed Sep 18, 2020
1 parent 31440a7 commit e49622e
Show file tree
Hide file tree
Showing 16 changed files with 138 additions and 23 deletions.
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ env:
- JOBS=2
- LUAROCKS_VER=2.4.3
matrix:
- OPENRESTY_VER=1.11.2.2
- OPENRESTY_VER=1.11.2.4
- OPENRESTY_VER=1.15.8.1
- OPENRESTY_VER=1.11.2.5
- OPENRESTY_VER=1.13.6.2
- OPENRESTY_VER=1.15.8.3
- OPENRESTY_VER=1.17.8.2
# - LINT=1

install:
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ Versioning is strictly based on [Semantic Versioning](https://semver.org/)

### Unreleased

* BREAKING: Bump `lua-resty-worker-events` dependency to `2.0.0`. This makes
a lot of the APIs in this library asynchronous as the worker events `post`
and `post_local` won't anymore call `poll` on a running worker automatically,
for more information, see:
https://github.com/Kong/lua-resty-worker-events#200-16-september-2020
* fix: properly log line numbers by using tail calls [#29](https://github.com/Kong/lua-resty-healthcheck/pull/29)
* fix: when not providing a hostname, use IP [#48](https://github.com/Kong/lua-resty-healthcheck/pull/48)
* fix: makefile; make install
Expand Down Expand Up @@ -193,7 +198,7 @@ Versioning is strictly based on [Semantic Versioning](https://semver.org/)
## Copyright and License

```
Copyright 2017-2019 Kong Inc.
Copyright 2017-2020 Kong Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
4 changes: 2 additions & 2 deletions lib/resty/healthcheck.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
-- - Events will be raised in every worker, see [lua-resty-worker-events](https://github.com/Kong/lua-resty-worker-events)
-- for details.
--
-- @copyright 2017 Kong Inc.
-- @copyright 2017-2020 Kong Inc.
-- @author Hisham Muhammad, Thijs Schreijer
-- @license Apache 2.0

Expand Down Expand Up @@ -1433,7 +1433,7 @@ function _M.new(opts)
worker_events.register_weak(self.ev_callback, self.EVENT_SOURCE)

-- handle events to sync up in case there was a change by another worker
worker_events:poll()
worker_events.poll()
end

-- start timers
Expand Down
2 changes: 1 addition & 1 deletion lib/resty/healthcheck/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
-- Utilities used by the healthcheck library.
--
-- Code originally from https://github.com/Kong/lua-resty-dns-client
-- @copyright 2017 Kong Inc.
-- @copyright 2017-2020 Kong Inc.
-- @author Hisham Muhammad, Thijs Schreijer
-- @license Apache 2.0

Expand Down
32 changes: 16 additions & 16 deletions lua-resty-healthcheck-scm-2.rockspec
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
package = "lua-resty-healthcheck"
version = "scm-2"
source = {
url = "git://github.com/kong/lua-resty-healthcheck",
url = "git://github.com/kong/lua-resty-healthcheck",
}
description = {
summary = "Healthchecks for OpenResty to check upstream service status",
detailed = [[
lua-resty-healthcheck is a module that can check upstream service
availability by sending requests and validating responses at timed
intervals.
]],
license = "Apache 2.0",
homepage = "https://github.com/Kong/lua-resty-healthcheck"
summary = "Healthchecks for OpenResty to check upstream service status",
detailed = [[
lua-resty-healthcheck is a module that can check upstream service
availability by sending requests and validating responses at timed
intervals.
]],
license = "Apache 2.0",
homepage = "https://github.com/Kong/lua-resty-healthcheck"
}
dependencies = {
"lua-resty-worker-events >= 0.3.2, < 2.0",
"penlight == 1.7.0",
"lua-resty-worker-events ~> 2",
"penlight ~> 1.7",
}
build = {
type = "builtin",
modules = {
["resty.healthcheck"] = "lib/resty/healthcheck.lua",
["resty.healthcheck.utils"] = "lib/resty/healthcheck/utils.lua",
}
type = "builtin",
modules = {
["resty.healthcheck"] = "lib/resty/healthcheck.lua",
["resty.healthcheck.utils"] = "lib/resty/healthcheck/utils.lua",
}
}
6 changes: 6 additions & 0 deletions t/03-get_target_status.t
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,17 @@ qq{
}
})
ngx.sleep(0.1) -- wait for initial timers to run once

local ok, err = checker:add_target("127.0.0.1", 2115, nil, true)
we.poll()
ngx.say(checker:get_target_status("127.0.0.1", 2115)) -- true

checker:report_tcp_failure("127.0.0.1", 2115)
we.poll()
ngx.say(checker:get_target_status("127.0.0.1", 2115)) -- false

checker:report_success("127.0.0.1", 2115)
we.poll()
ngx.say(checker:get_target_status("127.0.0.1", 2115)) -- true
}
}
Expand Down
8 changes: 8 additions & 0 deletions t/04-report_success.t
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,14 @@ qq{
ngx.sleep(0.1) -- wait for initial timers to run once
local ok, err = checker:add_target("127.0.0.1", 2116, nil, false)
local ok, err = checker:add_target("127.0.0.1", 2118, nil, false)
we.poll()
checker:report_success("127.0.0.1", 2116, nil, "active")
checker:report_success("127.0.0.1", 2118, nil, "passive")
checker:report_success("127.0.0.1", 2116, nil, "active")
checker:report_success("127.0.0.1", 2118, nil, "passive")
checker:report_success("127.0.0.1", 2116, nil, "active")
checker:report_success("127.0.0.1", 2118, nil, "passive")
we.poll()
ngx.say(checker:get_target_status("127.0.0.1", 2116)) -- true
ngx.say(checker:get_target_status("127.0.0.1", 2118)) -- true
}
Expand Down Expand Up @@ -145,12 +147,14 @@ qq{
ngx.sleep(0.1) -- wait for initial timers to run once
local ok, err = checker:add_target("127.0.0.1", 2116, nil, false)
local ok, err = checker:add_target("127.0.0.1", 2118, nil, false)
we.poll()
checker:report_success("127.0.0.1", 2116, nil, "active")
checker:report_success("127.0.0.1", 2118, nil, "passive")
checker:report_success("127.0.0.1", 2116, nil, "active")
checker:report_success("127.0.0.1", 2118, nil, "passive")
checker:report_success("127.0.0.1", 2116, nil, "active")
checker:report_success("127.0.0.1", 2118, nil, "passive")
we.poll()
ngx.say(checker:get_target_status("127.0.0.1", 2116)) -- true
ngx.say(checker:get_target_status("127.0.0.1", 2118)) -- true
}
Expand Down Expand Up @@ -220,9 +224,11 @@ qq{
})
ngx.sleep(0.1) -- wait for initial timers to run once
local ok, err = checker:add_target("127.0.0.1", 2116, nil, false)
we.poll()
checker:report_success("127.0.0.1", 2116, nil, "active")
checker:report_success("127.0.0.1", 2116, nil, "active")
checker:report_success("127.0.0.1", 2116, nil, "active")
we.poll()
ngx.say(checker:get_target_status("127.0.0.1", 2116)) -- false
}
}
Expand Down Expand Up @@ -284,9 +290,11 @@ qq{
})
ngx.sleep(0.1) -- wait for initial timers to run once
local ok, err = checker:add_target("127.0.0.1", 2118, nil, false)
we.poll()
checker:report_success("127.0.0.1", 2118, nil, "passive")
checker:report_success("127.0.0.1", 2118, nil, "passive")
checker:report_success("127.0.0.1", 2118, nil, "passive")
we.poll()
ngx.say(checker:get_target_status("127.0.0.1", 2118, nil)) -- false
}
}
Expand Down
6 changes: 6 additions & 0 deletions t/05-report_failure.t
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,14 @@ qq{
ngx.sleep(0.1) -- wait for initial timers to run once
local ok, err = checker:add_target("127.0.0.1", 2117, nil, true)
local ok, err = checker:add_target("127.0.0.1", 2113, nil, true)
we.poll()
checker:report_failure("127.0.0.1", 2117, nil, "active")
checker:report_failure("127.0.0.1", 2113, nil, "passive")
checker:report_failure("127.0.0.1", 2117, nil, "active")
checker:report_failure("127.0.0.1", 2113, nil, "passive")
checker:report_failure("127.0.0.1", 2117, nil, "active")
checker:report_failure("127.0.0.1", 2113, nil, "passive")
we.poll()
ngx.say(checker:get_target_status("127.0.0.1", 2117, nil)) -- false
ngx.say(checker:get_target_status("127.0.0.1", 2113, nil)) -- false
}
Expand Down Expand Up @@ -145,12 +147,14 @@ qq{
ngx.sleep(0.1) -- wait for initial timers to run once
local ok, err = checker:add_target("127.0.0.1", 2117, nil, true)
local ok, err = checker:add_target("127.0.0.1", 2113, nil, true)
we.poll()
checker:report_failure("127.0.0.1", 2117, nil, "active")
checker:report_failure("127.0.0.1", 2113, nil, "passive")
checker:report_failure("127.0.0.1", 2117, nil, "active")
checker:report_failure("127.0.0.1", 2113, nil, "passive")
checker:report_failure("127.0.0.1", 2117, nil, "active")
checker:report_failure("127.0.0.1", 2113, nil, "passive")
we.poll()
ngx.say(checker:get_target_status("127.0.0.1", 2117, nil)) -- false
ngx.say(checker:get_target_status("127.0.0.1", 2113, nil)) -- false
}
Expand Down Expand Up @@ -220,12 +224,14 @@ qq{
ngx.sleep(0.1) -- wait for initial timers to run once
local ok, err = checker:add_target("127.0.0.1", 2117, nil, true)
local ok, err = checker:add_target("127.0.0.1", 2113, nil, true)
we.poll()
checker:report_failure("127.0.0.1", 2117, nil, "active")
checker:report_failure("127.0.0.1", 2113, nil, "passive")
checker:report_failure("127.0.0.1", 2117, nil, "active")
checker:report_failure("127.0.0.1", 2113, nil, "passive")
checker:report_failure("127.0.0.1", 2117, nil, "active")
checker:report_failure("127.0.0.1", 2113, nil, "passive")
we.poll()
ngx.say(checker:get_target_status("127.0.0.1", 2117, nil)) -- true
ngx.say(checker:get_target_status("127.0.0.1", 2113, nil)) -- true
}
Expand Down
13 changes: 13 additions & 0 deletions t/06-report_http_status.t
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,14 @@ qq{
ngx.sleep(0.1) -- wait for initial timers to run once
local ok, err = checker:add_target("127.0.0.1", 2119, nil, true)
local ok, err = checker:add_target("127.0.0.1", 2113, nil, true)
we.poll()
checker:report_http_status("127.0.0.1", 2119, nil, 500, "active")
checker:report_http_status("127.0.0.1", 2113, nil, 500, "passive")
checker:report_http_status("127.0.0.1", 2119, nil, 500, "active")
checker:report_http_status("127.0.0.1", 2113, nil, 500, "passive")
checker:report_http_status("127.0.0.1", 2119, nil, 500, "active")
checker:report_http_status("127.0.0.1", 2113, nil, 500, "passive")
we.poll()
ngx.say(checker:get_target_status("127.0.0.1", 2119)) -- false
ngx.say(checker:get_target_status("127.0.0.1", 2113)) -- false
}
Expand Down Expand Up @@ -146,6 +148,7 @@ qq{
ngx.sleep(0.1) -- wait for initial timers to run once
local ok, err = checker:add_target("127.0.0.1", 2119, nil, false)
local ok, err = checker:add_target("127.0.0.1", 2113, nil, false)
we.poll()
checker:report_http_status("127.0.0.1", 2119, nil, 200, "active")
checker:report_http_status("127.0.0.1", 2113, nil, 200, "passive")
checker:report_http_status("127.0.0.1", 2119, nil, 200, "active")
Expand All @@ -154,6 +157,7 @@ qq{
checker:report_http_status("127.0.0.1", 2113, nil, 200, "passive")
checker:report_http_status("127.0.0.1", 2119, nil, 200, "active")
checker:report_http_status("127.0.0.1", 2113, nil, 200, "passive")
we.poll()
ngx.say(checker:get_target_status("127.0.0.1", 2119)) -- true
ngx.say(checker:get_target_status("127.0.0.1", 2113)) -- true
}
Expand Down Expand Up @@ -226,10 +230,12 @@ qq{
})
ngx.sleep(0.1) -- wait for initial timers to run once
local ok, err = checker:add_target("127.0.0.1", 2119, nil, false)
we.poll()
checker:report_http_status("127.0.0.1", 2119, nil, 200, "passive")
checker:report_http_status("127.0.0.1", 2119, nil, 200, "passive")
checker:report_http_status("127.0.0.1", 2119, nil, 200, "passive")
checker:report_http_status("127.0.0.1", 2119, nil, 200, "passive")
we.poll()
ngx.say(checker:get_target_status("127.0.0.1", 2119, nil)) -- false
}
}
Expand Down Expand Up @@ -293,10 +299,12 @@ qq{
})
ngx.sleep(0.1) -- wait for initial timers to run once
local ok, err = checker:add_target("127.0.0.1", 2119, nil, false)
we.poll()
checker:report_http_status("127.0.0.1", 2119, nil, 200, "active")
checker:report_http_status("127.0.0.1", 2119, nil, 200, "active")
checker:report_http_status("127.0.0.1", 2119, nil, 200, "active")
checker:report_http_status("127.0.0.1", 2119, nil, 200, "active")
we.poll()
ngx.say(checker:get_target_status("127.0.0.1", 2119, nil)) -- false
}
}
Expand Down Expand Up @@ -360,10 +368,12 @@ qq{
})
ngx.sleep(0.1) -- wait for initial timers to run once
local ok, err = checker:add_target("127.0.0.1", 2119, nil, true)
we.poll()
checker:report_http_status("127.0.0.1", 2119, nil, 500, "passive")
checker:report_http_status("127.0.0.1", 2119, nil, 500, "passive")
checker:report_http_status("127.0.0.1", 2119, nil, 500, "passive")
checker:report_http_status("127.0.0.1", 2119, nil, 500, "passive")
we.poll()
ngx.say(checker:get_target_status("127.0.0.1", 2119)) -- true
}
}
Expand Down Expand Up @@ -427,10 +437,12 @@ qq{
})
ngx.sleep(0.1) -- wait for initial timers to run once
local ok, err = checker:add_target("127.0.0.1", 2119, nil, true)
we.poll()
checker:report_http_status("127.0.0.1", 2119, nil, 500, "active")
checker:report_http_status("127.0.0.1", 2119, nil, 500, "active")
checker:report_http_status("127.0.0.1", 2119, nil, 500, "active")
checker:report_http_status("127.0.0.1", 2119, nil, 500, "active")
we.poll()
ngx.say(checker:get_target_status("127.0.0.1", 2119, nil)) -- true
}
}
Expand Down Expand Up @@ -477,6 +489,7 @@ qq{
}
})
local ok, err = checker:add_target("127.0.0.1", 2119, nil, true)
we.poll()
checker:report_http_status("127.0.0.1", 2119, nil, 500, "passive")
checker:report_http_status("127.0.0.1", 2119, nil, 500, "passive")
checker:report_http_status("127.0.0.1", 2119, nil, 500, "passive")
Expand Down
6 changes: 6 additions & 0 deletions t/07-report_tcp_failure.t
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,14 @@ qq{
ngx.sleep(0.1) -- wait for initial timers to run once
local ok, err = checker:add_target("127.0.0.1", 2120, nil, true)
local ok, err = checker:add_target("127.0.0.1", 2113, nil, true)
we.poll()
checker:report_tcp_failure("127.0.0.1", 2120, nil, nil, "active")
checker:report_tcp_failure("127.0.0.1", 2113, nil, nil, "passive")
checker:report_tcp_failure("127.0.0.1", 2120, nil, nil, "active")
checker:report_tcp_failure("127.0.0.1", 2113, nil, nil, "passive")
checker:report_tcp_failure("127.0.0.1", 2120, nil, nil, "active")
checker:report_tcp_failure("127.0.0.1", 2113, nil, nil, "passive")
we.poll()
ngx.say(checker:get_target_status("127.0.0.1", 2120)) -- false
ngx.say(checker:get_target_status("127.0.0.1", 2113)) -- false
}
Expand Down Expand Up @@ -144,9 +146,11 @@ qq{
})
ngx.sleep(0.1) -- wait for initial timers to run once
local ok, err = checker:add_target("127.0.0.1", 2120, nil, true)
we.poll()
checker:report_tcp_failure("127.0.0.1", 2120, nil, nil, "active")
checker:report_tcp_failure("127.0.0.1", 2120, nil, nil, "active")
checker:report_tcp_failure("127.0.0.1", 2120, nil, nil, "active")
we.poll()
ngx.say(checker:get_target_status("127.0.0.1", 2120)) -- true
}
}
Expand Down Expand Up @@ -211,9 +215,11 @@ qq{
})
ngx.sleep(0.1) -- wait for initial timers to run once
local ok, err = checker:add_target("127.0.0.1", 2120, nil, true)
we.poll()
checker:report_tcp_failure("127.0.0.1", 2120, nil, nil, "passive")
checker:report_tcp_failure("127.0.0.1", 2120, nil, nil, "passive")
checker:report_tcp_failure("127.0.0.1", 2120, nil, nil, "passive")
we.poll()
ngx.say(checker:get_target_status("127.0.0.1", 2120)) -- true
}
}
Expand Down
6 changes: 6 additions & 0 deletions t/08-report_timeout.t
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,12 @@ qq{
ngx.sleep(0.1) -- wait for initial timers to run once
local ok, err = checker:add_target("127.0.0.1", 2122, nil, true)
local ok, err = checker:add_target("127.0.0.1", 2113, nil, true)
we.poll()
checker:report_timeout("127.0.0.1", 2122, nil, "active")
checker:report_timeout("127.0.0.1", 2113, nil, "passive")
checker:report_timeout("127.0.0.1", 2122, nil, "active")
checker:report_timeout("127.0.0.1", 2113, nil, "passive")
we.poll()
ngx.say(checker:get_target_status("127.0.0.1", 2122)) -- false
ngx.say(checker:get_target_status("127.0.0.1", 2113)) -- false
}
Expand Down Expand Up @@ -144,9 +146,11 @@ qq{
})
ngx.sleep(0.1) -- wait for initial timers to run once
local ok, err = checker:add_target("127.0.0.1", 2122, nil, true)
we.poll()
checker:report_timeout("127.0.0.1", 2122, nil, "active")
checker:report_timeout("127.0.0.1", 2122, nil, "active")
checker:report_timeout("127.0.0.1", 2122, nil, "active")
we.poll()
ngx.say(checker:get_target_status("127.0.0.1", 2122)) -- true
}
}
Expand Down Expand Up @@ -213,9 +217,11 @@ qq{
})
ngx.sleep(0.1) -- wait for initial timers to run once
local ok, err = checker:add_target("127.0.0.1", 2122, nil, true)
we.poll()
checker:report_timeout("127.0.0.1", 2122, nil, "passive")
checker:report_timeout("127.0.0.1", 2122, nil, "passive")
checker:report_timeout("127.0.0.1", 2122, nil, "passive")
we.poll()
ngx.say(checker:get_target_status("127.0.0.1", 2122)) -- true
}
}
Expand Down
Loading

0 comments on commit e49622e

Please sign in to comment.