Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): fix for Windows platform #681

Merged
merged 2 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 53 additions & 8 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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
StephenSorriaux marked this conversation as resolved.
Show resolved Hide resolved
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
StephenSorriaux marked this conversation as resolved.
Show resolved Hide resolved
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
8 changes: 5 additions & 3 deletions kazoo/handlers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from collections import defaultdict
import errno
import functools
import os
import select
import selectors
import ssl
Expand Down Expand Up @@ -349,7 +348,6 @@ def fileobj_to_fd(fileobj):
raise TypeError("Invalid file object: " "{!r}".format(fileobj))
if fd < 0:
raise TypeError("Invalid file descriptor: {}".format(fd))
os.fstat(fd)
return fd


Expand Down Expand Up @@ -380,7 +378,11 @@ def selector_select(

selector = selectors_module.DefaultSelector()
for fd, events in fd_events.items():
selector.register(fd, events)
try:
selector.register(fd, events)
except (ValueError, OSError) as e:
# gevent can raise OSError
StephenSorriaux marked this conversation as resolved.
Show resolved Hide resolved
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")
StephenSorriaux marked this conversation as resolved.
Show resolved Hide resolved
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")
StephenSorriaux marked this conversation as resolved.
Show resolved Hide resolved
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
8 changes: 1 addition & 7 deletions kazoo/tests/test_selectors_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
to test the selector_select function.
"""

import errno
import os
import socket
import sys
Expand Down Expand Up @@ -41,12 +40,7 @@ def test_errno(self):
with open(__file__, "rb") as fp:
fd = fp.fileno()
fp.close()
try:
select([fd], [], [], 0)
except OSError as err:
self.assertEqual(err.errno, errno.EBADF)
else:
self.fail("exception not raised")
self.assertRaises(ValueError, select, [fd], [], [], 0)

def test_returned_list_identity(self):
# See issue #8329
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