Skip to content

Commit ff98df9

Browse files
committed
test(plugin): retry-until-valid loop + per-plugin CI matrix
- run.sh: segments flush asynchronously, so a single shot can validate before they all arrive (this failed in CI). Each attempt now fires traffic, waits 20s, then validates; retried up to 10 times. - plugin-test.yml: one matrix job PER scenario (auto-discovered) so results show per plugin in the checks UI, mirroring apache/skywalking-java's plugin-test.
1 parent 163b797 commit ff98df9

2 files changed

Lines changed: 50 additions & 33 deletions

File tree

.github/workflows/plugin-test.yml

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,51 @@
11
name: Plugin Test
22

3-
# Per-plugin tests: run each plugin scenario against a dedicated mock collector and assert the
4-
# REAL emitted segments, version-by-version (see test/plugin/). Heavier than unit tests (Docker +
5-
# a Java collector build), so it runs only when the agent, a plugin, or the framework changes.
3+
# Per-plugin tests: each plugin scenario runs against a dedicated mock collector and asserts the REAL
4+
# emitted segments, version-by-version (see test/plugin/). One matrix job PER PLUGIN so results show
5+
# per plugin in the checks UI (like apache/skywalking-java's plugin-test). Heavier than unit tests
6+
# (Docker + a Java collector build), so it runs only when the agent, a plugin, or the framework changes.
67
on:
78
push:
89
branches: [main]
9-
paths:
10-
- 'src/**'
11-
- 'test/plugin/**'
12-
- '.github/workflows/plugin-test.yml'
10+
paths: ['src/**', 'test/plugin/**', '.github/workflows/plugin-test.yml']
1311
pull_request:
14-
paths:
15-
- 'src/**'
16-
- 'test/plugin/**'
17-
- '.github/workflows/plugin-test.yml'
12+
paths: ['src/**', 'test/plugin/**', '.github/workflows/plugin-test.yml']
1813

1914
concurrency:
2015
group: plugin-test-${{ github.ref }}
2116
cancel-in-progress: true
2217

2318
jobs:
19+
# Discover the scenarios so each becomes its own matrix entry (no need to edit this file per plugin).
20+
discover:
21+
runs-on: ubuntu-latest
22+
outputs:
23+
scenarios: ${{ steps.list.outputs.scenarios }}
24+
steps:
25+
- uses: actions/checkout@v4
26+
- id: list
27+
run: |
28+
scenarios=$(ls -d test/plugin/scenarios/*/ | xargs -n1 basename | jq -R . | jq -cs .)
29+
echo "scenarios=$scenarios" >> "$GITHUB_OUTPUT"
30+
echo "scenarios: $scenarios"
31+
2432
plugin-test:
33+
needs: discover
2534
runs-on: ubuntu-latest
2635
timeout-minutes: 40
36+
strategy:
37+
fail-fast: false
38+
matrix:
39+
scenario: ${{ fromJSON(needs.discover.outputs.scenarios) }}
40+
name: ${{ matrix.scenario }}
2741
steps:
2842
- uses: actions/checkout@v4
2943
with:
3044
submodules: recursive # the protocol-v3 codegen source
31-
32-
# Needed to build the mock collector from the pinned agent-test-tool commit.
3345
- uses: actions/setup-java@v4
3446
with:
3547
distribution: temurin
3648
java-version: '11'
37-
38-
- name: Run plugin scenarios (build collector + per-version build/run/validate)
39-
run: bash test/plugin/run.sh
49+
cache: maven # cache the mock-collector build deps
50+
- name: Run ${{ matrix.scenario }} (build collector + per-version build/run/validate)
51+
run: bash test/plugin/run.sh ${{ matrix.scenario }}

test/plugin/run.sh

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,23 +51,21 @@ ensure_collector() {
5151
rm -rf "$work" "$ctx"
5252
}
5353

54-
# Wait until the collector has received at least one segment, then validate.
54+
# Segments flush to the collector asynchronously (CAP dispatches on background threads, and the
55+
# agent batches), so a single shot can validate before everything arrives. Each attempt FIRES
56+
# TRAFFIC, WAITS, then VALIDATES; we retry the whole loop until it passes or the attempts run out.
57+
VALIDATE_ATTEMPTS="${VALIDATE_ATTEMPTS:-10}"
58+
VALIDATE_WAIT="${VALIDATE_WAIT:-20}"
59+
60+
drive_traffic() {
61+
for _ in 1 2 3 4 5; do curl -sf --max-time 5 "http://localhost:${ENTRY_PORT}/case/cap" >/dev/null 2>&1 || true; done
62+
}
63+
5564
validate() {
5665
local expected="$1"
57-
for _ in $(seq 1 30); do
58-
if curl -sf --max-time 10 "$COLLECTOR_HTTP/receiveData" 2>/dev/null | grep -q "segmentId:"; then
59-
break
60-
fi
61-
sleep 2
62-
done
6366
local code; code="$(curl -s -o /tmp/plugin-validate.out -w '%{http_code}' --max-time 20 \
6467
-X POST --data-binary @"$expected" "$COLLECTOR_HTTP/dataValidate")"
65-
if [ "$code" = "200" ]; then
66-
return 0
67-
fi
68-
log "VALIDATION FAILED (HTTP $code):"
69-
sed -n '/cause by/,$p' /tmp/plugin-validate.out | head -40
70-
return 1
68+
[ "$code" = "200" ]
7169
}
7270

7371
run_case() {
@@ -79,13 +77,20 @@ run_case() {
7977
TFM="$tfm" CAP_VERSION="$ver" DOTNET_VERSION="$dotnet" \
8078
docker compose up -d --build --quiet-pull
8179
)
82-
local rc=0
83-
# health-gate the app, then drive the entry endpoint a few times
80+
# health-gate the app
8481
for _ in $(seq 1 30); do
8582
curl -sf --max-time 5 "http://localhost:${ENTRY_PORT}/case/healthCheck" >/dev/null 2>&1 && break || sleep 2
8683
done
87-
for _ in $(seq 1 5); do curl -sf --max-time 5 "http://localhost:${ENTRY_PORT}/case/cap" >/dev/null 2>&1 || true; sleep 1; done
88-
validate "$scen/config/expectedData.yaml" || rc=1
84+
local rc=1
85+
for attempt in $(seq 1 "$VALIDATE_ATTEMPTS"); do
86+
drive_traffic
87+
sleep "$VALIDATE_WAIT"
88+
if validate "$scen/config/expectedData.yaml"; then rc=0; break; fi
89+
log "attempt $attempt/$VALIDATE_ATTEMPTS: not valid yet, retrying"
90+
done
91+
if [ "$rc" -ne 0 ]; then
92+
log "VALIDATION FAILED:"; sed -n '/cause by/,$p' /tmp/plugin-validate.out | head -40
93+
fi
8994
( cd "$scen" && docker compose down -v >/dev/null 2>&1 || true )
9095
return $rc
9196
}

0 commit comments

Comments
 (0)