Skip to content

Commit 853e7b0

Browse files
wu-shengclaude
andcommitted
fix(test): seed the mock collector before concurrent same-service reports
The mock collector's first-ever insert for a service name is a check-then-act race (SegmentItems.addSegmentItem): when the fork test's parent and child post their first segments concurrently under the same service name, one segment is silently dropped while both reporters get HTTP 200 — reproduced 15/200 with barrier-synchronized first POSTs and 0/200 once the key exists. This was the remaining sw_fork_support CI flake (either side's segment could vanish, transport-independent). Seed the service name via a parent-only /ping warm-up (which also serves as the readiness probe) before /users triggers the concurrent pair; the expected data now validates all three segments. The real fix belongs in skywalking-agent-test-tool (computeIfAbsent) and an image repin. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 04aaa9a commit 853e7b0

3 files changed

Lines changed: 35 additions & 2 deletions

File tree

tests/plugin/web/sw_fork_support/expected.data.yml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,27 @@
1717

1818
segmentItems:
1919
- serviceName: provider
20-
segmentSize: 2
20+
segmentSize: 3
2121
segments:
22+
- segmentId: not null
23+
spans:
24+
- operationName: /ping
25+
parentSpanId: -1
26+
spanId: 0
27+
spanLayer: Http
28+
tags:
29+
- key: http.method
30+
value: GET
31+
- key: http.url
32+
value: http://0.0.0.0:9090/ping
33+
- key: http.status_code
34+
value: '200'
35+
startTime: gt 0
36+
endTime: gt 0
37+
componentId: 7001
38+
spanType: Entry
39+
peer: not null
40+
skipAnalysis: false
2241
- segmentId: not null
2342
spans:
2443
- operationName: /users

tests/plugin/web/sw_fork_support/services/app.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ def users():
5050

5151
frontend = Flask('frontend')
5252

53+
# readiness/warm-up endpoint: its segment arrives alone and seeds the service name
54+
# in the mock collector, whose first-insert for a service is not concurrency-safe
55+
# (SegmentItems.addSegmentItem check-then-act) — the parent and child later report
56+
# their /users segments concurrently under the same service name
57+
@frontend.route('/ping', methods=['GET'])
58+
def ping():
59+
return jsonify({'song': 'Despacito'})
60+
5361
@frontend.route('/users', methods=['GET'])
5462
def call_backend():
5563
res = requests.get('http://127.0.0.1:9091/users', timeout=5)

tests/plugin/web/sw_fork_support/test_fork_support.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@
2525
@pytest.fixture
2626
def prepare():
2727
# type: () -> Callable
28-
return lambda *_: requests.get('http://0.0.0.0:9090/users', timeout=5).raise_for_status()
28+
# /ping (parent-only) also seeds the service name in the mock collector before the
29+
# parent and child post their /users segments concurrently: the collector's very first
30+
# insert for a service name is not concurrency-safe and can silently drop one segment
31+
return lambda *_: requests.get('http://0.0.0.0:9090/ping', timeout=5).raise_for_status()
2932

3033

3134
class TestPlugin(TestPluginBase):
@@ -40,6 +43,9 @@ class TestPlugin(TestPluginBase):
4043

4144
@pytest.mark.parametrize('version', ['grpcio>=1.83'])
4245
def test_plugin(self, docker_compose, version):
46+
response = requests.get('http://0.0.0.0:9090/users', timeout=5)
47+
assert response.status_code == 200
48+
4349
self.validate()
4450

4551
stdout, stderr = docker_compose.get_logs()

0 commit comments

Comments
 (0)