Test that a variant is made from a cached source of a negative-cached URL
check / check (push) Canceled after 0s
check / check (push) Canceled after 0s
The negative cache refuses only a fetch from the upstream: a variant not in the cache is made from the cached source, and refused once that source is evicted. Model: opus-5-5
This commit is contained in:
@@ -97,8 +97,9 @@ func TestNegativeCache_Expired(t *testing.T) {
|
|||||||
// TestService_Get_ServesCachedVariantOfNegativeCachedURL caches a variant of
|
// TestService_Get_ServesCachedVariantOfNegativeCachedURL caches a variant of
|
||||||
// the test photo, then keeps a failed fetch of the photo's URL in the negative
|
// the test photo, then keeps a failed fetch of the photo's URL in the negative
|
||||||
// cache, as a failed fetch for another variant does once the source has been
|
// cache, as a failed fetch for another variant does once the source has been
|
||||||
// evicted. The cached variant is still served; a variant not in the cache is
|
// evicted. The cached variant is still served, and a variant not in the cache
|
||||||
// still refused.
|
// is made from the cached source. Once the source is evicted, a variant not in
|
||||||
|
// the cache needs a fetch and is refused.
|
||||||
func TestService_Get_ServesCachedVariantOfNegativeCachedURL(t *testing.T) {
|
func TestService_Get_ServesCachedVariantOfNegativeCachedURL(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
@@ -129,11 +130,31 @@ func TestService_Get_ServesCachedVariantOfNegativeCachedURL(t *testing.T) {
|
|||||||
resp.CacheStatus, CacheHit)
|
resp.CacheStatus, CacheHit)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = svc.Get(t.Context(), photoVariant(fixtures, 40, FitCover))
|
resp, err = svc.Get(t.Context(), photoVariant(fixtures, 40, FitCover))
|
||||||
t.Logf("Get() of a variant not in the cache: error = %v", err)
|
t.Logf("Get() of a variant made from the cached source: error = %v", err)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Get() of a variant made from the cached source error = %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
_ = resp.Content.Close()
|
||||||
|
|
||||||
|
contentHash, _, err := svc.cache.LookupSource(t.Context(),
|
||||||
|
photoVariant(fixtures, 85, FitCover))
|
||||||
|
if err != nil || contentHash == "" {
|
||||||
|
t.Fatalf("LookupSource() = %q, %v, want the cached source", contentHash, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = svc.cache.evictSourceBlob(t.Context(), contentHash)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("evictSourceBlob() error = %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = svc.Get(t.Context(), photoVariant(fixtures, 60, FitCover))
|
||||||
|
t.Logf("Get() of a variant whose source was evicted: error = %v", err)
|
||||||
|
|
||||||
if !errors.Is(err, ErrNegativeCached) {
|
if !errors.Is(err, ErrNegativeCached) {
|
||||||
t.Errorf("Get() of a variant not in the cache error = %v, want %v",
|
t.Errorf("Get() of a variant whose source was evicted error = %v, want %v",
|
||||||
err, ErrNegativeCached)
|
err, ErrNegativeCached)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user