Skip to content

Commit 3e51cbf

Browse files
authored
feat: add method to close gRPC conn (#196)
1 parent dae03bc commit 3e51cbf

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

lib/resty/etcd/v3.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,12 @@ function _M.new(opts)
458458
end
459459

460460

461+
function _grpc_M.close(self)
462+
self.conn:close()
463+
self.conn = nil
464+
end
465+
466+
461467
local function wake_up_everyone(self)
462468
local count = -self.sema:count()
463469
if count > 0 then

t/v3/grpc/misc.t

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ add_block_preprocessor(sub {
2525
if ((!defined $block->error_log) && (!defined $block->no_error_log)) {
2626
$block->set_value("no_error_log", "[error]");
2727
}
28+
29+
my $http_config = <<'_EOC_';
30+
lua_package_path 'lib/?.lua;/usr/local/share/lua/5.3/?.lua;/usr/share/lua/5.1/?.lua;;';
31+
_EOC_
32+
if (!$block->http_config) {
33+
$block->set_value("http_config", $http_config);
34+
}
2835
});
2936

3037
run_tests();
@@ -47,3 +54,16 @@ init_by_lua_block {
4754
}
4855
}
4956
--- response_body
57+
58+
59+
60+
=== TEST 2: close conn
61+
--- config
62+
location /t {
63+
content_by_lua_block {
64+
local etcd = require "resty.etcd" .new({protocol = "v3", use_grpc = true})
65+
assert(etcd.conn ~= nil)
66+
etcd:close()
67+
assert(etcd.conn == nil)
68+
}
69+
}

0 commit comments

Comments
 (0)