Skip to content

test(e2e): fix debug-trace propagation wait so all 9 traffic tests run#59

Merged
shreemaan-abhishek merged 1 commit into
masterfrom
fix/debug-trace-test-propagation
May 28, 2026
Merged

test(e2e): fix debug-trace propagation wait so all 9 traffic tests run#59
shreemaan-abhishek merged 1 commit into
masterfrom
fix/debug-trace-test-propagation

Conversation

@shreemaan-abhishek
Copy link
Copy Markdown
Contributor

@shreemaan-abhishek shreemaan-abhishek commented May 27, 2026

Summary

`waitForDebugTraceRoute` polled the gateway for a non-404 response code to decide a newly-created route had propagated to the data plane. That signal only works when the route's path happens to exist on the upstream too. In this repo's setup the upstream is `go-httpbin`, which serves `/get`, `/post`, `/anything`, etc., but not `/debug-trace-test`, `/debug-trace-headers`, `/debug-trace-yaml`, etc.

So routes did propagate within milliseconds, the gateway matched them, but it forwarded e.g. `/debug-trace-test` to httpbin, which replied with its own 404. The wait loop interpreted that as "not propagated yet", spent the full 15s timeout, then soft-skipped.

Reproduction

```bash
A7_GATEWAY_URL=http://localhost:9080 HTTPBIN_URL=http://host.docker.internal:8081 \
go test -tags e2e -v -count=1 -run TestDebugTrace_JSONOutput ./test/e2e/...
```

Before this PR:
```
--- SKIP: TestDebugTrace_JSONOutput (15.35s)
debug_test.go:59: route /debug-trace-test did not propagate to the local gateway within timeout
```

A direct curl during that 15s window returns a 404 with `Server: API7/3.9.12` and `Content-Type: text/plain` — the signature of go-httpbin's not-found handler, NOT the gateway's own `{"error_msg":"404 Route Not Found"}`. The route IS at the gateway; the upstream just doesn't serve the synthetic path.

Fix

In `createDebugTraceRoute`, when the caller does not supply its own plugins, inject a default `proxy-rewrite: { uri: "/anything" }`. `/anything` is a path go-httpbin always returns 200 for (with a JSON echo of the request), so the wait loop sees the route the moment the data plane picks it up. Callers that DO supply plugins (`WithMethod`, `WithPath`, `WithHost`) are unaffected — the existing `strings.Contains(extraFields, "plugins")` guard keeps their custom plugin set intact.

Test plan

Local rerun against API7 EE 3.9.12 with go-httpbin upstream:

Test Before After
TestRoute_TrafficForwarding PASS 0.70s PASS 0.65s
TestConsumer_WithKeyAuth PASS 1.39s PASS 1.35s
TestDebugTrace_WithMethod PASS 0.79s PASS 0.61s
TestDebugTrace_WithPath PASS 0.76s PASS 1.17s
TestDebugTrace_NonexistentRoute PASS 0.04s PASS 0.03s
TestDebugTrace_JSONOutput SKIP 15.35s PASS 0.62s
TestDebugTrace_WithHeaders SKIP 15.31s PASS 0.63s
TestDebugTrace_WithHost SKIP 15.37s PASS 0.67s
TestDebugTrace_YAMLOutput SKIP 15.37s PASS 1.14s

9/9 PASS, 0/9 skip. Total wall time dropped from 67s to 8s.

  • `go vet -tags e2e ./test/e2e/...` clean
  • `go test -tags e2e -count=1 -v -run 'TestRoute_TrafficForwarding|TestConsumer_WithKeyAuth|TestDebugTrace_' ./test/e2e/...` all pass
  • Tests that supplied their own plugins keep doing so; no behavior change for them

Summary by CodeRabbit

  • Tests
    • Enhanced end-to-end test infrastructure for debug trace route handling to ensure proper upstream response behavior during testing.

Review Change Stack

waitForDebugTraceRoute polled the gateway for a non-404 response code to
decide the new route had propagated to the data plane. That worked only
when the route's path happened to exist on the upstream too: in this
repo's setup the upstream is go-httpbin, which serves /get, /post,
/anything, etc., but not /debug-trace-test, /debug-trace-headers, etc.

Result: routes did propagate within milliseconds, the gateway matched
them, but it forwarded e.g. /debug-trace-test to httpbin which replied
with its own 404. The wait loop interpreted that as "not propagated
yet", spent the full 15s timeout, then soft-skipped.

This was masked because some debug-trace tests already set their own
proxy-rewrite plugin (rewriting to /post, /anything/*) for unrelated
reasons; those tests passed in roughly half a second. The four tests
that did NOT supply a plugin (JSONOutput, WithHeaders, WithHost,
YAMLOutput) always skipped.

Inject a default `proxy-rewrite: { uri: "/anything" }` in
createDebugTraceRoute when the caller does not supply its own plugins.
go-httpbin's /anything endpoint always returns 200 with a JSON echo, so
the wait loop sees the route the moment it lands at the gateway.
Callers that DO supply plugins (WithMethod, WithPath, WithHost) are
unaffected.

Local rerun: all 9 traffic tests pass; total wall time dropped from
67s to 8s.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 27, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8ec6b42e-dcce-4f59-a893-81d01d21adc7

📥 Commits

Reviewing files that changed from the base of the PR and between addcf9a and de40fbb.

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

📝 Walkthrough

Walkthrough

test/e2e/debug_test.go imports strings and updates createDebugTraceRoute to automatically append a default proxy-rewrite plugin when extraFields lacks a plugins key, allowing debug trace routes to avoid 404 responses during e2e test propagation checks.

Changes

Debug Trace Route Enhancement

Layer / File(s) Summary
Add proxy-rewrite plugin default to debug trace routes
test/e2e/debug_test.go
createDebugTraceRoute imports strings and appends a default proxy-rewrite plugin JSON snippet (/anything) when extraFields does not include a plugins key, ensuring debug-trace route paths receive non-404 upstream responses for the propagation/wait logic in e2e tests.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 5 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
E2e Test Quality Review ⚠️ Warning Code uses fragile substring matching (strings.Contains) to detect plugins field; field description containing "plugins" would cause false positive preventing injection. Use strings.Contains(extraFields, "plugins":) instead of strings.Contains(extraFields, "plugins") for robust JSON field detection.
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: fixing debug-trace propagation wait logic in e2e tests so all 9 traffic tests run (previously some were skipped due to timeouts).
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Security Check ✅ Passed E2e test injects only benign proxy-rewrite plugin with no secrets, credentials, or sensitive data. No authorization, crypto, or isolation issues detected.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/debug-trace-test-propagation

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

Copy link
Copy Markdown
Contributor

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

Updates the e2e debug-trace route helper so route propagation waiting succeeds even when synthetic test paths aren’t served by the upstream (go-httpbin), preventing unintended 15s timeouts and soft-skips.

Changes:

  • Injects a default proxy-rewrite plugin (to /anything) when creating debug-trace routes without caller-supplied plugins.
  • Adds strings import to support the plugin-presence guard.

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

Comment thread test/e2e/debug_test.go
@shreemaan-abhishek shreemaan-abhishek merged commit d99f5fa into master May 28, 2026
7 of 8 checks passed
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.

2 participants