Skip to content

Commit

Permalink
fix(traffic-split): upstream_obj.upstream should not be a string (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
shreemaan-abhishek authored Jan 22, 2025
1 parent 6a84576 commit 0cb7d9a
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 2 deletions.
3 changes: 1 addition & 2 deletions apisix/plugins/traffic-split.lua
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,7 @@ local function new_rr_obj(weighted_upstreams)
-- If the upstream object has only the weight value, it means
-- that the upstream weight value on the default route has been reached.
-- Mark empty upstream services in the plugin.
upstream_obj.upstream = "plugin#upstream#is#empty"
server_list[upstream_obj.upstream] = upstream_obj.weight
server_list["plugin#upstream#is#empty"] = upstream_obj.weight

end
end
Expand Down
99 changes: 99 additions & 0 deletions t/plugin/traffic-split5.t
Original file line number Diff line number Diff line change
Expand Up @@ -535,3 +535,102 @@ id=1
Content-Type: application/x-www-form-urlencoded;charset=UTF-8
--- response_body
1970
=== TEST 12: failure after plugin reload
--- extra_yaml_config
nginx_config:
worker_processes: 1
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/upstreams/1',
ngx.HTTP_PUT,
[[{
"type": "roundrobin",
"nodes": {
"127.0.0.1:1970":10
}
}]]
)
if code >= 300 then
ngx.status = code
ngx.say(body)
return
end
local code, body = t('/apisix/admin/upstreams/2',
ngx.HTTP_PUT,
[[{
"type": "roundrobin",
"nodes": {
"127.0.0.1:1971":10
}
}]]
)
if code >= 300 then
ngx.status = code
ngx.say(body)
return
end
local code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
[[{
"uri": "/hello",
"plugins": {
"traffic-split": {
"rules": [
{
"weighted_upstreams": [
{
"upstream_id": "2",
"weight": 1
},
{
"weight": 1
}
]
}
]
}
},
"upstream_id": "1"
}]]
)
if code >= 300 then
ngx.status = code
return
end
local code, body = t('/hello')
if code >= 300 then
ngx.status = code
ngx.say(body)
return
end
local code, body = t('/apisix/admin/plugins/reload', ngx.HTTP_PUT)
if code >= 300 then
ngx.status = code
ngx.say(body)
return
end
local code, body = t('/hello')
if code >= 300 then
ngx.status = code
ngx.say(body)
return
end
ngx.say("passed.")
}
}
--- request
GET /t
--- response_body
passed.

0 comments on commit 0cb7d9a

Please sign in to comment.