GitLabgitlab-org
cli
main
1package api
3import (
4 "net/http"
5 "strconv"
6 "testing"
7 "time"
9 "github.com/stretchr/testify/assert"
10)
12func TestRetryAfter(t *testing.T) {
13 now := time.Date(2026, 11, 13, 10, 0, 0, 0, time.UTC)
14 reset := strconv.FormatInt(now.Add(30*time.Second).Unix(), 10)
16 tests := []struct {
17 name string
18 header http.Header
19 want time.Duration
20 wantOK bool
21 }{
22 {
23 name: "seconds",
24 header: http.Header{"Retry-After": {"60"}},
25 want: time.Minute,
26 wantOK: true,
27 },
28 {
29 name: "HTTP date",
30 header: http.Header{"Retry-After": {now.Add(90 * time.Second).Format(http.TimeFormat)}},
31 want: 90 * time.Second,
32 wantOK: true,
33 },
34 {
35 name: "HTTP date in the past",
36 header: http.Header{"Retry-After": {now.Add(-time.Minute).Format(http.TimeFormat)}},
37 want: 0,
38 wantOK: true,
39 },
40 {
41 name: "RateLimit-Reset",
42 header: http.Header{"Ratelimit-Reset": {reset}},
43 want: 30 * time.Second,
44 wantOK: true,
45 },
46 {
47 name: "Retry-After preferred over RateLimit-Reset",
48 header: http.Header{
49 "Retry-After": {"5"},
50 "Ratelimit-Reset": {reset},
51 },
52 want: 5 * time.Second,
53 wantOK: true,
54 },
55 {
56 name: "unparseable Retry-After falls back to RateLimit-Reset",
57 header: http.Header{"Retry-After": {"soon"}, "Ratelimit-Reset": {reset}},
58 want: 30 * time.Second,
59 wantOK: true,
60 },
61 {
62 name: "negative Retry-After",
63 header: http.Header{"Retry-After": {"-1"}},
64 wantOK: false,
65 },
66 {
67 name: "no headers",
68 header: http.Header{},
69 wantOK: false,
70 },
71 }
73 for _, tt := range tests {
74 t.Run(tt.name, func(t *testing.T) {
75 got, ok := RetryAfter(tt.header, now)
76 assert.Equal(t, tt.wantOK, ok)
77 assert.Equal(t, tt.want, got)
78 })
79 }
80}
82func TestRateLimitHint(t *testing.T) {
83 now := time.Now()
85 tests := []struct {
86 name string
87 resp *http.Response
88 want string
89 }{
90 {
91 name: "named limit",
92 resp: &http.Response{
93 StatusCode: http.StatusTooManyRequests,
94 Header: http.Header{"Retry-After": {"60"}, "Ratelimit-Name": {"search_rate_limit"}},
95 },
96 want: "rate limited by search_rate_limit, retry after 1m0s",
97 },
98 {
99 name: "no name",
100 resp: &http.Response{
101 StatusCode: http.StatusTooManyRequests,
102 Header: http.Header{"Retry-After": {"12"}},
103 },
104 want: "rate limited, retry after 12s",
105 },
106 {
107 name: "no wait",
108 resp: &http.Response{
109 StatusCode: http.StatusTooManyRequests,
110 Header: http.Header{"Ratelimit-Name": {"search_rate_limit"}},
111 },
112 want: "",
113 },
114 {
115 name: "not a 429",
116 resp: &http.Response{
117 StatusCode: http.StatusServiceUnavailable,
118 Header: http.Header{"Retry-After": {"60"}},
119 },
120 want: "",
121 },
122 {
123 name: "nil response",
124 want: "",
125 },
126 }
128 for _, tt := range tests {
129 t.Run(tt.name, func(t *testing.T) {
130 assert.Equal(t, tt.want, RateLimitHint(tt.resp, now))
131 })
132 }
133}
Diagnostics6 git calls · 195 ms
CallStatusSizeTime0195 ms
discover200185 B2 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=3 git.response.bytes=185 git.server.agent=git/2.56.g1891de4-Linux git.server.object_format=sha1 git.server.caps=agent ls-refs fetch server-option object-format git.server.fetch=shallow wait-for-done filter git.protocol.version=2 git.pkt.frames=9 git.pkt.data=7 git.pkt.flush=2 git.pkt.delim=0 git.pkt.bytes=185 git.pkt.payload.max=35
ls-refs20058 KiB2 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=2 git.response.bytes=59849 git.response.cache=UPDATING git.response.duration_ms=2 git.protocol.version=2 git.pkt.frames=731 git.pkt.data=730 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=59849 git.pkt.payload.max=143 git.ls_refs.count=730 git.ls_refs.head=refs/heads/main
fetchcombine:blob:none+tree:2 · deepen 12004.2 KiB · hit3 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=3 git.response.bytes=4273 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=combine:blob:none+tree:2 git.fetch.wants=0dd7574dce9e385c5c30540e6c15657adc6bdce9 git.fetch.haves.count=0 git.fetch.deepen=1 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=7 git.pkt.data=5 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=4273 git.pkt.payload.max=4173 git.sideband.band1.bytes=4173 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=11 git.pack.bytes=4173 git.fetch.wide.objects=11 git.fetch.wide.extra_bytes=3930 git.fetch.wide.blobs=0
fetchtree:0 · deepen 1020032 KiB · hit3 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=2 git.response.bytes=32926 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=tree:0 git.fetch.wants=0dd7574dce9e385c5c30540e6c15657adc6bdce9 git.fetch.haves.count=0 git.fetch.deepen=10 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=22 git.pkt.data=20 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=32926 git.pkt.payload.max=32046 git.sideband.band1.bytes=32046 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=80 git.pack.bytes=32046 git.pack.ofs_delta=36 git.pack.ref_delta=0 git.pack.chain.max=2 git.pack.trailer=cb0bad5d7ffc514895d8b21c4dd470327f90bc91 git.pack.full=44Open pack map
fetchtree:02001.1 KiB · hit2 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=188 git.response.bytes=1165 git.response.cache=HIT git.response.duration_ms=2 git.fetch.filter=tree:0 git.fetch.wants=71c8407e0ff0e0af10f6a041ae330f754b68e7eb git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=4 git.pkt.data=3 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=1165 git.pkt.payload.max=1138 git.sideband.band1.bytes=1138 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=1138 git.pack.trailer=61886367c69619d8db2b2cf2d7d24dca2016141cOpen pack map
fetch200862 B188 ms
git.upload-pack fetch http.response.status_code=200 git.response.bytes=862 git.response.cache=MISS git.response.duration_ms=188 git.fetch.wants=1c4afa543732d12340c43d0aab9453d77dea4e49 git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=4 git.pkt.data=3 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=862 git.pkt.payload.max=835 git.sideband.band1.bytes=835 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0
Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.
- Remote
- https://gitlab.com/gitlab-org/cli
- Ref
- refs/heads/main
- Commit
- 0dd7574dce9e385c5c30540e6c15657adc6bdce9
- cf-ray
- a5e1dc601bbdecfa
- Request
- 58b6c277…
- Protocol
- v2 · sha1
- Agent
- git/2.56.g1891de4-Linux
- Filter
- advertised
- Fetch
- shallow wait-for-done filter
- Capabilities
- agent ls-refs fetch server-option object-format