Skip to content

Commit

Permalink
[WIP] CI: Added tests on FreeBSD, OpenBSD & NetBSD
Browse files Browse the repository at this point in the history
  • Loading branch information
francis-clairicia committed Oct 20, 2024
1 parent 51bc68a commit efe3db7
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 18 deletions.
103 changes: 103 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,106 @@ jobs:
test-functional,
OS-${{ runner.os }},
Py-${{ matrix.python_version }}
test-freebsd:
# TODO: Add this when the workflow is stable.
# if: |
# (github.event_name != 'push' || !startsWith(github.event.head_commit.message, 'Bump version:'))
# && (github.event_name != 'pull_request' || (github.event.pull_request.draft != true && !contains(github.event.pull_request.labels.*.name, 'pr-skip-test')))
if: false
runs-on: ubuntu-24.04

name: test (FreeBSD, 3.11)
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Launch tests
timeout-minutes: 20
uses: vmactions/freebsd-vm@v1
with:
release: '14.1'
usesh: true
# py311-sqlite3 is needed for coverage.py
prepare: |
set -e
pkg install -y curl git python311 py311-sqlite3
curl -sSL https://pdm-project.org/install-pdm.py | python3.11 - --version=2.19.3 --path=/usr/local
pdm config check_update false
pdm config install.cache true
run: |
pdm install --frozen-lockfile --global --project=. --no-self --no-default --dev --group=tox
tox --version
tox run -f py311
tox run -f coverage
rm -rf .tox
find . -name '__pycache__' | xargs rm -rf
- name: Check files in workspace
if: always()
run: ls -lA

test-openbsd:
# TODO: Add this when the workflow is stable.
# if: |
# (github.event_name != 'push' || !startsWith(github.event.head_commit.message, 'Bump version:'))
# && (github.event_name != 'pull_request' || (github.event.pull_request.draft != true && !contains(github.event.pull_request.labels.*.name, 'pr-skip-test')))
runs-on: ubuntu-24.04

name: test (OpenBSD, 3.11)
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Launch tests
timeout-minutes: 20
uses: vmactions/openbsd-vm@v1
with:
release: '7.6'
usesh: true
prepare: |
set -e
pkg_add -v -r curl git python
curl -sSL https://pdm-project.org/install-pdm.py | python3.11 - --version=2.19.3 --path=/usr/local
run: |
python3.11 -VV
- name: Check files in workspace
if: always()
run: ls -lA

test-netbsd:
# TODO: Add this when the workflow is stable.
# if: |
# (github.event_name != 'push' || !startsWith(github.event.head_commit.message, 'Bump version:'))
# && (github.event_name != 'pull_request' || (github.event.pull_request.draft != true && !contains(github.event.pull_request.labels.*.name, 'pr-skip-test')))
if: false
runs-on: ubuntu-24.04

name: test (NetBSD, 3.11)
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Launch tests
timeout-minutes: 20
uses: vmactions/netbsd-vm@v1
with:
release: '10.0'
usesh: true
prepare: |
set -e
/usr/sbin/pkg_add -v pkgin
pkgin update
pkgin -y install curl git python311-*
curl -sSL https://pdm-project.org/install-pdm.py | python3.11 - --version=2.19.3 --path=/usr/local
pdm config check_update false
pdm config install.cache true
run: |
pdm install --frozen-lockfile --global --project=. --no-self --no-default --dev --group=tox
tox --version
tox run -f py311
tox run -f coverage
rm -rf .tox
find . -name '__pycache__' | xargs rm -rf
- name: Check files in workspace
if: always()
run: ls -lA
14 changes: 7 additions & 7 deletions pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,13 @@ test = [
"pytest-cov~=5.0",
"pytest-asyncio~=0.24.0",
"trove-classifiers>=2023.11.9",
"trustme~=1.0",
# "pytest-retry~=1.6",
# Temporary use VCS to get the modifications added on main (c.f. https://github.com/str0zzapreti/pytest-retry/pull/39)
"pytest-retry @ git+https://github.com/str0zzapreti/pytest-retry.git@bb465fff6f01f3f90a77229468f7e08a3bdbce20",
]
test-ssl = [
"trustme~=1.0",
]
test-trio = [
"pytest-trio~=0.8.0",
]
Expand Down
12 changes: 10 additions & 2 deletions tests/functional_test/test_communication/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@
from contextlib import ExitStack
from functools import partial
from socket import AF_INET, AF_INET6, SOCK_DGRAM, SOCK_STREAM, has_ipv6 as HAS_IPV6, socket as Socket
from typing import Any
from typing import TYPE_CHECKING, Any

from easynetwork.protocol import AnyStreamProtocolType, BufferedStreamProtocol, DatagramProtocol, StreamProtocol

import pytest
import trustme

from .serializer import BadSerializeStringSerializer, NotGoodStringSerializer, StringSerializer

if TYPE_CHECKING:
import trustme


