Skip to content

test(e2e): cover scenario combinations#18

Merged
moonming merged 2 commits intoapi7:mainfrom
guoqqqi:test/e2e-scenario-coverage
Apr 20, 2026
Merged

test(e2e): cover scenario combinations#18
moonming merged 2 commits intoapi7:mainfrom
guoqqqi:test/e2e-scenario-coverage

Conversation

@guoqqqi
Copy link
Copy Markdown
Contributor

@guoqqqi guoqqqi commented Apr 10, 2026

Summary

  • add an E2E scenario covering route + service + plugin-config working together through the gateway
  • add a real-traffic multi-node upstream test that verifies requests reach both backend nodes
  • explicitly skip these scenarios in environments that reject resource creation with a license gate

Validation

  • GOCACHE=/tmp/go-build-a6 GOMODCACHE=/tmp/gomod-a6 go test ./test/e2e -run 'TestRoute_ServiceAndPluginConfigCombination|TestUpstream_MultiNodeRealTraffic' -tags e2e -count=1 -v -timeout 10m

Refs #14

Summary by CodeRabbit

  • Tests
    • Added end-to-end integration tests to validate route configurations and multi-node traffic distribution in real-world scenarios.

Copilot AI review requested due to automatic review settings April 10, 2026 03:24
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 10, 2026

Warning

Rate limit exceeded

@guoqqqi has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 18 minutes and 39 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 18 minutes and 39 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0136a5f2-3166-4f4a-8e1f-c5882c196cf3

📥 Commits

Reviewing files that changed from the base of the PR and between 890e731 and 9a91d00.

📒 Files selected for processing (1)
  • test/e2e/scenario_coverage_test.go
📝 Walkthrough

Walkthrough

Added a new E2E test file containing two integration tests: one verifying service, plugin configuration, and route behavior together; another validating upstream round-robin traffic distribution across multiple backend nodes. Includes helper utilities for test server creation, URL parsing, and license validation.

Changes

Cohort / File(s) Summary
E2E Integration Tests
test/e2e/scenario_coverage_test.go
Added TestRoute_ServiceAndPluginConfigCombination and TestUpstream_MultiNodeRealTraffic tests with provisioning via CLI, polling-based verification, and response assertion. Includes helper functions: newNamedTestServer (creates test HTTP server), hostPort (extracts host from URL), and skipIfLicenseRestricted (conditional test skip on license restrictions).

Sequence Diagram(s)

sequenceDiagram
    participant Test
    participant CLI
    participant Gateway
    participant Upstream[Service/Upstream]
    participant Plugin[Plugin System]

    Test->>CLI: Provision service, plugin config, route
    Test->>Gateway: Poll GET /scenario-combo
    Gateway->>Plugin: Apply plugin transformations
    Plugin->>Upstream: Forward to upstream URL
    Upstream-->>Plugin: Response + data
    Plugin-->>Gateway: Add X-Scenario-Coverage header
    Gateway-->>Test: HTTP 200 + JSON response
    Test->>Test: Assert upstream URL and plugin header
    Test->>CLI: Cleanup delete route/service/config
