TestQueryDetailFansOutAcrossCPs proves /queries/by-worker/:wid scatter-gathers: when the serving replica doesn't own the worker, it fetches peers and returns the one owner's body; and a scope=local (peer) call never fans out.
(t *testing.T)
| 62 | // TestQueryDetailFansOutAcrossCPs proves /queries/by-worker/:wid scatter-gathers: |
| 63 | // when the serving replica doesn't own the worker, it fetches peers and returns |
| 64 | // the one owner's body; and a scope=local (peer) call never fans out. |
| 65 | func TestQueryDetailFansOutAcrossCPs(t *testing.T) { |
| 66 | local := &fakeLiveInfo{} // owns nothing |
| 67 | peerBody, _ := json.Marshal(QueryDetail{Org: "b", PID: 77, WorkerID: 20, Query: "SELECT 2"}) |
| 68 | fetcher := &fakePeerFetcher{byPath: map[string][][]byte{"/api/v1/queries/by-worker/20": {peerBody}}} |
| 69 | r := liveTestRouter(local, fetcher) |
| 70 | |
| 71 | // Default scope: not owned locally → fan out → peer's detail returned. |
| 72 | w := httptest.NewRecorder() |
| 73 | r.ServeHTTP(w, httptest.NewRequest(http.MethodGet, "/api/v1/queries/by-worker/20", nil)) |
| 74 | if w.Code != http.StatusOK { |
| 75 | t.Fatalf("expected 200 from peer fan-out, got %d (%s)", w.Code, w.Body.String()) |
| 76 | } |
| 77 | var got QueryDetail |
| 78 | if err := json.Unmarshal(w.Body.Bytes(), &got); err != nil { |
| 79 | t.Fatalf("decode: %v", err) |
| 80 | } |
| 81 | if got.WorkerID != 20 || got.Query != "SELECT 2" || got.Org != "b" { |
| 82 | t.Fatalf("unexpected fanned-out body: %+v", got) |
| 83 | } |
| 84 | |
| 85 | // scope=local: recursion guard — no fan-out even with a fetcher present. |
| 86 | before := fetcher.callCount() |
| 87 | w = httptest.NewRecorder() |
| 88 | r.ServeHTTP(w, httptest.NewRequest(http.MethodGet, "/api/v1/queries/by-worker/20?scope=local", nil)) |
| 89 | if w.Code != http.StatusNotFound { |
| 90 | t.Fatalf("expected 404 under scope=local, got %d", w.Code) |
| 91 | } |
| 92 | if fetcher.callCount() != before { |
| 93 | t.Fatalf("scope=local must not fan out, but FetchPeers was called (%d → %d)", before, fetcher.callCount()) |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | // TestQueryDetailWorkerIDDistinguishesCollidingPIDs is the regression for the |
nothing calls this directly
no test coverage detected