You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2022/04/02 01:54:36 UTC

[GitHub] [apisix] spacewander commented on a change in pull request #6759: feat(xds): using data written by xds to control dp behavior

spacewander commented on a change in pull request #6759:
URL: https://github.com/apache/apisix/pull/6759#discussion_r840991798



##########
File path: t/xds-library/config_xds_2.t
##########
@@ -76,3 +76,166 @@ __DATA__
     }
 --- response_body
 hello world
+
+
+
+=== TEST 2: proxy request using data written by xds(id = 2, upstream_id = 1)
+--- config
+    location /t {
+        content_by_lua_block {
+            local http = require "resty.http"
+            local httpc = http.new()
+            local uri = "http://127.0.0.1:" .. ngx.var.server_port .. "/hello1"
+            local res, err = httpc:request_uri(uri, { method = "GET"})
+
+            if not res then
+                ngx.say(err)
+                return
+            end
+            ngx.print(res.body)
+        }
+    }
+--- response_body
+hello1 world
+
+
+
+=== TEST 3: proxy request using data written by xds(id = 3, upstream_id = 2)
+--- config
+    location /t {
+        content_by_lua_block {
+            ngx.sleep(1.5)
+            local core = require("apisix.core")
+            local value = ngx.shared["xds-config"]:flush_all()
+            ngx.sleep(1.5)
+            local http = require "resty.http"
+            local httpc = http.new()
+            local uri = "http://127.0.0.1:" .. ngx.var.server_port .. "/hello"
+            local res, err = httpc:request_uri(uri, { method = "GET"})
+
+            if not res then
+                ngx.say(err)
+                return
+            end
+            ngx.print(res.body)
+        }
+    }
+--- response_body
+hello world
+
+
+
+=== TEST 4: flush all keys in xds config
+--- config
+    location /t {
+        content_by_lua_block {
+            local core = require("apisix.core")
+            ngx.shared["xds-config"]:flush_all()
+            ngx.update_time()
+            ngx.shared["xds-conf-version"]:set("version", ngx.now())
+            ngx.sleep(1.5)
+
+            local http = require "resty.http"
+            local httpc = http.new()
+            local uri = "http://127.0.0.1:" .. ngx.var.server_port .. "/hello"
+            local res, err = httpc:request_uri(uri, { method = "GET"})
+
+            if not res then
+                ngx.say(err)
+                return
+            end
+            ngx.status = res.status
+            ngx.print(res.body)
+        }
+    }
+--- error_code: 404
+--- response_body
+{"error_msg":"404 Route Not Found"}
+
+
+
+=== TEST 5: bad format json
+--- config
+    location /t {
+        content_by_lua_block {
+            local data = [[{
+                upstream = {
+                    type = "roundrobin"
+                    nodes = {
+                        ["127.0.0.1:1980"] = 1,
+                    }
+                },
+                uri = "/bad_json"
+            }]]
+            ngx.shared["xds-config"]:set("/routes/3", data)
+            ngx.update_time()
+            ngx.shared["xds-conf-version"]:set("version", ngx.now())
+            ngx.sleep(1.5)
+
+            local http = require "resty.http"
+            local httpc = http.new()
+            local uri = "http://127.0.0.1:" .. ngx.var.server_port .. "/bad_json"
+            local res, err = httpc:request_uri(uri, { method = "GET"})
+
+            if not res then
+                ngx.say(err)
+                return
+            end
+            ngx.status = res.status
+        }
+    }
+--- error_code: 404
+--- no_error_log
+[alert]

Review comment:
       Why should we check the alert log? Is there any alert log in the path?

##########
File path: t/xds-library/main.go
##########
@@ -72,7 +72,29 @@ func write_config(config_zone unsafe.Pointer, version_zone unsafe.Pointer) {
 }
 }`)
 
-	write_shdict(key, value, config_zone)
+	upstream_key := "/upstreams/1"
+	upstream_value := fmt.Sprintf(`{
+"id": "1",
+"nodes": {
+	"127.0.0.1:1980": 1
+},
+"type": "roundrobin"
+}`)
+
+	r_u_key := "/routes/2"
+	r_u__value := fmt.Sprintf(`{

Review comment:
       Why not use r_u_value?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org