Skip to content

Commit 1e103ac

Browse files
wu-shengclaude
andcommitted
fix(test): make sw_loguru deterministic under the collector's log sorting
The upgraded collector sorts expected and actual logs by their body text before comparing them pairwise (apache/skywalking-agent-test-tool#59). The two `logging`-module records are matched by `text: not null`, which sorts as that literal string, while the records themselves led with the default layout's timestamp — so they sorted first while their placeholders sorted last, inverting the pairing and failing every field. Pin a layout that leads with the logger name, which sorts after the placeholders and orders the two records deterministically (CRITICAL before ERROR), and reorder the expected entries to match. The formatted path is still exercised, only the field order in the layout changes. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent d55f162 commit 1e103ac

2 files changed

Lines changed: 18 additions & 7 deletions

File tree

tests/plugin/data/sw_loguru/docker-compose.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ services:
4444
SW_AGENT_NAME: provider
4545
SW_AGENT_LOGGING_LEVEL: DEBUG
4646
SW_AGENT_LOG_REPORTER_LEVEL: INFO
47+
# The collector sorts expected and actual logs by their body text before comparing
48+
# them pairwise, so the reported text must order deterministically. The default
49+
# layout leads with the timestamp, which sorts the `logging` records ahead of the
50+
# loguru ones and ahead of the `not null` placeholders they are matched by; leading
51+
# with the logger name keeps them last and stable. See expected.data.yml.
52+
SW_AGENT_LOG_REPORTER_LAYOUT: '%(name)s [%(threadName)s] %(levelname)s - %(message)s'
4753

4854
consumer:
4955
extends:

tests/plugin/data/sw_loguru/expected.data.yml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
# limitations under the License.
1616
#
1717

18+
# The collector sorts expected and actual logs by their body text and then compares them
19+
# pairwise, so the order here is significant. The two loguru records sort by their literal
20+
# text; the two `logging` records are matched by `text: not null`, which sorts after them,
21+
# and among themselves they follow the order the collector sees - CRITICAL before ERROR,
22+
# given the log layout pinned in docker-compose.yml.
1823
logItems:
1924
- serviceName: provider
2025
logSize: 4
@@ -46,17 +51,17 @@ logItems:
4651
body:
4752
type: 'text'
4853
content:
49-
text: not null
54+
text: 'Loguru provider warning reported.'
5055
traceContext:
5156
traceId: not null
5257
traceSegmentId: not null
5358
spanId: 0
5459
tags:
5560
data:
5661
- key: level
57-
value: ERROR
62+
value: WARNING
5863
- key: logger
59-
value: not null
64+
value: loguru
6065
- key: thread
6166
value: not null
6267
layer: ''
@@ -66,17 +71,17 @@ logItems:
6671
body:
6772
type: 'text'
6873
content:
69-
text: 'Loguru provider warning reported.'
74+
text: not null
7075
traceContext:
7176
traceId: not null
7277
traceSegmentId: not null
7378
spanId: 0
7479
tags:
7580
data:
7681
- key: level
77-
value: WARNING
82+
value: CRITICAL
7883
- key: logger
79-
value: loguru
84+
value: not null
8085
- key: thread
8186
value: not null
8287
layer: ''
@@ -94,7 +99,7 @@ logItems:
9499
tags:
95100
data:
96101
- key: level
97-
value: CRITICAL
102+
value: ERROR
98103
- key: logger
99104
value: not null
100105
- key: thread

0 commit comments

Comments
 (0)