test: proxy HTTP error branches (403/502) + revalidation upstream error
This commit is contained in:
@@ -361,6 +361,34 @@ func TestWaitForStoreCoalesces(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRevalidationUpstreamError(t *testing.T) {
|
||||
requireStack(t)
|
||||
ctx := context.Background()
|
||||
r := seed(t, models.Remote{Name: "eng-reval-err", PackageType: models.PackageNPM, RepoType: models.RepoTypeRemote, BaseURL: upstream.URL, CheckMutable: true, MutableTTL: 3600, StaleOnError: true})
|
||||
p := prov(t, models.PackageNPM)
|
||||
|
||||
res, err := testEngine.Fetch(ctx, r, "pkg", p)
|
||||
if err != nil {
|
||||
t.Fatalf("initial fetch: %v", err)
|
||||
}
|
||||
res.Reader.Close()
|
||||
|
||||
// Expire freshness but keep the ETag, then break the upstream: the
|
||||
// conditional HEAD (checkUpstream) errors, and stale-on-error serves the
|
||||
// stored index.
|
||||
testCache.SetTTL(ctx, "eng-reval-err", "pkg", time.Millisecond)
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
r.BaseURL = "http://127.0.0.1:1"
|
||||
res, err = testEngine.Fetch(ctx, r, "pkg", p)
|
||||
if err != nil {
|
||||
t.Fatalf("expected stale serve on revalidation error, got %v", err)
|
||||
}
|
||||
if res.Source != "cache" {
|
||||
t.Errorf("expected stale cache source, got %s", res.Source)
|
||||
}
|
||||
res.Reader.Close()
|
||||
}
|
||||
|
||||
func TestUpstreamErrorUnwrap(t *testing.T) {
|
||||
base := context.DeadlineExceeded
|
||||
ue := &UpstreamError{Err: base}
|
||||
|
||||
Reference in New Issue
Block a user