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 9995d4c81 test(xrpc): fix first-run failures in redis.t and 
prometheus.t (#13507)
9995d4c81 is described below

commit 9995d4c81cc8831251b3b33bc251c7bffce5dfd4
Author: Nic <[email protected]>
AuthorDate: Thu Jun 11 10:14:12 2026 +0800

    test(xrpc): fix first-run failures in redis.t and prometheus.t (#13507)
---
 t/xrpc/prometheus.t | 9 +++++++++
 t/xrpc/redis.t      | 7 ++++++-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/t/xrpc/prometheus.t b/t/xrpc/prometheus.t
index cc267ac6c..c58971922 100644
--- a/t/xrpc/prometheus.t
+++ b/t/xrpc/prometheus.t
@@ -145,9 +145,18 @@ passed
                 ngx.say("failed to get animals: ", err)
                 return
             end
+
+            -- metrics are accumulated in a per-worker counter and flushed
+            -- to the shared dict by an ngx.timer.every(1, ...); once this
+            -- block ends, the only remaining flush is the premature timer
+            -- run when the HUP reload retires the stream worker, which races
+            -- with (and can lose to) the next block's scrape. Wait for a
+            -- regular flush before the block ends instead.
+            ngx.sleep(2)
         }
     }
 --- response_body
+--- timeout: 5
 --- stream_conf_enable
 
 
diff --git a/t/xrpc/redis.t b/t/xrpc/redis.t
index f9cff50a7..18447472b 100644
--- a/t/xrpc/redis.t
+++ b/t/xrpc/redis.t
@@ -242,7 +242,12 @@ hget animals: bark
                     local begin = tonumber(results[3])
                     for j = 1, 4 do
                         local incred = results[3 + j]
-                        if incred ~= results[2 + j] + 1 then
+                        -- on a fresh redis the first pipeline's GET returns
+                        -- ngx.null (the counter doesn't exist yet), skip the
+                        -- comparison for it instead of doing arithmetic on a
+                        -- userdata value
+                        local prev = tonumber(results[2 + j])
+                        if prev and incred ~= prev + 1 then
                             ngx.log(ngx.ERR, cjson.encode(results))
                         end
                     end

Reply via email to