Skip to content

Commit

Permalink
[WIP] CI: Add tests on FreeBSD
Browse files Browse the repository at this point in the history
  • Loading branch information
francis-clairicia committed Oct 19, 2024
1 parent 51bc68a commit f9296d4
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 14 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,40 @@ 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')))
runs-on: ubuntu-24.04

name: test (FreeBSD, 3.11)
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Launch tests
# Add 10 minutes timeout because some wheels are long to build
timeout-minutes: 30
uses: vmactions/freebsd-vm@v1
with:
release: '14.1'
# py311-sqlite3 is needed for coverage.py
# rust is needed to install cryptography from source
prepare: |
set -e
pkg install -y curl git python311 py311-sqlite3 rust
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 -vv
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
9 changes: 7 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,8 @@ def socket_pair(localhost_ip: str, tcp_socket_factory: Callable[[], Socket]) ->

@pytest.fixture(scope="session")
def ssl_certificate_authority() -> trustme.CA:
import trustme

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
3 changes: 3 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ package = wheel
wheel_build_env = {[base]wheel_build_env}
groups =
test
functional-standard: test-ssl
coverage
cbor: cbor
msgpack: msgpack
Expand Down Expand Up @@ -104,6 +105,7 @@ platform =
uvloop: linux|darwin
groups =
test
test-ssl
coverage
uvloop: uvloop
setenv =
Expand Down Expand Up @@ -181,6 +183,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 f9296d4

Please sign in to comment.