Skip to content

Commit

Permalink
WIP: ci: add a job for Windows testing
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenSorriaux committed Apr 24, 2023
1 parent 2c36d69 commit 8c747d4
Show file tree
Hide file tree
Showing 10 changed files with 149 additions and 85 deletions.
181 changes: 113 additions & 68 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,106 @@ on:
- release/*

jobs:
validate:
name: Code Validation

runs-on: ubuntu-latest

# validate:
# name: Code Validation

# runs-on: ubuntu-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: Install required dependencies
# run: |
# python3 -m pip install --upgrade pip
# pip install tox
# - name: Code check
# run: tox -e ${TOX_VENV}
# env:
# TOX_VENV: black,pep8,mypy

# test:
# needs: [validate]

# name: >
# Test Python ${{ matrix.python-version }},
# ZK ${{ matrix.zk-version }}
# runs-on: ubuntu-latest

# strategy:
# fail-fast: false
# matrix:
# python-version: ["3.7", "3.8", "3.9", "3.10", "pypy-3.7"]
# zk-version: ["3.4.14", "3.5.10", "3.6.3", "3.7.1"]
# include:
# - python-version: "3.7"
# tox-env: py37
# - python-version: "3.8"
# tox-env: py38
# - python-version: "3.9"
# tox-env: py39
# - python-version: "3.10"
# tox-env: py310
# - python-version: "pypy-3.7"
# tox-env: pypy3
# steps:
# - name: Handle the code
# uses: actions/checkout@v3

# - name: Set up Python ${{ matrix.python-version }}
# uses: actions/setup-python@v4
# with:
# python-version: ${{ matrix.python-version }}

# - 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
# - name: Install required dependencies
# run: |
# sudo apt-get -y install libevent-dev krb5-kdc krb5-admin-server libkrb5-dev
# python3 -m pip install --upgrade pip
# pip install tox
# - name: Test with tox
# run: tox -e ${TOX_VENV}
# env:
# TOX_VENV: ${{ format('{0}-{1}', matrix.tox-env, 'gevent-eventlet-sasl') }}
# ZOOKEEPER_VERSION: ${{ matrix.zk-version }}
# # TODO: can be removed once tests for ZK 3.4 are removed
# ZOOKEEPER_PREFIX: "${{ !contains(matrix.zk-version, '3.4') && 'apache-' || '' }}"
# ZOOKEEPER_SUFFIX: "${{ !contains(matrix.zk-version, '3.4') && '-bin' || '' }}"
# ZOOKEEPER_LIB: "${{ !contains(matrix.zk-version, '3.4') && 'lib' || '' }}"

# - 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
Expand All @@ -33,58 +128,6 @@ jobs:
restore-keys: |
${{ runner.os }}-pip-
- name: Install required dependencies
run: |
python3 -m pip install --upgrade pip
pip install tox
- name: Code check
run: tox -e ${TOX_VENV}
env:
TOX_VENV: black,pep8,mypy

test:
needs: [validate]

name: >
Test Python ${{ matrix.python-version }},
ZK ${{ matrix.zk-version }}
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "pypy-3.7"]
zk-version: ["3.4.14", "3.5.10", "3.6.3", "3.7.1"]
include:
- python-version: "3.7"
tox-env: py37
- python-version: "3.8"
tox-env: py38
- python-version: "3.9"
tox-env: py39
- python-version: "3.10"
tox-env: py310
- python-version: "pypy-3.7"
tox-env: pypy3
steps:
- name: Handle the code
uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- 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:
Expand All @@ -93,21 +136,23 @@ jobs:
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: |
sudo apt-get -y install libevent-dev krb5-kdc krb5-admin-server libkrb5-dev
python3 -m pip install --upgrade pip
pip install tox
- name: Test with tox
run: tox -e ${TOX_VENV}
run: tox -e py310
env:
TOX_VENV: ${{ format('{0}-{1}', matrix.tox-env, 'gevent-eventlet-sasl') }}
ZOOKEEPER_VERSION: ${{ matrix.zk-version }}
# TODO: can be removed once tests for ZK 3.4 are removed
ZOOKEEPER_PREFIX: "${{ !contains(matrix.zk-version, '3.4') && 'apache-' || '' }}"
ZOOKEEPER_SUFFIX: "${{ !contains(matrix.zk-version, '3.4') && '-bin' || '' }}"
ZOOKEEPER_LIB: "${{ !contains(matrix.zk-version, '3.4') && 'lib' || '' }}"

- name: Publish Codecov report
uses: codecov/codecov-action@v3
ZOOKEEPER_VERSION: 3.7.1
ZOOKEEPER_PREFIX: "apache-"
ZOOKEEPER_SUFFIX: "-bin"
ZOOKEEPER_LIB: "lib"
shell: bash
10 changes: 7 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,13 @@ 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
raise ValueError('Invalid event mask or fd') from e
except KeyError as e:
raise KeyError('fd is already registered') from e

revents, wevents, xevents = [], [], []
try:
Expand Down
2 changes: 1 addition & 1 deletion kazoo/protocol/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ def _connect_attempt(self, host, hostip, port, retry):
return STOP_CONNECTING
except (ConnectionDropped, KazooTimeoutError) as e:
if isinstance(e, ConnectionDropped):
self.logger.warning("Connection dropped: %s", e)
self.logger.exception("Connection dropped: %s", e)
else:
self.logger.warning("Connection time-out: %s", e)
if client._state != KeeperState.CONNECTING:
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
7 changes: 6 additions & 1 deletion kazoo/tests/test_eventlet_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,12 @@ 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
6 changes: 4 additions & 2 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 @@ -76,7 +78,7 @@ def func():
h.dispatch_callback(call1)
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 @@ -164,7 +166,7 @@ def test_huge_file_descriptor(self):
for sock in socks:
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
7 changes: 1 addition & 6 deletions kazoo/tests/test_selectors_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,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
7 changes: 6 additions & 1 deletion kazoo/tests/test_threading_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ 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
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 8c747d4

Please sign in to comment.