Skip to content

Commit f4980f0

Browse files
committed
fix(dshm/memcached): add a missing return parameter as otherwise pool parameters are not respected
### Summary @oldium resported this issue in #171.
1 parent 8b5f875 commit f4980f0

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed

lib/resty/session/dshm.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ function storage.new(configuration)
309309
local server_name = configuration and configuration.server_name
310310

311311
if pool or pool_size or backlog then
312-
setmetatable({
312+
return setmetatable({
313313
prefix = prefix,
314314
suffix = suffix,
315315
host = host,

lib/resty/session/memcached.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ function storage.new(configuration)
354354
local server_name = configuration and configuration.server_name
355355

356356
if pool or pool_size or backlog then
357-
setmetatable({
357+
return setmetatable({
358358
prefix = prefix,
359359
suffix = suffix,
360360
host = host,

spec/01-utils_spec.lua

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,50 @@ describe("Testing utils", function()
136136
end
137137
end)
138138
end)
139+
describe("load_storage", function()
140+
-- "dshm" is disabled as it currently cannot be checked by CI
141+
for _, strategy in ipairs({ "memcached", "mysql", "postgres", "redis" }) do
142+
it("respects pool parameters #" .. strategy, function()
143+
local storage = assert(utils.load_storage(strategy, {
144+
[strategy] = {
145+
pool = "doge",
146+
pool_size = 10,
147+
backlog = 20,
148+
},
149+
}))
150+
151+
assert.equal("doge", storage.options.pool)
152+
assert.equal(10, storage.options.pool_size)
153+
assert.equal(20, storage.options.backlog)
154+
end)
155+
end
156+
it("respects pool parameters #redis-sentinel", function()
157+
local storage = assert(utils.load_storage("redis", {
158+
redis = {
159+
pool = "doge",
160+
pool_size = 10,
161+
backlog = 20,
162+
sentinels = {},
163+
},
164+
}))
165+
166+
assert.equal("doge", storage.connector.config.connection_options.pool)
167+
assert.equal(10, storage.connector.config.connection_options.pool_size)
168+
assert.equal(20, storage.connector.config.connection_options.backlog)
169+
end)
170+
it("respects pool parameters #redis-cluster", function()
171+
local storage = assert(utils.load_storage("redis", {
172+
redis = {
173+
pool = "doge",
174+
pool_size = 10,
175+
backlog = 20,
176+
nodes = {},
177+
},
178+
}))
179+
180+
assert.equal("doge", storage.options.connect_opts.pool)
181+
assert.equal(10, storage.options.connect_opts.pool_size)
182+
assert.equal(20, storage.options.connect_opts.backlog)
183+
end)
184+
end)
139185
end)

0 commit comments

Comments
 (0)