Fix TestFullDIFCConfigFromJSON timeout waiting for backend connections#3960
Fix TestFullDIFCConfigFromJSON timeout waiting for backend connections#3960
Conversation
The test waited 5s for 'Starting MCPG' in stderr, but that message only prints after NewUnified() returns. NewUnified blocks on registerAllTools() which tries to connect backends (Docker container launch has a 30s timeout). The test's assertions only need DIFC guard registration output. Fix: wait for '[DIFC] Registered guard' instead, which appears before the blocking backend connections. Remove the health check (requires full startup) and the now-unused encoding/json import. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR updates the DIFC integration test to avoid timing out while the gateway blocks on slow backend/tool registration (notably Docker-backed servers), by waiting for earlier DIFC guard-registration logs instead of full startup completion.
Changes:
- Updated
TestFullDIFCConfigFromJSONto wait for DIFC guard registration output rather than"Starting MCPG". - Removed the
/healthcheck (which requires full gateway startup) and dropped the now-unusedencoding/jsonimport. - Added a short post-detection delay to allow additional stderr output to flush before terminating the subprocess.
Show a summary per file
| File | Description |
|---|---|
| test/integration/difc_config_test.go | Makes the test synchronize on DIFC guard-registration logs and removes the health check to avoid backend-connection startup delays. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 1/1 changed files
- Comments generated: 1
| ok := waitForStderr(&stderr, "[DIFC] Registered guard", 5*time.Second) | ||
| require.Truef(t, ok, "timeout waiting for DIFC guard registration within %s; stderr:\n%s", 5*time.Second, stderr.String()) | ||
|
|
||
| var health map[string]interface{} | ||
| json.NewDecoder(resp.Body).Decode(&health) | ||
| t.Logf("Health response: %+v", health) | ||
| } | ||
| // Brief pause to let remaining sequential guard registrations flush to stderr | ||
| time.Sleep(300 * time.Millisecond) |
There was a problem hiding this comment.
The test now waits for the first occurrence of "[DIFC] Registered guard" and then sleeps 300ms before killing the gateway. Since launcher.ServerIDs() returns IDs in map iteration order (non-deterministic), you can kill the process after only one guard registration, before the second backend's guard (and related log lines like server1/server2) is emitted—making the assertions below flaky. Prefer waiting for both expected registrations explicitly (e.g., wait for "Registered guard ... server 'server1'" and "... server 'server2'", or wait for both server IDs to appear) and then remove the fixed sleep.
See below for a potential fix:
// Wait for both configured servers to appear in stderr before stopping the
// process. Guard registration happens before the blocking registerAllTools
// backend connections that may take 30+ seconds for Docker containers, but
// the registrations are sequential and server iteration order is
// non-deterministic. Waiting for both server-specific log entries avoids
// flakiness from killing the process after only the first registration.
ok := waitForStderr(&stderr, "server1", 5*time.Second)
require.Truef(t, ok, "timeout waiting for server1 DIFC configuration within %s; stderr:\n%s", 5*time.Second, stderr.String())
ok = waitForStderr(&stderr, "server2", 5*time.Second)
require.Truef(t, ok, "timeout waiting for server2 DIFC configuration within %s; stderr:\n%s", 5*time.Second, stderr.String())
Problem
TestFullDIFCConfigFromJSONfails with a 5s timeout waiting for"Starting MCPG"in stderr:Root Cause
"Starting MCPG in ROUTED/UNIFIED mode"only prints afterNewUnified()returns.NewUnified()blocks onregisterAllTools()which tries to connect to all backends — including a Docker container (test/server1:latest) with a 30s launch timeout. The test's 5s deadline expires while waiting for Docker to fail.Fix
The test's assertions only verify DIFC guard registration output, which appears before the blocking backend connections. Changed the wait string from
"Starting MCPG"to"[DIFC] Registered guard", added a 300ms flush delay, and removed the health check (which requires full startup).Changes
test/integration/difc_config_test.goencoding/jsonimportmake agent-finished✓