alamb commented on code in PR #9015:
URL: https://github.com/apache/arrow-datafusion/pull/9015#discussion_r1486734893


##########
datafusion/execution/src/memory_pool/pool.rs:
##########
@@ -310,4 +466,34 @@ mod tests {
         let err = r4.try_grow(30).unwrap_err().strip_backtrace();
         assert_eq!(err, "Resources exhausted: Failed to allocate additional 30 
bytes for s4 with 0 bytes already allocated - maximum available is 20");
     }
+
+    #[test]
+    fn test_greedy() {
+        let pool = Arc::new(GreedyMemoryPool::new(100)) as _;
+        let mut r1 = MemoryConsumer::new("r1").register(&pool);
+
+        // Can grow beyond capacity of pool
+        r1.grow(2000);
+        assert_eq!(pool.reserved(), 2000);
+
+        let mut r2 = MemoryConsumer::new("r2")
+            .with_can_spill(true)
+            .register(&pool);
+        // Can grow beyond capacity of pool
+        r2.grow(2000);
+
+        let err = r1.try_grow(1).unwrap_err().strip_backtrace();
+        assert_eq!(err, "Resources exhausted: Failed to allocate additional 1 
bytes for r1 with 2000 bytes already allocated - maximum available is 0");

Review Comment:
   Sure -- thank you for working on this PR
   
   I was thinking something like this
   
   ```rust
       #[test]
       fn test_display() {
           let greedy_pool = Arc::new(GreedyMemoryPool::new(1000));
           let pool: Arc<dyn MemoryPool> = greedy_pool.clone();
   
           let mut r1 = MemoryConsumer::new("r1").register(&pool);
           let mut r2 = MemoryConsumer::new("r2").register(&pool);
   
           r1.grow(100);
           r2.grow(321);
   
           assert_eq!(
               format!("{}", greedy_pool),
               "GreedyPool 2 allocations, 421 used, 579 free, 1000 
capacity\n\t321: r2\n\t100: r1\n"
           );
       }
   ```
   
   As otherwise we could potentially mess up the formatting of the pool usage 
without any tests failing



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to