diff options
author | Nirbheek Chauhan <nirbheek@centricular.com> | 2019-07-19 14:29:13 +0530 |
---|---|---|
committer | Nirbheek Chauhan <nirbheek@centricular.com> | 2019-07-19 14:29:13 +0530 |
commit | f6a338b8771756b838941178a4566245014c4220 (patch) | |
tree | 577a54ea1e3b2aa5ad4f195f9630663c0dfcec97 | |
parent | 43aae8243c35b63ed6764ed1ed2cf5ef0010c887 (diff) | |
download | meson-nirbheek/unittest-urlopen-timeout.tar.gz |
unit tests: Use a timeout for tests that use the networknirbheek/unittest-urlopen-timeout
It's better to quickly skip when the network is unavailable or slow.
-rwxr-xr-x | run_unittests.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/run_unittests.py b/run_unittests.py index 7bd459d45..0bb532a4b 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -68,6 +68,10 @@ from run_tests import ( run_configure_inprocess, run_mtest_inprocess ) + +URLOPEN_TIMEOUT = 5 + + def get_dynamic_section_entry(fname, entry): if is_cygwin() or is_osx(): raise unittest.SkipTest('Test only applicable to ELF platforms') @@ -1150,7 +1154,9 @@ class DataTests(unittest.TestCase): interp = Interpreter(FakeBuild(env), mock=True) url = 'https://raw.githubusercontent.com/TingPing/language-meson/master/grammars/meson.json' try: - r = urllib.request.urlopen(url) + # Use a timeout to avoid blocking forever in case the network is + # slow or unavailable in a weird way + r = urllib.request.urlopen(url, timeout=URLOPEN_TIMEOUT) except urllib.error.URLError as e: # Skip test when network is not available, such as during packaging # by a distro or Flatpak |