nic-6443 commented on code in PR #13630:
URL: https://github.com/apache/apisix/pull/13630#discussion_r3496700572


##########
t/stream-plugin/traffic-split.t:
##########
@@ -59,8 +59,22 @@ add_block_preprocessor(sub {
                 reqs[i] = { "/hit" }
             end
             local resps = { ngx.location.capture_multi(reqs) }
-            for i, resp in ipairs(resps) do
-                ngx.say(resp.body)
+            -- Count responses per upstream instead of printing them in arrival
+            -- order: the round-robin picker starts at a random node, so the 
order
+            -- the upstreams are hit in is not deterministic, only the ratio 
is.

Review Comment:
   Good catch, reworded — capture_multi returns results in request order, and 
the nondeterministic part is which upstream serves each request, not the print 
order. Updated the comment to say that.



##########
t/stream-plugin/traffic-split.t:
##########
@@ -59,8 +59,22 @@ add_block_preprocessor(sub {
                 reqs[i] = { "/hit" }
             end
             local resps = { ngx.location.capture_multi(reqs) }
-            for i, resp in ipairs(resps) do
-                ngx.say(resp.body)
+            -- Count responses per upstream instead of printing them in arrival
+            -- order: the round-robin picker starts at a random node, so the 
order
+            -- the upstreams are hit in is not deterministic, only the ratio 
is.
+            local count = {}
+            for _, resp in ipairs(resps) do
+                local port = resp.body and resp.body:match("port (%d+)")
+                local key = port and ("port " .. port) or "no response"
+                count[key] = (count[key] or 0) + 1

Review Comment:
   I'll leave this as-is. In this test the weight-1 upstream points at a port 
with no listener, so it can only ever refuse the connection (empty body) — 
there's no code path that returns an unexpected non-empty body here, and the 
`--- error_log: Connection refused` assertion separately confirms that path is 
exercised. Splitting out an "unexpected body" bucket would be defending against 
a case this test can't produce.



-- 
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: [email protected]

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

Reply via email to