Skip to content

Commit 4a208ec

Browse files
authored
Add travis config (#37)
* Add travis config lifted from lua-resty-redis * Fix up makefile and test files to make proper use of environment * Add build status to readme
1 parent a167edd commit 4a208ec

File tree

7 files changed

+152
-57
lines changed

7 files changed

+152
-57
lines changed

.travis.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
sudo: required
2+
dist: trusty
3+
4+
os: linux
5+
6+
language: c
7+
8+
compiler: gcc
9+
10+
addons:
11+
apt:
12+
packages:
13+
- luarocks
14+
- redis
15+
- lsof
16+
17+
cache:
18+
directories:
19+
- download-cache
20+
21+
env:
22+
global:
23+
- JOBS=3
24+
- NGX_BUILD_JOBS=$JOBS
25+
- LUAJIT_PREFIX=/opt/luajit21
26+
- LUAJIT_LIB=$LUAJIT_PREFIX/lib
27+
- LUAJIT_INC=$LUAJIT_PREFIX/include/luajit-2.1
28+
- LUA_INCLUDE_DIR=$LUAJIT_INC
29+
- OPENSSL_PREFIX=/opt/ssl
30+
- OPENSSL_LIB=$OPENSSL_PREFIX/lib
31+
- OPENSSL_INC=$OPENSSL_PREFIX/include
32+
- OPENSSL_VER=1.1.1f
33+
- LD_LIBRARY_PATH=$LUAJIT_LIB:$LD_LIBRARY_PATH
34+
- TEST_NGINX_SLEEP=0.006
35+
- LUACHECK_VER=0.21.1
36+
jobs:
37+
- NGINX_VERSION=1.17.8
38+
39+
before_install:
40+
- sudo luarocks install luacov
41+
- sudo luarocks install lua-resty-redis
42+
- sudo luarocks install luacheck $LUACHECK_VER
43+
- luacheck -q .
44+
45+
install:
46+
- if [ ! -d download-cache ]; then mkdir download-cache; fi
47+
- if [ ! -f download-cache/openssl-$OPENSSL_VER.tar.gz ]; then wget -O download-cache/openssl-$OPENSSL_VER.tar.gz https://www.openssl.org/source/openssl-$OPENSSL_VER.tar.gz; fi
48+
- sudo apt-get install -qq -y cpanminus axel
49+
- sudo cpanm --notest Test::Nginx > build.log 2>&1 || (cat build.log && exit 1)
50+
- git clone https://github.com/openresty/openresty.git ../openresty
51+
- git clone https://github.com/openresty/nginx-devel-utils.git
52+
- git clone https://github.com/openresty/lua-cjson.git
53+
- git clone https://github.com/openresty/lua-nginx-module.git ../lua-nginx-module
54+
- git clone https://github.com/openresty/stream-lua-nginx-module.git ../stream-lua-nginx-module
55+
- git clone https://github.com/openresty/lua-resty-core.git ../lua-resty-core
56+
- git clone https://github.com/openresty/lua-resty-lrucache.git ../lua-resty-lrucache
57+
- git clone https://github.com/openresty/echo-nginx-module.git ../echo-nginx-module
58+
- git clone https://github.com/openresty/no-pool-nginx.git ../no-pool-nginx
59+
- git clone -b v2.1-agentzh https://github.com/openresty/luajit2.git
60+
61+
script:
62+
- sudo iptables -A OUTPUT -p tcp --dst 127.0.0.2 --dport 12345 -j DROP
63+
- cd luajit2/
64+
- make -j$JOBS CCDEBUG=-g Q= PREFIX=$LUAJIT_PREFIX CC=$CC XCFLAGS='-DLUA_USE_APICHECK -DLUA_USE_ASSERT' > build.log 2>&1 || (cat build.log && exit 1)
65+
- sudo make install PREFIX=$LUAJIT_PREFIX > build.log 2>&1 || (cat build.log && exit 1)
66+
- cd ../lua-cjson && make && sudo PATH=$PATH make install && cd ..
67+
- tar zxf download-cache/openssl-$OPENSSL_VER.tar.gz
68+
- cd openssl-$OPENSSL_VER/
69+
- ./config shared --prefix=$OPENSSL_PREFIX -DPURIFY > build.log 2>&1 || (cat build.log && exit 1)
70+
- make -j$JOBS > build.log 2>&1 || (cat build.log && exit 1)
71+
- sudo make PATH=$PATH install_sw > build.log 2>&1 || (cat build.log && exit 1)
72+
- cd ..
73+
- export PATH=$PWD/work/nginx/sbin:$PWD/nginx-devel-utils:$PATH
74+
- export NGX_BUILD_CC=$CC
75+
- ngx-build $NGINX_VERSION --with-ipv6 --with-http_realip_module --with-http_ssl_module --with-cc-opt="-I$OPENSSL_INC" --with-ld-opt="-L$OPENSSL_LIB -Wl,-rpath,$OPENSSL_LIB" --add-module=../echo-nginx-module --add-module=../lua-nginx-module --add-module=../stream-lua-nginx-module --with-stream --with-stream_ssl_module --with-debug > build.log 2>&1 || (cat build.log && exit 1)
76+
- nginx -V
77+
- ldd `which nginx`|grep -E 'luajit|ssl|pcre'
78+
- mkdir -p tmp
79+
- TMP_DIR=$PWD/tmp make test_all

Makefile

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ SHELL := /bin/bash # Cheat by using bash :)
33
OPENRESTY_PREFIX = /usr/local/openresty
44

55
TEST_FILE ?= t
6+
TMP_DIR ?= /tmp
67
SENTINEL_TEST_FILE ?= $(TEST_FILE)/sentinel
78

89
REDIS_CMD = redis-server
@@ -11,41 +12,51 @@ SENTINEL_CMD = $(REDIS_CMD) --sentinel
1112
REDIS_SOCK = /redis.sock
1213
REDIS_PID = /redis.pid
1314
REDIS_LOG = /redis.log
14-
REDIS_PREFIX = /tmp/redis-
15+
REDIS_PREFIX = $(TMP_DIR)/redis-
1516

1617
# Overrideable redis test variables
17-
TEST_REDIS_PORTS ?= 6379 6380 6378
18-
TEST_REDIS_DATABASE ?= 1
18+
TEST_REDIS_PORT ?= 6380
19+
TEST_REDIS_PORT_SL1 ?= 6381
20+
TEST_REDIS_PORT_SL2 ?= 6382
21+
TEST_REDIS_PORTS ?= $(TEST_REDIS_PORT) $(TEST_REDIS_PORT_SL1) $(TEST_REDIS_PORT_SL2)
22+
TEST_REDIS_DATABASE ?= 1
23+
TEST_REDIS_SOCKET ?= $(REDIS_PREFIX)$(TEST_REDIS_PORT)$(REDIS_SOCK)
1924

20-
REDIS_FIRST_PORT := $(firstword $(TEST_REDIS_PORTS))
21-
REDIS_SLAVE_ARG := --slaveof 127.0.0.1 $(REDIS_FIRST_PORT)
22-
REDIS_CLI := redis-cli -p $(REDIS_FIRST_PORT) -n $(TEST_REDIS_DATABASE)
23-
24-
# Override socket for running make test on its own
25-
# (make test TEST_REDIS_SOCKET=/path/to/sock.sock)
26-
TEST_REDIS_SOCKET ?= $(REDIS_PREFIX)$(REDIS_FIRST_PORT)$(REDIS_SOCK)
25+
REDIS_SLAVE_ARG := --slaveof 127.0.0.1 $(TEST_REDIS_PORT)
26+
REDIS_CLI := redis-cli -p $(TEST_REDIS_PORT) -n $(TEST_REDIS_DATABASE)
2727

2828
# Overrideable redis + sentinel test variables
29-
TEST_SENTINEL_PORTS ?= 6381 6382 6383
29+
TEST_SENTINEL_PORT1 ?= 6390
30+
TEST_SENTINEL_PORT2 ?= 6391
31+
TEST_SENTINEL_PORT3 ?= 6392
32+
TEST_SENTINEL_PORTS ?= $(TEST_SENTINEL_PORT1) $(TEST_SENTINEL_PORT2) $(TEST_SENTINEL_PORT3)
3033
TEST_SENTINEL_MASTER_NAME ?= mymaster
3134
TEST_SENTINEL_PROMOTION_TIME ?= 20
3235

3336
# Command line arguments for redis tests
3437
TEST_REDIS_VARS = PATH=$(OPENRESTY_PREFIX)/nginx/sbin:$(PATH) \
35-
TEST_NGINX_REDIS_SOCKET=unix://$(TEST_REDIS_SOCKET) \
36-
TEST_REDIS_DATABASE=$(TEST_REDIS_DATABASE) \
38+
TEST_NGINX_REDIS_PORT=$(TEST_REDIS_PORT) \
39+
TEST_NGINX_REDIS_PORT_SL1=$(TEST_REDIS_PORT_SL1) \
40+
TEST_NGINX_REDIS_PORT_SL2=$(TEST_REDIS_PORT_SL2) \
41+
TEST_NGINX_REDIS_SOCKET=unix:$(TEST_REDIS_SOCKET) \
42+
TEST_NGINX_REDIS_DATABASE=$(TEST_REDIS_DATABASE) \
3743
TEST_NGINX_NO_SHUFFLE=1
3844

3945
# Command line arguments for sentinel tests
4046
TEST_SENTINEL_VARS = PATH=$(OPENRESTY_PREFIX)/nginx/sbin:$(PATH) \
41-
TEST_SENTINEL_PORT=$(firstword $(TEST_SENTINEL_PORTS)) \
42-
TEST_SENTINEL_MASTER_NAME=$(TEST_SENTINEL_MASTER_NAME) \
43-
TEST_REDIS_DATABASE=$(TEST_REDIS_DATABASE) \
47+
TEST_NGINX_REDIS_PORT=$(TEST_NGINX_REDIS_PORT) \
48+
TEST_NGINX_REDIS_PORT_SL1=$(TEST_NGINX_REDIS_PORT_SL1) \
49+
TEST_NGINX_REDIS_PORT_SL2=$(TEST_NGINX_REDIS_PORT_SL2) \
50+
TEST_NGINX_SENTINEL_PORT1=$(TEST_NGINX_SENTINEL_PORT1) \
51+
TEST_NGINX_SENTINEL_PORT2=$(TEST_NGINX_SENTINEL_PORT2) \
52+
TEST_NGINX_SENTINEL_PORT3=$(TEST_NGINX_SENTINEL_PORT3) \
53+
TEST_NGINX_SENTINEL_MASTER_NAME=$(TEST_NGINX_SENTINEL_MASTER_NAME) \
54+
TEST_NGINX_REDIS_DATABASE=$(TEST_NGINX_REDIS_DATABASE) \
4455
TEST_NGINX_NO_SHUFFLE=1
4556

4657
# Sentinel configuration can only be set by a config file
4758
define TEST_SENTINEL_CONFIG
48-
sentinel monitor $(TEST_SENTINEL_MASTER_NAME) 127.0.0.1 $(REDIS_FIRST_PORT) 2
59+
sentinel monitor $(TEST_SENTINEL_MASTER_NAME) 127.0.0.1 $(TEST_REDIS_PORT) 2
4960
sentinel down-after-milliseconds $(TEST_SENTINEL_MASTER_NAME) 2000
5061
sentinel failover-timeout $(TEST_SENTINEL_MASTER_NAME) 10000
5162
sentinel parallel-syncs $(TEST_SENTINEL_MASTER_NAME) 5
@@ -83,8 +94,10 @@ sleep:
8394
sleep 3
8495

8596
start_redis_instances: check_ports create_sentinel_config
97+
$(REDIS_CMD) --version
98+
8699
@$(foreach port,$(TEST_REDIS_PORTS), \
87-
[[ "$(port)" != "$(REDIS_FIRST_PORT)" ]] && \
100+
[[ "$(port)" != "$(TEST_REDIS_PORT)" ]] && \
88101
SLAVE="$(REDIS_SLAVE_ARG)" || \
89102
SLAVE="" && \
90103
$(MAKE) start_redis_instance args="$$SLAVE" port=$(port) \
@@ -97,7 +110,6 @@ start_redis_instances: check_ports create_sentinel_config
97110
prefix=$(REDIS_PREFIX)$(port) && \
98111
) true
99112

100-
101113
stop_redis_instances: delete_sentinel_config
102114
-@$(foreach port,$(TEST_REDIS_PORTS) $(TEST_SENTINEL_PORTS), \
103115
$(MAKE) stop_redis_instance cleanup_redis_instance port=$(port) \
@@ -108,7 +120,7 @@ stop_redis_instances: delete_sentinel_config
108120
start_redis_instance:
109121
-@echo "Starting redis on port $(port) with args: \"$(args)\""
110122
-@mkdir -p $(prefix)
111-
@$(REDIS_CMD) $(args) \
123+
$(REDIS_CMD) $(args) \
112124
--pidfile $(prefix)$(REDIS_PID) \
113125
--bind 127.0.0.1 --port $(port) \
114126
--unixsocket $(prefix)$(REDIS_SOCK) \

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# lua-resty-redis-connector
22

3+
[![Build Status](https://travis-ci.org/ledgetech/lua-resty-redis-connector.svg?branch=master)](https://travis-ci.org/ledgetech/lua-resty-redis-connector)
4+
35
Connection utilities for [lua-resty-redis](https://github.com/openresty/lua-resty-redis), making it easy and reliable to connect to Redis hosts, either directly or via [Redis Sentinel](http://redis.io/topics/sentinel).
46

57

lib/resty/redis/connector.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ function _M.connect_via_sentinel(self, params)
230230
local password = params.password
231231
local sentinel_password = params.sentinel_password
232232
if sentinel_password then
233-
for i,host in ipairs(sentinels) do
233+
for _,host in ipairs(sentinels) do
234234
host.password = sentinel_password
235235
end
236236
end

t/config.t

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ location /t {
4848
content_by_lua_block {
4949
local config = {
5050
connect_timeout = 500,
51-
port = 6380,
51+
port = $TEST_NGINX_REDIS_PORT,
5252
db = 6,
5353
}
5454
local rc = require("resty.redis.connector").new(config)
@@ -72,7 +72,7 @@ location /t {
7272
content_by_lua_block {
7373
local rc = require("resty.redis.connector").new({
7474
connect_timeout = 500,
75-
port = 6380,
75+
port = $TEST_NGINX_REDIS_PORT,
7676
db = 6,
7777
keepalive_poolsize = 10,
7878
})
@@ -84,7 +84,7 @@ location /t {
8484
assert(rc.config.keepalive_poolsize == 10,
8585
"keepalive_poolsize should be 10")
8686

87-
local redis = assert(rc:connect({ port = 6379, disabled_commands = {"set"} }),
87+
local redis = assert(rc:connect({ port = $TEST_NGINX_REDIS_PORT, disabled_commands = {"set"} }),
8888
"rc:connect should return positively")
8989

9090
local ok, err = redis:set("foo", "bar")
@@ -104,7 +104,7 @@ location /t {
104104
content_by_lua_block {
105105
local rc, err = require("resty.redis.connector").new({
106106
connect_timeout = 500,
107-
port = 6380,
107+
port = $TEST_NGINX_REDIS_PORT,
108108
db = 6,
109109
foo = "bar",
110110
})
@@ -123,7 +123,7 @@ location /t {
123123
keepalive_poolsize = 30,
124124

125125
host = "127.0.0.1",
126-
port = 6379,
126+
port = $TEST_NGINX_REDIS_PORT,
127127
path = "",
128128
password = "",
129129
db = 0,
@@ -147,7 +147,7 @@ location /t {
147147
keepalive_poolsize = 30,
148148

149149
host = "127.0.0.1",
150-
port = 6379,
150+
port = $TEST_NGINX_REDIS_PORT,
151151
path = "",
152152
password = "",
153153
db = 0,

t/connector.t

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,15 +240,13 @@ GET /t
240240
location /t {
241241
lua_socket_log_errors Off;
242242
content_by_lua_block {
243-
ngx.log (ngx.DEBUG, "$TEST_NGINX_REDIS_SOCKET")
244243
local redis, err = require("resty.redis.connector").new({
245244
path = "$TEST_NGINX_REDIS_SOCKET",
246245
}):connect()
247246

248247
assert (redis and not err,
249248
"connection should be valid")
250249

251-
252250
redis:close()
253251
}
254252
}
@@ -318,7 +316,7 @@ location /t {
318316
local rc = require("resty.redis.connector")
319317

320318
local user_params = {
321-
url = "redis://foo@127.0.0.1:6381/4",
319+
url = "redis://foo@127.0.0.1:$TEST_NGINX_REDIS_PORT/4",
322320
db = 2,
323321
password = "bar",
324322
host = "example.com",
@@ -332,7 +330,7 @@ location /t {
332330
assert(params.password == "bar", "password should be bar")
333331
assert(params.host == "example.com", "host should be example.com")
334332

335-
assert(tonumber(params.port) == 6381, "ort should still be 6381")
333+
assert(tonumber(params.port) == $TEST_NGINX_REDIS_PORT, "port should still be $TEST_NGINX_REDIS_PORT")
336334

337335
}
338336
}

0 commit comments

Comments
 (0)