Loading
sequenceDiagram
    participant Test
    participant CLI
    participant Gateway
    participant LoadBalancer[Round-robin Upstream]
    participant BackendA[Backend A]
    participant BackendB[Backend B]

    Test->>CLI: Provision upstream (round-robin) with 2 nodes
    Test->>CLI: Provision route to upstream
    Test->>Gateway: Poll GET /scenario-multi-node
    Gateway->>LoadBalancer: Route request via round-robin
    LoadBalancer->>BackendA: Forward request
    BackendA-->>Gateway: Response with backend-a identifier
    Test->>Test: Record backend-a observed
    Test->>Gateway: Poll GET /scenario-multi-node again
    Gateway->>LoadBalancer: Route request via round-robin
    LoadBalancer->>BackendB: Forward request
    BackendB-->>Gateway: Response with backend-b identifier
    Test->>Test: Assert both backends reached
    Test->>CLI: Cleanup delete route/upstream
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 3 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
E2e Test Quality Review ⚠️ Warning PR introduces well-designed E2E tests covering scenario combinations and following existing patterns, but contains three critical assertion bugs documented in review comments: hardcoded httpbinURL address (line 46), overly strict URL assertion not accounting for gateway rewrites (line 111), and incomplete header type handling (line 115). Replace hardcoded '127.0.0.1:8080' with hostPort(t, httpbinURL), modify line 111 to assert only URL path using url.Parse(), update line 115 to handle both string and array header types, and add 'net/url' import.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding E2E tests that cover scenario combinations, which aligns with the two new test functions covering service+plugin+route interaction and multi-node upstream scenarios.
Security Check ✅ Passed The pull request contains only E2E test code with no sensitive data exposure, database operations, or authorization logic flaws.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@test/e2e/scenario_coverage_test.go`:
- Around line 40-49: The service JSON currently hardcodes the upstream node
address when building serviceJSON; change it to use the existing httpbinURL
variable instead of "127.0.0.1:8080" so test environment overrides (HTTPBIN_URL)
are respected. Locate the serviceJSON construction that references serviceID and
replace the upstream node entry with the httpbinURL value (ensure it remains a
string in the formatted JSON). No other behavior should change—only swap the
hardcoded address for httpbinURL.
- Around line 109-115: The assertions in the test are too strict: instead of
asserting result["url"] equals fmt.Sprintf("%s/get", httpbinURL), update the
check to accept gateway-hosted URLs by asserting the URL string ends with or
contains "/get" (use strings.HasSuffix or strings.Contains on the result["url"]
value after converting to string); and for headers, make the extraction of
headers flexible by handling headers :=
result["headers"].(map[string]interface{}) then reading v :=
headers["X-Scenario-Coverage"] and accepting either a string or an array
([]interface{})—normalize to a []string or check membership so that
"service-route-plugin-config" is accepted whether the header decodes as a single
string or as an array; adjust the require/assert calls accordingly in
scenario_coverage_test.go around the json.Unmarshal/result/headers checks.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a1a10776-b08e-4031-a8c2-9dd74c568fa2

📥 Commits

Reviewing files that changed from the base of the PR and between 85d58d7 and 890e731.

📒 Files selected for processing (1)
  • test/e2e/scenario_coverage_test.go

Comment thread test/e2e/scenario_coverage_test.go Outdated
Comment thread test/e2e/scenario_coverage_test.go Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds new end-to-end scenario tests to increase coverage for “combination” gateway configuration cases and multi-node upstream real-traffic behavior, with conditional skipping in license-gated environments.

Changes:

  • Add an E2E test covering service + route + plugin-config working together through the gateway.
  • Add an E2E test validating real traffic reaches multiple upstream nodes (round-robin).
  • Add a helper to skip these scenarios when resource creation fails due to a license gate.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread test/e2e/scenario_coverage_test.go Outdated
Comment on lines +111 to +112
assert.Equal(t, fmt.Sprintf("%s/get", httpbinURL), result["url"])

Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test assumes httpbin’s JSON field url will be HTTPBIN_URL + "/get", but httpbin typically builds this value from the incoming Host header. APISIX commonly preserves the client Host header by default, so this may end up being the gateway host/port (e.g. 127.0.0.1:9080) and make the assertion fail even when the proxying works. Consider asserting on the parsed URL path (equals /get) and/or that it ends with /get, rather than matching the full host.

Suggested change
assert.Equal(t, fmt.Sprintf("%s/get", httpbinURL), result["url"])
returnedURL, ok := result["url"].(string)
require.True(t, ok, "httpbin response should expose url as a string")
assert.True(t, strings.HasSuffix(returnedURL, "/get"), "httpbin response url should end with /get, got %q", returnedURL)

Copilot uses AI. Check for mistakes.
Comment on lines +165 to +182
seen := map[string]bool{}
for i := 0; i < 12; i++ {
resp, err := http.Get(gatewayURL + "/scenario-multi-node")
require.NoError(t, err, "gateway request should succeed")

payload, readErr := io.ReadAll(resp.Body)
resp.Body.Close()
require.NoError(t, readErr)

if resp.StatusCode == http.StatusOK {
seen[strings.TrimSpace(string(payload))] = true
if seen["backend-a"] && seen["backend-b"] {
break
}
}

time.Sleep(200 * time.Millisecond)
}
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The retry budget here is only ~2.4s (12 * 200ms). Other e2e tests in this package typically allow ~5s (10 * 500ms) for config propagation. This shorter window can introduce flakes in slower environments; consider using the same retry duration pattern (or a time-based deadline) before asserting that both backends were seen.

Copilot uses AI. Check for mistakes.
Comment on lines +199 to +205
func hostPort(t *testing.T, rawURL string) string {
t.Helper()

host := strings.TrimPrefix(rawURL, "http://")
_, _, err := net.SplitHostPort(host)
require.NoError(t, err)
return host
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hostPort currently strips only the http:// prefix and then relies on net.SplitHostPort. This is a bit brittle (e.g., if the URL format changes, or if an https:// server is used later). Parsing via net/url and using u.Host would make the helper more robust and self-documenting.

Copilot uses AI. Check for mistakes.
@moonming moonming merged commit 9a91d00 into api7:main Apr 20, 2026
6 checks passed
@guoqqqi guoqqqi deleted the test/e2e-scenario-coverage branch April 20, 2026 09:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants