MCPcopy Create free account
hub / github.com/ContentSquare/chproxy / TestKeyExpirationWhileFetchtingRedis

Function TestKeyExpirationWhileFetchtingRedis

cache/redis_cache_test.go:144–172  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

142}
143
144func TestKeyExpirationWhileFetchtingRedis(t *testing.T) {
145 cache, redis := getRedisCacheAndServer(t)
146 defer cache.Close()
147
148 key := &Key{
149 Query: []byte(fmt.Sprintf("SELECT test")),
150 }
151 payloadSize := 4 * 1024 * 1024
152 exepctedValue := strings.Repeat("a", payloadSize)
153 reader := strings.NewReader(exepctedValue)
154
155 if _, err := cache.Put(reader, ContentMetadata{Encoding: "ce", Type: "ct", Length: int64(payloadSize)}, key); err != nil {
156 t.Fatalf("failed to put it to cache: %s", err)
157 }
158 cachedData, err := cache.Get(key)
159 if err != nil {
160 t.Fatalf("failed to get data from redis cache: %s", err)
161 }
162
163 //simulating a cache expiration
164 if !redis.Del(key.String()) {
165 t.Fatalf("could not delete key")
166 }
167 _, err = io.ReadAll(cachedData.Data)
168 _, isRedisCacheError := err.(*RedisCacheError)
169 if err == nil || !isRedisCacheError {
170 t.Fatalf("expecting an error of type RedisCacheError, err=%s", err)
171 }
172}
173
174func TestCorruptedPayloadWhileFetchtingRedis(t *testing.T) {
175 cache, redis := getRedisCacheAndServer(t)

Callers

nothing calls this directly

Calls 5

StringMethod · 0.95
getRedisCacheAndServerFunction · 0.85
PutMethod · 0.65
GetMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected