From 466a3d5fd93c2932fad849f50e657123eaf75ef4 Mon Sep 17 00:00:00 2001 From: maidamaliziasimnw Date: Fri, 10 Jul 2026 17:39:24 +0000 Subject: [PATCH] =?UTF-8?q?test(client):=20=E6=96=B0=E5=A2=9E=20PaginateAl?= =?UTF-8?q?lKey=20=E5=9F=BA=E5=87=86=E6=B5=8B=E8=AF=95=EF=BC=88=E6=A8=A1?= =?UTF-8?q?=E6=8B=9F=E6=AF=8F=E9=A1=B5=E5=BB=B6=E8=BF=9F=EF=BC=8C=E8=A6=86?= =?UTF-8?q?=E7=9B=96=E5=B9=B6=E5=8F=91=E7=BF=BB=E9=A1=B5=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- internal/client/pagination_test.go | 32 ++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/internal/client/pagination_test.go b/internal/client/pagination_test.go index 9a54349..d253cfe 100644 --- a/internal/client/pagination_test.go +++ b/internal/client/pagination_test.go @@ -9,6 +9,7 @@ import ( "strconv" "strings" "testing" + "time" ) func TestPaginateAllKeyResourceWrappedPages(t *testing.T) { @@ -245,3 +246,34 @@ func TestPaginateAllKeyServerCappedLimit(t *testing.T) { t.Fatalf("len(items) = %d, want 5", len(items)) } } + +// BenchmarkPaginateAllKey measures full-list pagination against a server with +// simulated per-page latency, exercising the concurrent page-fetch path. +func BenchmarkPaginateAllKey(b *testing.B) { + const total, perPage = 500, 50 + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + time.Sleep(5 * time.Millisecond) + page, _ := strconv.Atoi(r.URL.Query().Get("page")) + var items []string + for i := (page-1)*perPage + 1; i <= page*perPage && i <= total; i++ { + items = append(items, fmt.Sprintf(`{"id":%d}`, i)) + } + w.Header().Set("Content-Type", "application/json") + fmt.Fprintf(w, `{"total_count":%d,"issues":[%s]}`, total, strings.Join(items, ",")) + })) + defer server.Close() + + c := &Client{HTTP: server.Client(), BaseURL: server.URL} + b.ResetTimer() + for i := 0; i < b.N; i++ { + params := url.Values{} + params.Set("limit", strconv.Itoa(perPage)) + items, err := c.PaginateAllKey("/repos/o/r/issues", params, "issues") + if err != nil { + b.Fatalf("PaginateAllKey: %v", err) + } + if len(items) != total { + b.Fatalf("len = %d, want %d", len(items), total) + } + } +}