From 927312b5ae96dfe6fea5c6750c11fd46410dcd4b Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Fri, 18 Mar 2022 13:18:21 +0000 Subject: [PATCH] Use gethostname instead of potentially slow getfqdn This avoid bug that is adding 30s on some machines where getfqdn() is very slow, as this is caused by an unsolved python bug. Related: https://bugs.python.org/issue35164 Fixes: #2375 --- docs/changelog/2375.bugfix.rst | 1 + src/tox/logs/result.py | 2 +- tests/unit/test_result.py | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 docs/changelog/2375.bugfix.rst diff --git a/docs/changelog/2375.bugfix.rst b/docs/changelog/2375.bugfix.rst new file mode 100644 index 000000000..d50b18ce3 --- /dev/null +++ b/docs/changelog/2375.bugfix.rst @@ -0,0 +1 @@ +Avoid potential 30s delay caused by socket.getfqdn(). -- by :user:`ssbarnea` diff --git a/src/tox/logs/result.py b/src/tox/logs/result.py index 73d61039f..d81e22b8a 100644 --- a/src/tox/logs/result.py +++ b/src/tox/logs/result.py @@ -22,7 +22,7 @@ def __init__(self): "reportversion": "1", "toxversion": __version__, "platform": sys.platform, - "host": os.getenv(str("HOSTNAME")) or socket.getfqdn(), + "host": os.getenv(str("HOSTNAME")) or socket.gethostname(), "commands": command_log, } diff --git a/tests/unit/test_result.py b/tests/unit/test_result.py index efbd3f9cb..3b7ee89b4 100644 --- a/tests/unit/test_result.py +++ b/tests/unit/test_result.py @@ -31,7 +31,7 @@ def test_pre_set_header(clean_hostname_envvar): assert replog.dict["reportversion"] == "1" assert replog.dict["toxversion"] == tox.__version__ assert replog.dict["platform"] == sys.platform - assert replog.dict["host"] == socket.getfqdn() + assert replog.dict["host"] == socket.gethostname() data = replog.dumps_json() replog2 = ResultLog.from_json(data) assert replog2.dict == replog.dict @@ -44,7 +44,7 @@ def test_set_header(pkg, clean_hostname_envvar): assert replog.dict["reportversion"] == "1" assert replog.dict["toxversion"] == tox.__version__ assert replog.dict["platform"] == sys.platform - assert replog.dict["host"] == socket.getfqdn() + assert replog.dict["host"] == socket.gethostname() expected = {"basename": "hello-1.0.tar.gz", "sha256": pkg.computehash("sha256")} env_log = replog.get_envlog("a") env_log.set_header(installpkg=pkg)