MCPcopy Create free account
hub / github.com/apache/datafusion / test_try_shrink

Function test_try_shrink

datafusion/execution/src/memory_pool/mod.rs:632–662  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

630
631 #[test]
632 fn test_try_shrink() {
633 let pool = Arc::new(GreedyMemoryPool::new(100)) as _;
634 let r1 = MemoryConsumer::new("r1").register(&pool);
635
636 r1.try_grow(50).unwrap();
637 assert_eq!(r1.size(), 50);
638 assert_eq!(pool.reserved(), 50);
639
640 // Successful shrink returns new size and frees pool memory
641 let new_size = r1.try_shrink(30).unwrap();
642 assert_eq!(new_size, 20);
643 assert_eq!(r1.size(), 20);
644 assert_eq!(pool.reserved(), 20);
645
646 // Freed pool memory is now available to other consumers
647 let r2 = MemoryConsumer::new("r2").register(&pool);
648 r2.try_grow(80).unwrap();
649 assert_eq!(pool.reserved(), 100);
650
651 // Shrinking more than allocated fails without changing state
652 let err = r1.try_shrink(25);
653 assert!(err.is_err());
654 assert_eq!(r1.size(), 20);
655 assert_eq!(pool.reserved(), 100);
656
657 // Shrink to exactly zero
658 let new_size = r1.try_shrink(20).unwrap();
659 assert_eq!(new_size, 0);
660 assert_eq!(r1.size(), 0);
661 assert_eq!(pool.reserved(), 80);
662 }
663}

Callers

nothing calls this directly

Calls 4

newFunction · 0.85
try_shrinkMethod · 0.80
registerMethod · 0.45
try_growMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…