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

Function test_fair

datafusion/execution/src/memory_pool/pool.rs:631–695  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

629
630 #[test]
631 fn test_fair() {
632 let pool = Arc::new(FairSpillPool::new(100)) as _;
633
634 let r1 = MemoryConsumer::new("unspillable").register(&pool);
635 // Can grow beyond capacity of pool
636 r1.grow(2000);
637 assert_eq!(pool.reserved(), 2000);
638
639 let r2 = MemoryConsumer::new("r2")
640 .with_can_spill(true)
641 .register(&pool);
642 // Can grow beyond capacity of pool
643 r2.grow(2000);
644
645 assert_eq!(pool.reserved(), 4000);
646
647 let err = r2.try_grow(1).unwrap_err().strip_backtrace();
648 assert_snapshot!(err, @"Resources exhausted: Failed to allocate additional 1.0 B for r2 with 2000.0 B already allocated for this reservation - 0.0 B remain available for the total memory pool: fair(pool_size: 100.0 B)");
649
650 let err = r2.try_grow(1).unwrap_err().strip_backtrace();
651 assert_snapshot!(err, @"Resources exhausted: Failed to allocate additional 1.0 B for r2 with 2000.0 B already allocated for this reservation - 0.0 B remain available for the total memory pool: fair(pool_size: 100.0 B)");
652
653 r1.shrink(1990);
654 r2.shrink(2000);
655
656 assert_eq!(pool.reserved(), 10);
657
658 r1.try_grow(10).unwrap();
659 assert_eq!(pool.reserved(), 20);
660
661 // Can grow r2 to 80 as only spilling consumer
662 r2.try_grow(80).unwrap();
663 assert_eq!(pool.reserved(), 100);
664
665 r2.shrink(70);
666
667 assert_eq!(r1.size(), 20);
668 assert_eq!(r2.size(), 10);
669 assert_eq!(pool.reserved(), 30);
670
671 let r3 = MemoryConsumer::new("r3")
672 .with_can_spill(true)
673 .register(&pool);
674
675 let err = r3.try_grow(70).unwrap_err().strip_backtrace();
676 assert_snapshot!(err, @"Resources exhausted: Failed to allocate additional 70.0 B for r3 with 0.0 B already allocated for this reservation - 40.0 B remain available for the total memory pool: fair(pool_size: 100.0 B)");
677
678 //Shrinking r2 to zero doesn't allow a3 to allocate more than 45
679 r2.free();
680 let err = r3.try_grow(70).unwrap_err().strip_backtrace();
681 assert_snapshot!(err, @"Resources exhausted: Failed to allocate additional 70.0 B for r3 with 0.0 B already allocated for this reservation - 40.0 B remain available for the total memory pool: fair(pool_size: 100.0 B)");
682
683 // But dropping r2 does
684 drop(r2);
685 assert_eq!(pool.reserved(), 20);
686 r3.try_grow(80).unwrap();
687
688 assert_eq!(pool.reserved(), 100);

Callers

nothing calls this directly

Calls 9

newFunction · 0.85
with_can_spillMethod · 0.80
strip_backtraceMethod · 0.80
unwrap_errMethod · 0.80
freeMethod · 0.80
registerMethod · 0.45
growMethod · 0.45
try_growMethod · 0.45
shrinkMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…