_FAMILY_TO_LOCALHOST: dict[int, str] = {
AF_INET: "127.0.0.1",
AF_INET6: "::1",
Expand Down Expand Up @@ -123,6 +126,11 @@ def socket_pair(localhost_ip: str, tcp_socket_factory: Callable[[], Socket]) ->

@pytest.fixture(scope="session")
def ssl_certificate_authority() -> trustme.CA:
try:
import trustme
except ModuleNotFoundError:
pytest.skip("trustme is not installed")

return trustme.CA()


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ async def test____send_packet____default(self, client: AsyncUDPNetworkClient[str
async with asyncio.timeout(3):
assert await server.recvfrom() == (b"ABCDEF", client.get_local_address())

@PlatformMarkers.runs_only_on_platform("linux", "Windows and MacOS do not raise error")
@PlatformMarkers.runs_only_on_platform("linux", "Windows, MacOS and BSD-like do not raise error")
async def test____send_packet____connection_refused(
self,
client: AsyncUDPNetworkClient[str, str],
Expand All @@ -97,7 +97,7 @@ async def test____send_packet____connection_refused(
with pytest.raises(ConnectionRefusedError):
await client.send_packet("ABCDEF")

@PlatformMarkers.runs_only_on_platform("linux", "Windows and MacOS do not raise error")
@PlatformMarkers.runs_only_on_platform("linux", "Windows, MacOS and BSD-like do not raise error")
async def test____send_packet____connection_refused____after_previous_successful_try(
self,
client: AsyncUDPNetworkClient[str, str],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,7 @@ async def test____serve_forever____accept_client____client_sent_RST_packet_right
await asyncio.sleep(0.1)

# On Linux: ENOTCONN error should not create a big Traceback error
# On BSD: ECONNABORTED error on accept() should not create a big Traceback error
assert len(caplog.records) == 0

async def test____serve_forever____client_extra_attributes(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ def test____send_packet____default(self, client: UDPNetworkClient[str, str], ser
client.send_packet("ABCDEF")
assert server.recvfrom(1024) == (b"ABCDEF", client.get_local_address())

@PlatformMarkers.runs_only_on_platform("linux", "Windows and MacOS do not raise error")
@PlatformMarkers.runs_only_on_platform("linux", "Windows, MacOS and BSD-like do not raise error")
def test____send_packet____connection_refused(self, client: UDPNetworkClient[str, str], server: Socket) -> None:
server.close()
with pytest.raises(ConnectionRefusedError):
client.send_packet("ABCDEF")

@PlatformMarkers.runs_only_on_platform("linux", "Windows and MacOS do not raise error")
@PlatformMarkers.runs_only_on_platform("linux", "Windows, MacOS and BSD-like do not raise error")
def test____send_packet____connection_refused____after_previous_successful_try(
self,
client: UDPNetworkClient[str, str],
Expand Down
5 changes: 5 additions & 0 deletions tests/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,14 @@ def skipif_platform_macOS_because(reason: str, *, skip_only_on_ci: bool = False)
def skipif_platform_linux_because(reason: str, *, skip_only_on_ci: bool = False) -> pytest.MarkDecorator:
return _make_skipif_platform("linux", reason, skip_only_on_ci=skip_only_on_ci)

@staticmethod
def skipif_platform_bsd_because(reason: str, *, skip_only_on_ci: bool = False) -> pytest.MarkDecorator:
return _make_skipif_platform(("freebsd", "openbsd", "netbsd"), reason, skip_only_on_ci=skip_only_on_ci)

skipif_platform_win32 = skipif_platform_win32_because("cannot run on Windows")
skipif_platform_macOS = skipif_platform_macOS_because("cannot run on MacOS")
skipif_platform_linux = skipif_platform_linux_because("cannot run on Linux")
skipif_platform_bsd = skipif_platform_bsd_because("Cannot run on BSD-related platforms (e.g. FreeBSD)")

###### RESTRICT TESTS FOR PLATFORMS ######

Expand Down
15 changes: 11 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,16 @@ commands =
docstrings: pytest --doctest-modules {posargs} {[docs]examples_dir}{/}tutorials{/}ftp_server
docstrings: pytest --doctest-glob="*.rst" {posargs} {[docs]source_dir}

[testenv:{py311,py312,py313}-{unit,functional}-{standard,cbor,msgpack,trio}]
[testenv:{py311,py312,py313}-{unit,functional}-{standard,cbor,msgpack,trio}{,-bsd}]
package = wheel
wheel_build_env = {[base]wheel_build_env}
platform =
!bsd: ((?!bsd).)*
bsd: (free|open|net)bsd.*
groups =
test
; Tests with SSL are deactivated on BSD because cryptography takes 4 minutes to compile :)
functional-standard-!bsd: test-ssl
coverage
cbor: cbor
msgpack: msgpack
Expand All @@ -96,14 +101,15 @@ commands =
msgpack: pytest -m "feature_msgpack" {posargs} {env:TESTS_ROOTDIR}
trio: pytest -n "{env:PYTEST_MAX_WORKERS:auto}" -m "feature_trio" {posargs} {env:TESTS_ROOTDIR}

[testenv:{py311,py312,py313}-functional-{asyncio_proactor,uvloop}]
[testenv:{py311,py312,py313}-functional-{asyncio_proactor,uvloop}{,-bsd}]
package = wheel
wheel_build_env = {[base]wheel_build_env}
platform =
asyncio_proactor: win32
uvloop: linux|darwin
groups =
test
test-ssl
coverage
uvloop: uvloop
setenv =
Expand All @@ -125,8 +131,8 @@ commands =
[testenv:coverage-{unit,functional,full}]
skip_install = true
depends =
unit: {py311,py312,py313}-unit-{standard,cbor,msgpack,trio}
functional: {py311,py312,py313}-functional-{standard,cbor,msgpack,trio,asyncio_proactor,uvloop}
unit: {py311,py312,py313}-unit-{standard,cbor,msgpack,trio}{,-bsd}
functional: {py311,py312,py313}-functional-{standard,cbor,msgpack,trio,asyncio_proactor,uvloop}{,-bsd}
full: coverage-{unit,functional}
parallel_show_output =
full: True
Expand Down Expand Up @@ -181,6 +187,7 @@ platform =
groups =
mypy
test: test
test: test-ssl
full,test,micro_benchmarks: cbor
full,test,micro_benchmarks: msgpack
full,test,micro_benchmarks: types-msgpack
Expand Down

0 comments on commit efe3db7

Please sign in to comment.