| 1 | package session |
| 2 | |
| 3 | import "testing" |
| 4 | |
| 5 | func TestOldIdleRetirementCannotRemoveNewIdleEpoch(t *testing.T) { |
| 6 | r := &Runtime{} |
| 7 | s := &Service{idleOrder: map[*Runtime]uint64{r: 2}} |
| 8 | if err := s.retireIfUnboundAt(t.Context(), r, 1); err != nil { |
| 9 | t.Fatal(err) |
| 10 | } |
| 11 | if s.idleOrder[r] != 2 { |
| 12 | t.Fatal("stale timer removed new idle retention") |
| 13 | } |
| 14 | } |
| 15 | |
| 16 | func TestIdlePoolSharesBudgetAcrossRootsAndProtectsReboundEntries(t *testing.T) { |
| 17 | var pool IdlePool |
| 18 | a, b := &Service{}, &Service{} |
| 19 | one, two, three := &Runtime{}, &Runtime{}, &Runtime{} |
| 20 | if victims := pool.add(a, one, 180<<20); len(victims) != 0 { |
| 21 | t.Fatal("early eviction") |
| 22 | } |
| 23 | victims := pool.add(b, two, 100<<20) |
| 24 | if len(victims) != 1 || victims[0].service != a || victims[0].runtime != one { |
| 25 | t.Fatalf("global LRU=%+v", victims) |
| 26 | } |
| 27 | pool.remove(two) // Rebinding removes an entry before another root admits work. |
| 28 | if victims := pool.add(a, three, 200<<20); len(victims) != 0 { |
| 29 | t.Fatal("active entry remained charged") |
| 30 | } |
| 31 | pool.remove(two) |
| 32 | if pool.used != 200<<20 { |
| 33 | t.Fatalf("budget=%d", pool.used) |
| 34 | } |
| 35 | } |
| 36 |