@@ -126,3 +126,66 @@ value: bcd3
126126closed
127127ok
128128--- timeout: 5
129+
130+
131+
132+ === TEST 2: request over unix socket, unix socket doesn't exist
133+ --- http_config eval: $::HttpConfig
134+ --- config
135+ location /t {
136+ content_by_lua_block {
137+ local etcd, err = require("resty.etcd").new({protocol = "v3", http_host = "http://127.0.0.1:2379",
138+ unix_socket_proxy = "unix:$TEST_NGINX_HTML_DIR/bad.sock"})
139+ check_res(etcd, err)
140+
141+ local res, err = etcd:set("/test", "abc")
142+ check_res(res, err)
143+
144+ ngx.timer.at(0.1, function ()
145+ etcd:set("/test", "bcd3")
146+ end)
147+
148+ ngx.timer.at(0.2, function ()
149+ etcd:set("/test", "bcd4")
150+ end)
151+
152+ local cur_time = ngx.now()
153+ local body_chunk_fun, err, http_cli = etcd:watch("/test", {timeout = 0.5, need_cancel = true})
154+
155+ if type(http_cli) ~= "table" then
156+ ngx.say("need_cancel failed")
157+ end
158+
159+ if not body_chunk_fun then
160+ ngx.say("failed to watch: ", err)
161+ end
162+
163+ local chunk, err = body_chunk_fun()
164+ ngx.say("created: ", chunk.result.created)
165+ local chunk, err = body_chunk_fun()
166+ ngx.say("value: ", chunk.result.events[1].kv.value)
167+
168+ local res, err = etcd:watchcancel(http_cli)
169+ if not res then
170+ ngx.say("failed to cancel: ", err)
171+ end
172+
173+ local chunk, err = body_chunk_fun()
174+ ngx.say(err)
175+
176+ ngx.say("ok")
177+ }
178+ }
179+ --- request
180+ GET /t
181+ --- no_error_log
182+ [error]
183+ --- grep_error_log eval
184+ qr/hit with host 127.0.0.1/
185+ --- grep_error_log_out
186+ --- response_body
187+ created: true
188+ value: bcd3
189+ closed
190+ ok
191+ --- timeout: 5
0 commit comments