From 74100623298ee909603f03685b1ff562785d087c Mon Sep 17 00:00:00 2001 From: Fabio Huser Date: Sun, 8 Aug 2021 19:32:52 +0200 Subject: [PATCH] Add 429 retry batch scenario to lfstest While the storage endpoint within lfstest-gitserver was already able to simulate a 429 "retry-after" scenario, the same support for the LFS batch API endpoint was missing. This commit adds this support in a similar manner to- and re-using the "checkRateLimit" function from the storage endpoint handler. --- t/cmd/lfstest-gitserver.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/t/cmd/lfstest-gitserver.go b/t/cmd/lfstest-gitserver.go index b50a694e..e7440562 100644 --- a/t/cmd/lfstest-gitserver.go +++ b/t/cmd/lfstest-gitserver.go @@ -409,6 +409,17 @@ func lfsBatchHandler(w http.ResponseWriter, r *http.Request, id, repo string) { } } + if strings.HasSuffix(repo, "batch-retry-later") { + if timeLeft, isWaiting := checkRateLimit("batch", "", repo, ""); isWaiting { + w.Header().Set("Retry-After", strconv.Itoa(timeLeft)) + w.WriteHeader(http.StatusTooManyRequests) + + w.Write([]byte("rate limit reached")) + fmt.Println("Setting header to: ", strconv.Itoa(timeLeft)) + return + } + } + res := []lfsObject{} testingChunked := testingChunkedTransferEncoding(r) testingTus := testingTusUploadInBatchReq(r)