MCPcopy Create free account
hub / github.com/erans/pgsqlite / test_preloading

Function test_preloading

src/cache/lazy_schema_loader.rs:332–359  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

330
331 #[test]
332 fn test_preloading() {
333 let conn = Connection::open_in_memory().unwrap();
334
335 // Create test tables
336 conn.execute("CREATE TABLE table1 (id INTEGER)", []).unwrap();
337 conn.execute("CREATE TABLE table2 (id INTEGER)", []).unwrap();
338
339 let loader = LazySchemaLoader::new(300);
340
341 // First, load schemas individually to generate cache misses
342 let _ = loader.get_schema(&conn, "table1").unwrap().unwrap();
343 let _ = loader.get_schema(&conn, "table2").unwrap().unwrap();
344
345 // Now accessing again should hit cache
346 let schema1 = loader.get_schema(&conn, "table1").unwrap().unwrap();
347 let schema2 = loader.get_schema(&conn, "table2").unwrap().unwrap();
348
349 assert_eq!(schema1.columns.len(), 1);
350 assert_eq!(schema2.columns.len(), 1);
351
352 // Should have cache hit rate of 0.5 (2 hits out of 4 total requests)
353 let hit_rate = loader.get_cache_hit_rate();
354 assert!(hit_rate >= 0.4, "Expected hit rate >= 0.4, got {hit_rate}");
355
356 // Test preloading functionality
357 let tables = vec!["table1".to_string(), "table2".to_string()];
358 loader.preload_schemas(&conn, &tables).unwrap();
359 }
360}

Callers

nothing calls this directly

Calls 4

get_schemaMethod · 0.80
executeMethod · 0.45
get_cache_hit_rateMethod · 0.45
preload_schemasMethod · 0.45

Tested by

no test coverage detected