This is an automated email from the ASF dual-hosted git repository.

shuyangw pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git


The following commit(s) were added to refs/heads/master by this push:
     new c1f8085  test: add case for default health status (#4378)
c1f8085 is described below

commit c1f80850e52d4ea4f52c5454dbf6bad4dbce5b60
Author: 罗泽轩 <[email protected]>
AuthorDate: Sun Jun 6 05:12:47 2021 +0800

    test: add case for default health status (#4378)
    
    Signed-off-by: spacewander <[email protected]>
---
 t/control/healthcheck.t | 61 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 61 insertions(+)

diff --git a/t/control/healthcheck.t b/t/control/healthcheck.t
index 41fe7f1..707174b 100644
--- a/t/control/healthcheck.t
+++ b/t/control/healthcheck.t
@@ -269,3 +269,64 @@ GET /v1/healthcheck/route/1
 --- error_code: 400
 --- response_body
 {"error_msg":"invalid src type route"}
+
+
+
+=== TEST 7: default health status
+--- apisix_yaml
+routes:
+  -
+    uris:
+        - /hello
+    upstream_id: 1
+upstreams:
+    - nodes:
+        "127.0.0.1:1988": 1
+        "127.0.0.2:1980": 1
+      type: chash
+      id: 1
+      key: "uri"
+      checks:
+        active:
+            http_path: "/status"
+            healthy:
+                interval: 1
+                successes: 1
+            unhealthy:
+                interval: 1
+                http_failures: 1
+#END
+--- config
+    location /t {
+        content_by_lua_block {
+            local json = require("toolkit.json")
+            local t = require("lib.test_admin")
+
+            -- not hit
+            local code, body, res = t.test('/v1/healthcheck',
+                ngx.HTTP_GET)
+            ngx.print(res)
+
+            -- hit, but no enough to mark node to unhealthy
+            local http = require "resty.http"
+            local uri = "http://127.0.0.1:"; .. ngx.var.server_port .. "/hello"
+            local httpc = http.new()
+            local res, err = httpc:request_uri(uri, {method = "GET"})
+            local code, body, res = t.test('/v1/healthcheck',
+                ngx.HTTP_GET)
+            res = json.decode(res)
+            table.sort(res[1].healthy_nodes, function(a, b)
+                return a.host < b.host
+            end)
+            ngx.say(json.encode(res[1].healthy_nodes))
+        }
+    }
+--- grep_error_log eval
+qr/unhealthy TCP increment \(.+\) for '[^']+'/
+--- grep_error_log_out
+unhealthy TCP increment (1/2) for '(127.0.0.1:1988)'
+--- no_error_log
+[error]
+--- response_body
+{}
+[{"host":"127.0.0.1","port":1988,"priority":0,"weight":1},{"host":"127.0.0.2","port":1980,"priority":0,"weight":1}]

Reply via email to