This is an automated email from the ASF dual-hosted git repository.

AlinsRan pushed a commit to branch test/kafka-logger-partition-flaky
in repository https://gitbox.apache.org/repos/asf/apisix.git

commit c8e53b1c22fd88e1d782d7cd1a52b24e689dc87c
Author: AlinsRan <[email protected]>
AuthorDate: Mon Jul 20 11:24:39 2026 +0800

    test(kafka-logger): fix flaky partition distribution assertion
    
    TEST 18 sent exactly three requests to a three-partition topic and required
    all three partition ids to show up. lua-resty-kafka chooses the partition
    with `correlation_id % partition_num`, and the correlation id advances once
    per produce request rather than once per message, so any retry shifts the
    rotation and two messages land on the same partition, leaving an expected
    partition id absent from the error log.
    
    Send six requests instead of three so a transient retry no longer removes a
    partition from the run, and drop the 1s timeout that made those retries
    likely in the first place.
---
 t/plugin/kafka-logger.t | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/t/plugin/kafka-logger.t b/t/plugin/kafka-logger.t
index 6e355ba81..6e04f1ca7 100644
--- a/t/plugin/kafka-logger.t
+++ b/t/plugin/kafka-logger.t
@@ -549,7 +549,6 @@ passed
                                 },
                                 "kafka_topic" : "test3",
                                 "producer_type": "sync",
-                                "timeout" : 1,
                                 "batch_max_size": 1,
                                 "include_req_body": false
                             }
@@ -564,15 +563,17 @@ passed
                 }]]
                 )
 
-            t('/hello',ngx.HTTP_GET)
-            ngx.sleep(0.5)
-            t('/hello',ngx.HTTP_GET)
-            ngx.sleep(0.5)
-            t('/hello',ngx.HTTP_GET)
-            ngx.sleep(0.5)
+            -- lua-resty-kafka picks the partition with `correlation_id % 
partition_num`,
+            -- and the correlation id advances per produce request rather than 
per
+            -- message, so a single retry shifts the rotation. Send more 
requests than
+            -- the partition count so every partition is still covered when 
that happens.
+            for _ = 1, 6 do
+                t('/hello', ngx.HTTP_GET)
+                ngx.sleep(0.2)
+            end
         }
     }
---- timeout: 5s
+--- timeout: 10s
 --- ignore_response
 --- error_log eval
 [qr/partition_id: 1/,

Reply via email to