Skip to content

Commit

Permalink
feat(testing): add test for Windows platform
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenSorriaux committed Apr 24, 2023
1 parent b39ca37 commit 623bf83
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 11 deletions.
54 changes: 52 additions & 2 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,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:
Expand Down Expand Up @@ -111,3 +110,54 @@ jobs:

- name: Publish Codecov report
uses: codecov/codecov-action@v3

test_windows:
needs: [validate]
name: Windows - Test Python 3.10, ZK 3.7.1

runs-on: windows-latest
steps:
- name: Handle the code
uses: actions/checkout@v3

- name: "Set up Python 3.10"
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
2 changes: 1 addition & 1 deletion kazoo/handlers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion kazoo/recipe/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions kazoo/testing/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")))
Expand All @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions kazoo/tests/test_cache.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import gc
import importlib
import sys
import uuid

from unittest.mock import patch, call, Mock
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion kazoo/tests/test_eventlet_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions kazoo/tests/test_gevent_handler.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import unittest
import sys

import pytest

Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion kazoo/tests/test_hosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion kazoo/tests/test_threading_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion kazoo/tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ def __init__(
getnow=(lambda: time.time),
getsleep=(lambda: time.sleep),
):

if timeout is not None:
self.timeout = timeout

Expand Down
2 changes: 2 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit 623bf83

Please sign in to comment.