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



##########
File path: t/plugin/traffic-split2.t
##########
@@ -311,3 +311,93 @@ host: localhost
 x-real-ip: 127.0.0.1
 --- no_error_log
 [error]
+
+
+
+=== TEST 10: the upstream.type is `chash` and `key` is header
+--- config
+    location /t {
+        content_by_lua_block {
+            local t = require("lib.test_admin").test
+            local code, body = t('/apisix/admin/routes/1',
+                ngx.HTTP_PATCH,
+                [=[{
+                    "uri": "/server_port",
+                    "plugins": {
+                        "traffic-split": {
+                            "rules": [
+                                {
+                                    "weighted_upstreams": [
+                                        {
+                                            "upstream": {
+                                                "name": "chash_test",
+                                                "type": "chash",
+                                                "hash_on": "header",
+                                                "key": "custom_header",
+                                                "nodes": {
+                                                    "127.0.0.1:1981":1,
+                                                    "127.0.0.1:1982":1
+                                                }
+                                            },
+                                            "weight": 1
+                                        }
+                                    ]
+                                }
+                            ]
+                        }
+                    },
+                    "upstream": {
+                            "type": "roundrobin",
+                            "nodes": {
+                                "127.0.0.1:1980": 1
+                            }
+                    }
+                }]=]
+            )
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 11: hit routes, hash_on custom header
+--- config
+location /t {
+    content_by_lua_block {
+        local t = require("lib.test_admin").test
+        local bodys = {}
+        local headers = {}
+        headers["custom_header"] = "custom-one"
+        for i = 1, 4 do
+            local _, _, body = t('/server_port', ngx.HTTP_GET, "", nil, 
headers)
+            bodys[i] = body
+        end
+
+        table.sort(bodys)
+        ngx.say(table.concat(bodys, ", "))
+    }
+}
+--- request
+GET /t
+--- response_body eval
+qr/1981, 1981, 1981, 1981|1982, 1982, 1982, 1982/

Review comment:
       Since we only use `custom-one` as the key, in what situation 1982 will 
be used?




-- 
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.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to