Files
zzet--gortex/internal/daemon/federation_events_test.go
wehub-resource-sync a06f331eb8
CI / benchmark (push) Has been skipped
install-script / posix-syntax (push) Successful in 6m1s
CI / build-onnx (push) Failing after 6m43s
init-smoke / dry-run (push) Failing after 15m57s
security / govulncheck (push) Has been cancelled
security / trivy-fs (push) Has been cancelled
CI / test (1.26, ubuntu-latest) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
CI / test (1.26, macos-latest) (push) Has been cancelled
CI / build-windows (push) Has been cancelled
CI / lint (push) Has been cancelled
install-script / powershell-syntax (push) Has been cancelled
install-script / install (macos-14) (push) Has been cancelled
install-script / install (ubuntu-latest) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:33:42 +08:00

57 lines
1.6 KiB
Go

package daemon
import (
"context"
"fmt"
"net/http"
"net/http/httptest"
"testing"
"time"
"github.com/zzet/gortex/internal/graph"
)
// TestStreamEvents_EvictsCachedProxies asserts a remote's graph_change SSE
// frame triggers eviction of this daemon's cached proxy nodes for that
// remote (marking them stale so the next access re-hydrates).
func TestStreamEvents_EvictsCachedProxies(t *testing.T) {
g := graph.New()
proxyID := graph.ProxyNodeID("remoteB", "rb/c.go::Helper")
g.AddNode(&graph.Node{
ID: proxyID, Kind: graph.KindFunction, Name: "Helper",
Origin: "remote:remoteB", Stub: true, FetchedAt: time.Now(),
})
// Fake remote: /v1/events emits one graph_change frame, then closes.
mux := http.NewServeMux()
mux.HandleFunc("/v1/events", func(w http.ResponseWriter, _ *http.Request) {
w.Header().Set("Content-Type", "text/event-stream")
fmt.Fprint(w, "event: graph_change\nid: 1\ndata: {}\n\n")
if fl, ok := w.(http.Flusher); ok {
fl.Flush()
}
})
srv := httptest.NewServer(mux)
t.Cleanup(srv.Close)
h := hydratorFor(g, []ServerEntry{{Slug: "remoteB", URL: srv.URL}})
cli, err := NewServerClient(ServerEntry{Slug: "remoteB", URL: srv.URL})
if err != nil {
t.Fatal(err)
}
evicted := 0
if err := cli.StreamEvents(context.Background(), func() {
evicted += h.EvictRemote("remoteB")
}); err != nil {
t.Fatalf("StreamEvents: %v", err)
}
if evicted == 0 {
t.Fatal("a graph_change frame must trigger eviction")
}
if !g.GetNode(proxyID).FetchedAt.IsZero() {
t.Error("the evicted proxy must be marked stale (FetchedAt zeroed) so it re-hydrates")
}
}