from meshnet_tracker.server import TrackerServer


class _FailingStore:
    def save_to_db(self) -> None:
        raise OSError("database or disk is full")


class _RecordingStore:
    def __init__(self) -> None:
        self.saved = False

    def save_to_db(self) -> None:
        self.saved = True


def test_stats_persistence_failure_does_not_abort_remaining_stores(capsys):
    "Tracker persistence isolates one full-disk failure from other stores\n\nTags: tracker, persistence"
    tracker = TrackerServer()
    tracker._stats = _FailingStore()
    tracker._route_stats = _RecordingStore()
    tracker._billing = None
    tracker._accounts = None
    tracker._contracts = None

    tracker._save_stats_once()

    assert tracker._route_stats.saved is True
    stderr = capsys.readouterr().err
    assert "stats persistence failed" in stderr
    assert "database or disk is full" in stderr
