botp
/

File size: 780 Bytes
1d2de8a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import json

import pytest

from solomon_mlx.budget import Budget


def test_budget_reserves_before_dispatch_and_exhausts(tmp_path):
    path = tmp_path / "budget.json"
    budget = Budget(path, 20)
    with budget.reserve(15, "one"):
        assert json.loads(path.read_text())["entries"][0]["status"] == "reserved"
        with pytest.raises(RuntimeError), budget.reserve(1, "concurrent"):
            pass
    with pytest.raises(RuntimeError), budget.reserve(6, "too expensive"):
        pass


def test_uncertain_dispatch_blocks_followups(tmp_path):
    budget = Budget(tmp_path / "budget.json")
    with pytest.raises(TimeoutError), budget.reserve(20, "uncertain"):
        raise TimeoutError()
    with pytest.raises(RuntimeError), budget.reserve(20, "retry"):
        pass