test(error-log-logger): don't assert a fixed JSON key order for the broker list#13703
Open
nic-6443 wants to merge 1 commit into
Open
test(error-log-logger): don't assert a fixed JSON key order for the broker list#13703nic-6443 wants to merge 1 commit into
nic-6443 wants to merge 1 commit into
Conversation
…roker list
TEST 10 matches the broker list the plugin logs against a literal
`[{"host":"127.0.0.1","port":9093}]`. The plugin builds that string with
`core.json.delay_encode(config.kafka.brokers)`, and cjson serialises a Lua
table in hash order, which is not stable across runs. When the encoder emits
`[{"port":9093,"host":"127.0.0.1"}]` instead, the pattern misses and the
block fails.
Match the host and the port as two independent patterns so the assertion
holds whatever order the encoder picks, without weakening what it checks.
Observed over 12 runs of the block before the change: 9 runs encoded
host-first and passed, 3 encoded port-first and failed. With the change, 14
runs pass, 3 of which encoded port-first.
AlinsRan
approved these changes
Jul 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
t/plugin/error-log-logger-kafka.tTEST 10 fails intermittently, for example in this run:This is not a timing problem. The block asserts the broker list against a literal string:
qr/sending a batch logs to kafka brokers: \[\{"host":"127.0.0.1","port":9093\}\]/but the plugin produces it with
core.json.delay_encode(config.kafka.brokers)(apisix/plugins/error-log-logger.lua:391), and cjson serialises a Lua table in hash order. That order is not stable between runs, so the encoder sometimes emits the keys the other way round and the pattern misses a line that is present.Running the block 12 times shows both encodings:
The giveaway in a failing run is that the later message matches while the batch line does not, which cannot happen if the line were merely late:
Change
Match the host and the port as two independent patterns, so the assertion holds whatever order the encoder picks and still checks both values. This follows the same order-tolerant style already used in TEST 2 of this file (
qr/broker_config is: \{.*"refresh_interval":1000/).How this was verified
Against a local kafka with the TLS listener from #13607, running the block in isolation:
Raising
--- waitdoes not fix this — I tried it, and a run still failed with the batch line flushed 1s after the error was logged, well inside the window.Checklist