Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions test/integration/difc_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package integration
import (
"bytes"
"context"
"encoding/json"
"fmt"
"net"
"net/http"
Expand Down Expand Up @@ -412,19 +411,15 @@ func TestFullDIFCConfigFromJSON(t *testing.T) {
err := cmd.Start()
require.NoError(t, err, "Failed to start gateway")

ok := waitForStderr(&stderr, "Starting MCPG", 5*time.Second)
require.Truef(t, ok, "timeout waiting for gateway stderr to contain %q within %s; stderr:\n%s", "Starting MCPG", 5*time.Second, stderr.String())

// Try health check
resp, err := http.Get(fmt.Sprintf("http://127.0.0.1:%d/health", port))
if err == nil {
defer resp.Body.Close()
assert.Equal(t, http.StatusOK, resp.StatusCode)
// Wait for guard registration (appears before the blocking registerAllTools
// backend connections that may take 30+ seconds for Docker containers).
// "Starting MCPG" only prints after NewUnified returns, which blocks on
// backend connections — too slow for this test's DIFC-config-only assertions.
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)
Comment on lines +418 to +422
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

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

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())

Copilot uses AI. Check for mistakes.

cmd.Process.Kill()
cmd.Wait()
Expand Down
Loading