mirror of
https://gitee.com/iresty/apisix.git
synced 2024-12-02 12:07:35 +08:00
fix(traffic-split): failed to match rule when the first rule failed (#6292)
Co-authored-by: tangzhenhuang <tangzhenhuang@cvte.com>
This commit is contained in:
parent
3f965c4309
commit
605141cba3
@ -238,6 +238,7 @@ function _M.access(conf, ctx)
|
||||
|
||||
for _, rule in ipairs(conf.rules) do
|
||||
if not rule.match then
|
||||
match_passed = true
|
||||
weighted_upstreams = rule.weighted_upstreams
|
||||
break
|
||||
end
|
||||
|
106
t/plugin/traffic-split5.t
vendored
106
t/plugin/traffic-split5.t
vendored
@ -311,3 +311,109 @@ passed
|
||||
}
|
||||
--- response_body
|
||||
1970, 1970, 1971, 1972, 1972, 1973
|
||||
|
||||
|
||||
|
||||
=== TEST 5: set upstream(multiple rules, the first rule has the match attribute and the second rule does not) and add route
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local json = require("toolkit.json")
|
||||
local t = require("lib.test_admin").test
|
||||
local data = {
|
||||
uri = "/hello",
|
||||
plugins = {
|
||||
["traffic-split"] = {
|
||||
rules = {
|
||||
{
|
||||
match = { {
|
||||
vars = { { "arg_id", "==", "1" } }
|
||||
} },
|
||||
weighted_upstreams = {
|
||||
{
|
||||
upstream = {
|
||||
name = "upstream_A",
|
||||
type = "roundrobin",
|
||||
nodes = {
|
||||
["127.0.0.1:1970"] = 1
|
||||
}
|
||||
},
|
||||
weight = 1
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
weighted_upstreams = {
|
||||
{
|
||||
upstream = {
|
||||
name = "upstream_B",
|
||||
type = "roundrobin",
|
||||
nodes = {
|
||||
["127.0.0.1:1971"] = 1
|
||||
}
|
||||
},
|
||||
weight = 1
|
||||
},
|
||||
{
|
||||
weight = 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
upstream = {
|
||||
type = "roundrobin",
|
||||
nodes = {
|
||||
["127.0.0.1:1972"] = 1
|
||||
}
|
||||
}
|
||||
}
|
||||
local code, body = t('/apisix/admin/routes/1',
|
||||
ngx.HTTP_PUT,
|
||||
json.encode(data)
|
||||
)
|
||||
if code >= 300 then
|
||||
ngx.status = code
|
||||
end
|
||||
ngx.say(body)
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
passed
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 6: first rule match failed and the second rule match success
|
||||
--- 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 .. "/hello?id=1"
|
||||
local ports = {}
|
||||
local res, err
|
||||
for i = 1, 2 do
|
||||
res, err = httpc:request_uri(uri)
|
||||
local port = tonumber(res.body)
|
||||
ports[i] = port
|
||||
end
|
||||
|
||||
local uri = "http://127.0.0.1:" .. ngx.var.server_port .. "/hello?id=2"
|
||||
for i = 3, 4 do
|
||||
res, err = httpc:request_uri(uri)
|
||||
local port = tonumber(res.body)
|
||||
ports[i] = port
|
||||
end
|
||||
table.sort(ports)
|
||||
|
||||
ngx.say(table.concat(ports, ", "))
|
||||
}
|
||||
}
|
||||
--- response_body
|
||||
1970, 1970, 1971, 1972
|
||||
|
Loading…
Reference in New Issue
Block a user