@@ -134,7 +134,7 @@ failed to get ngx.shared dict: error_shm_name
134134
135135
136136
137- === TEST 4: trigger unhealthy
137+ === TEST 4: trigger unhealthy with set
138138--- http_config eval: $::HttpConfig
139139--- config
140140 location /t {
@@ -157,19 +157,54 @@ failed to get ngx.shared dict: error_shm_name
157157 })
158158
159159 local res, err = etcd:set("/trigger_unhealthy", { a='abc'})
160- ngx.say("done" )
160+ ngx.say(err )
161161 }
162162 }
163163--- request
164164GET /t
165165--- error_log eval
166166qr/update endpoint: http:\/\/127.0.0.1:42379 to unhealthy/
167167--- response_body
168- done
168+ http://127.0.0.1:42379: connection refused
169+
170+
171+
172+ === TEST 5: trigger unhealthy with watch
173+ --- http_config eval: $::HttpConfig
174+ --- config
175+ location /t {
176+ content_by_lua_block {
177+ local health_check, err = require "resty.etcd.health_check" .init({
178+ shm_name = "etcd_cluster_health_check",
179+ fail_timeout = 10,
180+ max_fails = 1,
181+ })
182+
183+ local etcd, err = require "resty.etcd" .new({
184+ protocol = "v3",
185+ http_host = {
186+ "http://127.0.0.1:42379",
187+ "http://127.0.0.1:22379",
188+ "http://127.0.0.1:32379",
189+ },
190+ })
191+
192+ local body_chunk_fun, err = etcd:watch("/trigger_unhealthy")
193+ if not body_chunk_fun then
194+ ngx.say(err)
195+ end
196+ }
197+ }
198+ --- request
199+ GET /t
200+ --- error_log eval
201+ qr/update endpoint: http:\/\/127.0.0.1:42379 to unhealthy/
202+ --- response_body
203+ http://127.0.0.1:42379: connection refused
169204
170205
171206
172- === TEST 5 : fault count
207+ === TEST 6 : fault count
173208--- http_config eval: $::HttpConfig
174209--- config
175210 location /t {
@@ -209,7 +244,7 @@ GET /t
209244
210245
211246
212- === TEST 6 : check endpoint is healthy
247+ === TEST 7 : check endpoint is healthy
213248--- http_config eval: $::HttpConfig
214249--- config
215250 location /t {
@@ -246,7 +281,7 @@ false
246281
247282
248283
249- === TEST 7 : make sure `fail_timeout` works
284+ === TEST 8 : make sure `fail_timeout` works
250285--- http_config eval: $::HttpConfig
251286--- config
252287 location /t {
293328
294329
295330
296- === TEST 8 : has no healthy etcd endpoint, directly return an error message
331+ === TEST 9 : has no healthy etcd endpoint, directly return an error message
297332--- http_config eval: $::HttpConfig
298333--- config
299334 location /t {
@@ -334,7 +369,7 @@ qr/has no healthy etcd endpoint available/
334369
335370
336371
337- === TEST 9 : `health_check` shared by different etcd clients
372+ === TEST 10 : `health_check` shared by different etcd clients
338373--- http_config eval: $::HttpConfig
339374--- config
340375 location /t {
@@ -383,7 +418,7 @@ qr/update endpoint: http:\/\/127.0.0.1:42379 to unhealthy/
383418
384419
385420
386- === TEST 10 : mock etcd error and report fault
421+ === TEST 11 : mock etcd error and report fault
387422--- http_config eval: $::HttpConfig
388423--- config
389424 location /v3/auth/authenticate {
0 commit comments