You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use insta::{allow_duplicates, assert_snapshot,Settings};
446
447
use std::sync::Arc;
447
448
449
+
fnmake_settings() -> Settings{
450
+
letmut settings = Settings::clone_current();
451
+
settings.add_filter(
452
+
r"([^\s]+)\#\d+\(can spill: (true|false)\)",
453
+
"$1#[ID](can spill: $2)",
454
+
);
455
+
settings
456
+
}
457
+
448
458
#[test]
449
459
fntest_fair(){
450
460
let pool = Arc::new(FairSpillPool::new(100))as_;
@@ -463,10 +473,10 @@ mod tests {
463
473
assert_eq!(pool.reserved(),4000);
464
474
465
475
let err = r2.try_grow(1).unwrap_err().strip_backtrace();
466
-
assert_eq!(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 pool");
476
+
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 pool");
467
477
468
478
let err = r2.try_grow(1).unwrap_err().strip_backtrace();
469
-
assert_eq!(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 pool");
479
+
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 pool");
470
480
471
481
r1.shrink(1990);
472
482
r2.shrink(2000);
@@ -491,12 +501,12 @@ mod tests {
491
501
.register(&pool);
492
502
493
503
let err = r3.try_grow(70).unwrap_err().strip_backtrace();
494
-
assert_eq!(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 pool");
504
+
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 pool");
495
505
496
506
//Shrinking r2 to zero doesn't allow a3 to allocate more than 45
497
507
r2.free();
498
508
let err = r3.try_grow(70).unwrap_err().strip_backtrace();
499
-
assert_eq!(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 pool");
509
+
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 pool");
let err = r4.try_grow(30).unwrap_err().strip_backtrace();
512
-
assert_eq!(err,"Resources exhausted: Failed to allocate additional 30.0 B for s4 with 0.0 B already allocated for this reservation - 20.0 B remain available for the total pool");
522
+
assert_snapshot!(err,@"Resources exhausted: Failed to allocate additional 30.0 B for s4 with 0.0 B already allocated for this reservation - 20.0 B remain available for the total pool");
513
523
}
514
524
515
525
#[test]
516
526
fntest_tracked_consumers_pool(){
527
+
let setting = make_settings();
528
+
let _bound = setting.bind_to_scope();
517
529
let pool:Arc<dynMemoryPool> = Arc::new(TrackConsumersPool::new(
518
530
GreedyMemoryPool::new(100),
519
531
NonZeroUsize::new(3).unwrap(),
@@ -546,19 +558,22 @@ mod tests {
546
558
// Test: reports if new reservation causes error
547
559
// using the previously set sizes for other consumers
let expected = format!("Additional allocation failed with top memory consumers (across reservations) as:\n r1#{}(can spill: false) consumed 50.0 B,\n r3#{}(can spill: false) consumed 20.0 B,\n r2#{}(can spill: false) consumed 15.0 B.\nError: Failed to allocate additional 150.0 B for r5 with 0.0 B already allocated for this reservation - 5.0 B remain available for the total pool", r1.consumer().id(), r3.consumer().id(), r2.consumer().id());
let expected = format!("Additional allocation failed with top memory consumers (across reservations) as:\n foo#{}(can spill: false) consumed 0.0 B.\nError: Failed to allocate additional 150.0 B for foo with 0.0 B already allocated for this reservation - 100.0 B remain available for the total pool", r0.consumer().id());
// TODO: the insufficient_capacity_err() message is per reservation, not per consumer.
588
602
// a followup PR will clarify this message "0 bytes already allocated for this reservation"
589
-
let expected = format!("Additional allocation failed with top memory consumers (across reservations) as:\n foo#{}(can spill: false) consumed 10.0 B,\n foo#{}(can spill: false) consumed 0.0 B.\nError: Failed to allocate additional 150.0 B for foo with 0.0 B already allocated for this reservation - 90.0 B remain available for the total pool", r0.consumer().id(), r1.consumer().id());
"should provide proper error for 2 consumers, instead found {res:?}"
597
-
);
604
+
assert!(res.is_err());
605
+
let error = res.unwrap_err().strip_backtrace();
606
+
assert_snapshot!(error, @r"
607
+
Resources exhausted: Additional allocation failed with top memory consumers (across reservations) as:
608
+
foo#[ID](can spill: false) consumed 10.0 B,
609
+
foo#[ID](can spill: false) consumed 0.0 B.
610
+
Error: Failed to allocate additional 150.0 B for foo with 0.0 B already allocated for this reservation - 90.0 B remain available for the total pool
611
+
");
598
612
599
613
// Test: will accumulate size changes per consumer, not per reservation
600
614
r1.grow(20);
601
-
let expected = format!("Additional allocation failed with top memory consumers (across reservations) as:\n foo#{}(can spill: false) consumed 20.0 B,\n foo#{}(can spill: false) consumed 10.0 B.\nError: Failed to allocate additional 150.0 B for foo with 20.0 B already allocated for this reservation - 70.0 B remain available for the total pool", r1.consumer().id(), r0.consumer().id());
let expected = format!("Additional allocation failed with top memory consumers (across reservations) as:\n foo#{}(can spill: false) consumed 20.0 B,\n foo#{}(can spill: false) consumed 10.0 B,\n foo#{}(can spill: true) consumed 0.0 B.\nError: Failed to allocate additional 150.0 B for foo with 0.0 B already allocated for this reservation - 70.0 B remain available for the total pool", r1.consumer().id(), r0.consumer().id(), r2.consumer().id());
let expected = format!("Additional allocation failed with top memory consumers (across reservations) as:\n r1#{}(can spill: false) consumed 20.0 B,\n r0#{}(can spill: false) consumed 10.0 B.\nError: Failed to allocate additional 150.0 B for r0 with 10.0 B already allocated for this reservation - 70.0 B remain available for the total pool", r1.consumer().id(), r0.consumer().id());
"should provide proper error with only 1 consumer left registered, instead found {res:?}"
658
-
);
669
+
assert!(res.is_err());
670
+
let error = res.unwrap_err().strip_backtrace();
671
+
allow_duplicates!(assert_snapshot!(error, @r"
672
+
Resources exhausted: Additional allocation failed with top memory consumers (across reservations) as:
673
+
r0#[ID](can spill: false) consumed 10.0 B.
674
+
Error: Failed to allocate additional 150.0 B for r0 with 10.0 B already allocated for this reservation - 90.0 B remain available for the total pool
675
+
"));
659
676
660
677
// Test: actual message we see is the `available is 70`. When it should be `available is 90`.
661
678
// This is because the pool.shrink() does not automatically occur within the inner_pool.deregister().
662
-
let expected_90_available = "Failed to allocate additional 150.0 B for r0 with 10.0 B already allocated for this reservation - 90.0 B remain available for the total pool";
"should find that the inner pool will still count all bytes for the deregistered consumer until the reservation is dropped, instead found {res:?}"
670
-
);
680
+
assert!(res.is_err());
681
+
let error = res.unwrap_err().strip_backtrace();
682
+
allow_duplicates!(assert_snapshot!(error, @r"
683
+
Resources exhausted: Additional allocation failed with top memory consumers (across reservations) as:
684
+
r0#[ID](can spill: false) consumed 10.0 B.
685
+
Error: Failed to allocate additional 150.0 B for r0 with 10.0 B already allocated for this reservation - 90.0 B remain available for the total pool
686
+
"));
671
687
672
688
// Test: the registration needs to free itself (or be dropped),
673
689
// for the proper error message
674
-
let expected_90_available = "Failed to allocate additional 150.0 B for r0 with 10.0 B already allocated for this reservation - 90.0 B remain available for the total pool";
0 commit comments