From e5becc3e1e1fa9af041411f72b7b5263ad75d406 Mon Sep 17 00:00:00 2001 From: Stephen Sorriaux Date: Mon, 24 Apr 2023 14:40:20 -0400 Subject: [PATCH] feat(testing): add test for Windows platform --- .github/workflows/testing.yml | 61 +++++++++++++++++++++++---- kazoo/handlers/utils.py | 2 +- kazoo/recipe/lock.py | 1 - kazoo/testing/common.py | 6 +-- kazoo/tests/test_cache.py | 6 +++ kazoo/tests/test_eventlet_handler.py | 5 ++- kazoo/tests/test_gevent_handler.py | 4 ++ kazoo/tests/test_hosts.py | 1 - kazoo/tests/test_threading_handler.py | 5 ++- kazoo/tests/util.py | 1 - tox.ini | 2 + 11 files changed, 77 insertions(+), 17 deletions(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index bab6b8ac..f169e3e8 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -17,11 +17,9 @@ jobs: runs-on: ubuntu-latest steps: - - name: Handle the code - uses: actions/checkout@v4 + - uses: actions/checkout@v4 - - name: "Set up Python 3.10" - uses: actions/setup-python@v4 + - uses: actions/setup-python@v4 with: python-version: "3.10" @@ -47,9 +45,8 @@ jobs: needs: [validate] name: > - Test Python ${{ matrix.python-version }}, + Linux - Test Python ${{ matrix.python-version }}, ZK ${{ matrix.zk-version }} - runs-on: ubuntu-latest strategy: @@ -69,8 +66,7 @@ jobs: - python-version: "pypy-3.7" tox-env: pypy3 steps: - - name: Handle the code - uses: actions/checkout@v4 + - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v4 @@ -111,3 +107,52 @@ jobs: - name: Publish Codecov report uses: codecov/codecov-action@v3 + + test_windows: + needs: [validate] + name: Windows - Sanity test using a single version of Python and ZK + + runs-on: windows-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-python@v4 + with: + python-version: "3.10" + + - name: Handle pip cache + uses: actions/cache@v3 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements*.txt') }} + restore-keys: | + ${{ runner.os }}-pip- + + - name: Handle ZK installation cache + uses: actions/cache@v3 + with: + path: zookeeper + key: ${{ runner.os }}-zookeeper + restore-keys: | + ${{ runner.os }}-zookeeper + + # https://github.com/actions/setup-java + - name: Setup Java + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: '17' + + - name: Install required dependencies + run: | + python3 -m pip install --upgrade pip + pip install tox + + - name: Test with tox + run: tox -e py310 + env: + ZOOKEEPER_VERSION: 3.7.1 + ZOOKEEPER_PREFIX: "apache-" + ZOOKEEPER_SUFFIX: "-bin" + ZOOKEEPER_LIB: "lib" + shell: bash diff --git a/kazoo/handlers/utils.py b/kazoo/handlers/utils.py index 9db26c40..858df380 100644 --- a/kazoo/handlers/utils.py +++ b/kazoo/handlers/utils.py @@ -382,7 +382,7 @@ def selector_select( selector.register(fd, events) except (ValueError, OSError) as e: # gevent can raise OSError - raise ValueError('Invalid event mask or fd') from e + raise ValueError("Invalid event mask or fd") from e revents, wevents, xevents = [], [], [] try: diff --git a/kazoo/recipe/lock.py b/kazoo/recipe/lock.py index 59c6d8f3..8a490394 100644 --- a/kazoo/recipe/lock.py +++ b/kazoo/recipe/lock.py @@ -209,7 +209,6 @@ def _watch_session(self, state): return True def _inner_acquire(self, blocking, timeout, ephemeral=True): - # wait until it's our chance to get it.. if self.is_acquired: if not blocking: diff --git a/kazoo/testing/common.py b/kazoo/testing/common.py index a3491993..3c635ef8 100644 --- a/kazoo/testing/common.py +++ b/kazoo/testing/common.py @@ -240,7 +240,7 @@ def classpath(self): jars = glob((os.path.join(self.install_path, "zookeeper-*.jar"))) if jars: # Release build (`ant package`) - jars.extend(glob(os.path.join(self.install_path, "lib/*.jar"))) + jars.extend(glob(os.path.join(self.install_path, "lib", "*.jar"))) jars.extend(glob(os.path.join(self.install_path, "*.jar"))) # support for different file locations on Debian/Ubuntu jars.extend(glob(os.path.join(self.install_path, "log4j-*.jar"))) @@ -253,10 +253,10 @@ def classpath(self): else: # Development build (plain `ant`) jars = glob( - (os.path.join(self.install_path, "build/zookeeper-*.jar")) + (os.path.join(self.install_path, "build", "zookeeper-*.jar")) ) jars.extend( - glob(os.path.join(self.install_path, "build/lib/*.jar")) + glob(os.path.join(self.install_path, "build", "lib", "*.jar")) ) return os.pathsep.join(jars) diff --git a/kazoo/tests/test_cache.py b/kazoo/tests/test_cache.py index 31dabc72..7251db64 100644 --- a/kazoo/tests/test_cache.py +++ b/kazoo/tests/test_cache.py @@ -1,5 +1,6 @@ import gc import importlib +import sys import uuid from unittest.mock import patch, call, Mock @@ -28,6 +29,11 @@ def tearDown(self): def choose_an_installed_handler(self): for handler_module, handler_class in self.HANDLERS: + if ( + handler_module == "kazoo.handlers.gevent" + and sys.platform == "win32" + ): + continue try: mod = importlib.import_module(handler_module) cls = getattr(mod, handler_class) diff --git a/kazoo/tests/test_eventlet_handler.py b/kazoo/tests/test_eventlet_handler.py index 5e897895..2a201a8c 100644 --- a/kazoo/tests/test_eventlet_handler.py +++ b/kazoo/tests/test_eventlet_handler.py @@ -131,7 +131,10 @@ def broken(): r.get() def test_huge_file_descriptor(self): - import resource + try: + import resource + except ImportError: + self.skipTest("resource module unavailable on this platform") from eventlet.green import socket from kazoo.handlers.utils import create_tcp_socket diff --git a/kazoo/tests/test_gevent_handler.py b/kazoo/tests/test_gevent_handler.py index 0745c06d..fb37238d 100644 --- a/kazoo/tests/test_gevent_handler.py +++ b/kazoo/tests/test_gevent_handler.py @@ -1,4 +1,5 @@ import unittest +import sys import pytest @@ -9,6 +10,7 @@ from kazoo.tests import test_client +@pytest.mark.skipif(sys.platform == "win32", reason="does not run on windows") class TestGeventHandler(unittest.TestCase): def setUp(self): try: @@ -77,6 +79,7 @@ def func(): ev.wait() +@pytest.mark.skipif(sys.platform == "win32", reason="does not run on windows") class TestBasicGeventClient(KazooTestCase): def setUp(self): try: @@ -165,6 +168,7 @@ def test_huge_file_descriptor(self): sock.close() +@pytest.mark.skipif(sys.platform == "win32", reason="does not run on windows") class TestGeventClient(test_client.TestClient): def setUp(self): try: diff --git a/kazoo/tests/test_hosts.py b/kazoo/tests/test_hosts.py index 8f8a8110..a2fae1ae 100644 --- a/kazoo/tests/test_hosts.py +++ b/kazoo/tests/test_hosts.py @@ -36,7 +36,6 @@ def test_ipv6(self): assert chroot is None def test_hosts_list(self): - hosts, chroot = collect_hosts("zk01:2181, zk02:2181, zk03:2181") expected1 = [("zk01", 2181), ("zk02", 2181), ("zk03", 2181)] assert hosts == expected1 diff --git a/kazoo/tests/test_threading_handler.py b/kazoo/tests/test_threading_handler.py index 664c444c..77997876 100644 --- a/kazoo/tests/test_threading_handler.py +++ b/kazoo/tests/test_threading_handler.py @@ -45,7 +45,10 @@ def test_double_start_stop(self): assert h._running is False def test_huge_file_descriptor(self): - import resource + try: + import resource + except ImportError: + self.skipTest("resource module unavailable on this platform") import socket from kazoo.handlers.utils import create_tcp_socket diff --git a/kazoo/tests/util.py b/kazoo/tests/util.py index 63514683..836775a8 100644 --- a/kazoo/tests/util.py +++ b/kazoo/tests/util.py @@ -98,7 +98,6 @@ def __init__( getnow=(lambda: time.time), getsleep=(lambda: time.sleep), ): - if timeout is not None: self.timeout = timeout diff --git a/tox.ini b/tox.ini index 7a6cfe07..567acd29 100644 --- a/tox.ini +++ b/tox.ini @@ -32,7 +32,9 @@ deps = allowlist_externals = {toxinidir}/ensure-zookeeper-env.sh {toxinidir}/init_krb5.sh + bash commands = + bash \ sasl: {toxinidir}/init_krb5.sh {envtmpdir}/kerberos \ {toxinidir}/ensure-zookeeper-env.sh \ pytest {posargs: -ra -v --cov-report=xml --cov=kazoo kazoo/tests}