This is an automated email from the ASF dual-hosted git repository.
nic-6443 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 52ba4bf259 test(upstream): assert the ramp start when a node rejoins
(#14254)
52ba4bf259 is described below
commit 52ba4bf2594b51d77d2a18ff1cc2af3e751676e9
Author: Nic <[email protected]>
AuthorDate: Tue Nov 24 16:13:04 2026 +0800
test(upstream): assert the ramp start when a node rejoins (#14254)
---
t/node/upstream-slow-start.t | 51 +++++++++++++++++---------------------------
1 file changed, 19 insertions(+), 32 deletions(-)
diff --git a/t/node/upstream-slow-start.t b/t/node/upstream-slow-start.t
index 5d8a01ee94..64e755960c 100644
--- a/t/node/upstream-slow-start.t
+++ b/t/node/upstream-slow-start.t
@@ -294,17 +294,9 @@ slow start finished for node 127.0.0.1:1981
)
end
- local function split(times)
- local ports = {}
- for _ = 1, times do
- local httpc = http.new()
- local res, err = httpc:request_uri(uri)
- if not res then
- return nil, err
- end
- ports[res.body] = (ports[res.body] or 0) + 1
- end
- return ports
+ local function request()
+ local res = assert(http.new():request_uri(uri))
+ assert(res.status == 200, res.status)
end
local one = [=[[{"host": "127.0.0.1", "port": 1980, "weight":
100}]]=]
@@ -335,37 +327,32 @@ slow start finished for node 127.0.0.1:1981
end
ngx.sleep(0.5)
- split(1)
+ request()
-- 1981 joins and starts its ramp
set_upstream(two)
ngx.sleep(0.5)
- split(1)
+ request()
+
+ local dict = ngx.shared["upstream-slow-start"]
+ local upstream = require("apisix.upstream").get_by_id(2)
+ local key = upstream.resource_key .. "|127.0.0.1:1981"
+ local original_start = assert(dict:get(key))
+ assert(original_start > 0, "node did not start its first ramp")
- -- it leaves, and comes back well inside the 20s window
set_upstream(one)
ngx.sleep(0.5)
- split(1)
- ngx.sleep(4)
+ request()
+
+ local readded_at = ngx.now()
set_upstream(two)
ngx.sleep(0.5)
+ request()
- local ports, err = split(100)
- if not ports then
- ngx.say(err)
- return
- end
-
- -- whatever answers on 1981 now may have just started, so it ramps
- -- from the first bucket again, a twentieth of the weight. Resuming
- -- the ramp it had would have given it about a quarter
- local mature, warming = ports["1980"] or 0, ports["1981"] or 0
- ngx.log(ngx.WARN, "re-added split: 1980=", mature, " 1981=",
warming)
- if warming >= 1 and warming <= 10 then
- ngx.say("passed")
- else
- ngx.say("failed: 1980=", mature, " 1981=", warming)
- end
+ local new_start = assert(dict:get(key))
+ assert(new_start >= readded_at, "node resumed its old ramp")
+ assert(new_start - original_start < 20, "first ramp already
expired")
+ ngx.say("passed")
}
}
--- response_body