mirror of
https://github.com/juanfont/headscale.git
synced 2026-11-19 11:57:07 +09:00
tools/capver: test 429 and dropped-connection retries
This commit is contained in:
1 parent
9a199a7e7e
commit
48416ce089
1 file changed
+20
-2
@@ -16,7 +16,7 @@ func TestFetch(t *testing.T) {
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
statuses []int // served in order; the last one repeats
|
||||
statuses []int // served in order; the last one repeats; 0 drops the connection
|
||||
wantBody string
|
||||
wantErr error
|
||||
wantCalls int32
|
||||
@@ -33,6 +33,18 @@ func TestFetch(t *testing.T) {
|
||||
wantBody: "body",
|
||||
wantCalls: 2,
|
||||
},
|
||||
{
|
||||
name: "rate-limited-then-ok",
|
||||
statuses: []int{http.StatusTooManyRequests, http.StatusOK},
|
||||
wantBody: "body",
|
||||
wantCalls: 2,
|
||||
},
|
||||
{
|
||||
name: "dropped-connection-then-ok",
|
||||
statuses: []int{0, http.StatusOK},
|
||||
wantBody: "body",
|
||||
wantCalls: 2,
|
||||
},
|
||||
{
|
||||
name: "always-unavailable-fails",
|
||||
statuses: []int{http.StatusServiceUnavailable},
|
||||
@@ -53,7 +65,13 @@ func TestFetch(t *testing.T) {
|
||||
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||
n := int(calls.Add(1)) - 1
|
||||
w.WriteHeader(tt.statuses[min(n, len(tt.statuses)-1)])
|
||||
|
||||
status := tt.statuses[min(n, len(tt.statuses)-1)]
|
||||
if status == 0 {
|
||||
panic(http.ErrAbortHandler)
|
||||
}
|
||||
|
||||
w.WriteHeader(status)
|
||||
_, _ = w.Write([]byte("body"))
|
||||
}))
|
||||
defer srv.Close()
|
||||
|
||||
Reference in new issue
Block a user