-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Drop IP/mDNS validation and add a (local) test
The test does not mock anything out and depends on the correct IP address / host name being specified via environmental variables. Of note, I had experienced a peculiar issue with using a host name which was mapped to multiple IP addresses in my /etc/hosts. Curiously, this meant that the retrieval from the cache fetched the last IP in the file, not, actually, the one used upon the original resolution. This meant that AirQ.get worked perfectly when the DNS was resolved de-novo, but timed out when it was cached. While I am not sure if it is a bug or a feature of aiohttp, it is, perhaps, irrelevant for this module and the entire test parametrisation, which disables dns caching can be removed
- Loading branch information
1 parent
b8a0d0a
commit c3ea879
Showing
5 changed files
with
39 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import os | ||
|
||
import aiohttp | ||
import pytest | ||
import pytest_asyncio | ||
|
||
from aioairq import AirQ | ||
|
||
SUBJECT = "ping" | ||
|
||
PASS = os.environ.get("AIRQ_PASS", "placeholder_password") | ||
IP = os.environ.get("AIRQ_IP", "192.168.0.0") | ||
MDNS = os.environ.get("AIRQ_MDNS", "a123f_air-q.local") | ||
HOSTNAME = os.environ.get("AIRQ_HOSTNAME", "air-q") | ||
|
||
|
||
@pytest_asyncio.fixture() | ||
async def session(): | ||
session = aiohttp.ClientSession() | ||
yield session | ||
await session.close() | ||
|
||
|
||
@pytest.mark.asyncio | ||
@pytest.mark.parametrize("address", [IP, HOSTNAME]) | ||
@pytest.mark.parametrize("repeat_call", [False, True]) | ||
async def test_dns_caching_by_repeated_calls(address, repeat_call, session): | ||
"""Test if a repeated .get request results in a timeout | ||
when DNS needs to be resolved / looked up from a cache. | ||
""" | ||
airq = AirQ(address, PASS, session, timeout=5) | ||
await airq.get(SUBJECT) | ||
if repeat_call: | ||
await airq.get(SUBJECT) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters