MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / updating_cache_values

Function updating_cache_values

src/secrets/src/cache.rs:300–338  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

298
299 #[mz_ore::test(tokio::test)]
300 async fn updating_cache_values() {
301 let controller = InMemorySecretsController::new();
302 let testing_reader = TestingSecretsReader::new(controller.reader());
303 let caching_reader = CachingSecretsReader::new(Arc::new(testing_reader.clone()));
304
305 let secret = [42, 42, 42, 42];
306 let id = CatalogItemId::User(1);
307
308 // Store an initial value.
309 controller.ensure(id, &secret).await.expect("success");
310 // Read to load the value into the cache.
311 caching_reader.read(id).await.expect("success");
312
313 // Update the stored secret.
314 let new_secret = [100, 100];
315 controller.ensure(id, &new_secret).await.expect("success");
316
317 // Reading from the cache should give us the _old_ value.
318 let cached_secret = caching_reader.read(id).await.expect("success");
319 assert_eq!(cached_secret, secret);
320
321 // We should only have registered one read, since we made a stale read from the cache.
322 let reads = testing_reader.drain();
323 assert_eq!(reads.len(), 1);
324
325 // Wait for the secret to expire.
326 caching_reader.set_ttl(Duration::from_secs(2));
327 std::thread::sleep(Duration::from_secs(2));
328
329 // Since the cache value is expired, we should read from source, and get the new value.
330 let read1 = caching_reader.read(id).await.expect("success");
331 let read2 = caching_reader.read(id).await.expect("success");
332 assert_eq!(read1, new_secret);
333 assert_eq!(read1, read2);
334
335 // Should only have one read since we updated the cache.
336 let reads = testing_reader.drain();
337 assert_eq!(reads.len(), 1);
338 }
339
340 #[mz_ore::test(tokio::test)]
341 async fn test_invalidate() {

Callers

nothing calls this directly

Calls 9

sleepFunction · 0.85
expectMethod · 0.80
set_ttlMethod · 0.80
UserClass · 0.50
readerMethod · 0.45
cloneMethod · 0.45
ensureMethod · 0.45
readMethod · 0.45
drainMethod · 0.45

Tested by

no test coverage detected