Skip to content

Commit cae2f96

Browse files
committed
test(sentinel) modified test syntax
1 parent 1a36a0e commit cae2f96

File tree

1 file changed

+20
-27
lines changed

1 file changed

+20
-27
lines changed

t/sentinel.t

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -53,42 +53,35 @@ GET /t
5353
--- config
5454
location /t {
5555
content_by_lua_block {
56-
local redis_connector = require "resty.redis.connector"
57-
local rc = redis_connector.new()
56+
local rc = require("resty.redis.connector").new()
5857
5958
local sentinel, err = rc:connect{ url = "redis://127.0.0.1:6381" }
60-
if not sentinel then
61-
ngx.say("failed to connect: ", err)
62-
return
63-
end
64-
65-
local redis_sentinel = require "resty.redis.sentinel"
66-
67-
local slaves, err = redis_sentinel.get_slaves(sentinel, "mymaster")
68-
if not slaves then
69-
ngx.say(err)
70-
else
71-
-- order is undefined
72-
local all = {}
73-
for i,slave in ipairs(slaves) do
74-
all[i] = tonumber(slave.port)
75-
end
76-
table.sort(all)
77-
for _,p in ipairs(all) do
78-
ngx.say(p)
79-
end
80-
end
59+
assert(sentinel and not err, "sentinel should connect without error")
60+
61+
local slaves, err = require("resty.redis.sentinel").get_slaves(
62+
sentinel,
63+
"mymaster"
64+
)
65+
66+
assert(slaves and not err, "slaves should be returned without error")
67+
68+
local slaveports = { ["6378"] = false, ["6380"] = false }
69+
70+
for _,slave in ipairs(slaves) do
71+
slaveports[tostring(slave.port)] = true
72+
end
73+
74+
assert(slaveports["6378"] == true and slaveports["6380"] == true,
75+
"slaves should both be found")
8176
8277
sentinel:close()
8378
}
8479
}
8580
--- request
86-
GET /t
87-
--- response_body
88-
6378
89-
6380
81+
GET /t
9082
--- no_error_log
9183
[error]
84+
--- ONLY
9285
9386
9487
=== TEST 3: Get only healthy slaves

0 commit comments

Comments
 (0)