Skip to content

Commit

Permalink
Clean tests
Browse files Browse the repository at this point in the history
  • Loading branch information
laky55555 committed Oct 18, 2022
1 parent f61c42e commit 0369b5b
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions tests/test_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -2179,21 +2179,23 @@ def test_not_expired_ttl(self) -> None:
dns_cache_table.add("localhost", ["127.0.0.1"])
assert not dns_cache_table.expired("localhost")

async def test_expired_ttl(self, loop: Any, monkeypatch: Any) -> None:
dns_cache_table = _DNSCacheTable(ttl=0.01)
def test_expired_ttl(self, monkeypatch: pytest.MonkeyPatch) -> None:
dns_cache_table = _DNSCacheTable(ttl=1)
monkeypatch.setattr("aiohttp.connector.monotonic", lambda: 1)
dns_cache_table.add("localhost", ["127.0.0.1"])
monkeypatch.setattr("aiohttp.connector.monotonic", lambda: 1.02)
monkeypatch.setattr("aiohttp.connector.monotonic", lambda: 2)
assert not dns_cache_table.expired("localhost")
monkeypatch.setattr("aiohttp.connector.monotonic", lambda: 3)
assert dns_cache_table.expired("localhost")

async def test_never_expire(self, loop: Any, monkeypatch: Any) -> None:
def test_never_expire(self, monkeypatch: pytest.MonkeyPatch) -> None:
dns_cache_table = _DNSCacheTable(ttl=None)
monkeypatch.setattr("aiohttp.connector.monotonic", lambda: 1)
dns_cache_table.add("localhost", ["127.0.0.1"])
monkeypatch.setattr("aiohttp.connector.monotonic", lambda: 10000000)
assert not dns_cache_table.expired("localhost")

async def test_always_expire(self, loop: Any) -> None:
def test_always_expire(self) -> None:
dns_cache_table = _DNSCacheTable(ttl=0)
dns_cache_table.add("localhost", ["127.0.0.1"])
assert dns_cache_table.expired("localhost")
Expand Down

0 comments on commit 0369b5b

Please sign in to comment.