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

Add tests for Sable's postgresql chathistory backend #292

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion .github/workflows/test-devel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,7 @@ jobs:
cache-on-failure: true
workspaces: sable -> target
- run: rustc --version
- run: sudo systemctl start postgresql.service
- name: Build Sable
run: |
cd $GITHUB_WORKSPACE/sable/
Expand All @@ -1003,7 +1004,8 @@ jobs:
- env:
IRCTEST_DEBUG_LOGS: ${{ runner.debug }}
name: Test with pytest
run: PYTEST_ARGS='--junit-xml pytest.xml --timeout 300' PATH=$HOME/.local/bin:$PATH PATH=$GITHUB_WORKSPACE/sable/target/debug/sbin:$GITHUB_WORKSPACE/sable/target/debug/bin:$GITHUB_WORKSPACE/sable/target/debug:$PATH
run: PYTEST_ARGS='--junit-xml pytest.xml --timeout 300' PATH=$HOME/.local/bin:$PATH
IRCTEST_POSTGRESQL_URL=postgresql:// PATH=$GITHUB_WORKSPACE/sable/target/debug/sbin:$GITHUB_WORKSPACE/sable/target/debug/bin:$GITHUB_WORKSPACE/sable/target/debug:$PATH
make sable
timeout-minutes: 30
- if: always()
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/test-stable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1140,7 +1140,7 @@ jobs:
uses: actions/checkout@v4
with:
path: sable
ref: 52397dc9e0f27c3ed197f984c00f06639870716d
ref: aee63093bb6ee250b24aabb843b863ab0a327e7a
repository: Libera-Chat/sable
- name: Install rust toolchain
uses: actions-rs/toolchain@v1
Expand All @@ -1154,6 +1154,7 @@ jobs:
cache-on-failure: true
workspaces: sable -> target
- run: rustc --version
- run: sudo systemctl start postgresql.service
- name: Build Sable
run: |
cd $GITHUB_WORKSPACE/sable/
Expand All @@ -1167,7 +1168,8 @@ jobs:
- env:
IRCTEST_DEBUG_LOGS: ${{ runner.debug }}
name: Test with pytest
run: PYTEST_ARGS='--junit-xml pytest.xml --timeout 300' PATH=$HOME/.local/bin:$PATH PATH=$GITHUB_WORKSPACE/sable/target/debug/sbin:$GITHUB_WORKSPACE/sable/target/debug/bin:$GITHUB_WORKSPACE/sable/target/debug:$PATH
run: PYTEST_ARGS='--junit-xml pytest.xml --timeout 300' PATH=$HOME/.local/bin:$PATH
IRCTEST_POSTGRESQL_URL=postgresql:// PATH=$GITHUB_WORKSPACE/sable/target/debug/sbin:$GITHUB_WORKSPACE/sable/target/debug/bin:$GITHUB_WORKSPACE/sable/target/debug:$PATH
make sable
timeout-minutes: 30
- if: always()
Expand Down
29 changes: 15 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,71 +8,72 @@ PYTEST_ARGS ?=
EXTRA_SELECTORS ?=

BAHAMUT_SELECTORS := \
not Ergo \
not implementation-specific \
and not deprecated \
and not strict \
and not IRCv3 \
$(EXTRA_SELECTORS)

CHARYBDIS_SELECTORS := \
not Ergo \
not implementation-specific \
and not deprecated \
and not strict \
$(EXTRA_SELECTORS)

ERGO_SELECTORS := \
(Ergo or not implementation-specific) \
not deprecated \
$(EXTRA_SELECTORS)

HYBRID_SELECTORS := \
not Ergo \
not implementation-specific \
and not deprecated \
$(EXTRA_SELECTORS)

INSPIRCD_SELECTORS := \
not Ergo \
not implementation-specific \
and not deprecated \
and not strict \
$(EXTRA_SELECTORS)

IRCU2_SELECTORS := \
not Ergo \
not implementation-specific \
and not deprecated \
and not strict \
$(EXTRA_SELECTORS)

NEFARIOUS_SELECTORS := \
not Ergo \
not implementation-specific \
and not deprecated \
and not strict \
$(EXTRA_SELECTORS)

SNIRCD_SELECTORS := \
not Ergo \
not implementation-specific \
and not deprecated \
and not strict \
$(EXTRA_SELECTORS)

IRC2_SELECTORS := \
not Ergo \
not implementation-specific \
and not deprecated \
and not strict \
$(EXTRA_SELECTORS)

MAMMON_SELECTORS := \
not Ergo \
not implementation-specific \
and not deprecated \
and not strict \
$(EXTRA_SELECTORS)

NGIRCD_SELECTORS := \
not Ergo \
not implementation-specific \
and not deprecated \
and not strict \
$(EXTRA_SELECTORS)

PLEXUS4_SELECTORS := \
not Ergo \
not implementation-specific \
and not deprecated \
$(EXTRA_SELECTORS)

Expand All @@ -85,7 +86,7 @@ LIMNORIA_SELECTORS := \

# Tests marked with arbitrary_client_tags or react_tag can't pass because Sable does not support client tags yet
SABLE_SELECTORS := \
not Ergo \
(Sable or not implementation-specific) \
and not deprecated \
and not strict \
and not arbitrary_client_tags \
Expand All @@ -94,7 +95,7 @@ SABLE_SELECTORS := \
$(EXTRA_SELECTORS)

SOLANUM_SELECTORS := \
not Ergo \
not implementation-specific \
and not deprecated \
and not strict \
$(EXTRA_SELECTORS)
Expand All @@ -116,7 +117,7 @@ THELOUNGE_SELECTORS := \
# Tests marked with private_chathistory can't pass because Unreal does not implement CHATHISTORY for DMs

UNREALIRCD_SELECTORS := \
not Ergo \
not implementation-specific \
and not deprecated \
and not strict \
and not arbitrary_client_tags \
Expand Down
47 changes: 45 additions & 2 deletions irctest/basecontrollers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
import shutil
import socket
import subprocess
import sys
import tempfile
import textwrap
import threading
import time
from typing import (
IO,
Expand Down Expand Up @@ -67,6 +69,9 @@ class TestCaseControllerConfig:
This should be used as little as possible, using the other attributes instead;
as they are work with any controller."""

sable_history_server: bool = False
"""Whether to start Sable's long-term history server"""


class _BaseController:
"""Base class for software controllers.
Expand Down Expand Up @@ -145,10 +150,48 @@ def kill(self) -> None:
self._own_ports.remove((hostname, port))

def execute(
self, command: Sequence[Union[str, Path]], **kwargs: Any
self,
command: Sequence[Union[str, Path]],
proc_name: Optional[str] = None,
**kwargs: Any,
) -> subprocess.Popen:
output_to = None if self.debug_mode else subprocess.DEVNULL
return subprocess.Popen(command, stderr=output_to, stdout=output_to, **kwargs)
proc_name = proc_name or str(command[0])
kwargs.setdefault("stdout", output_to)
kwargs.setdefault("stderr", output_to)
stream_stdout = stream_stderr = None
if kwargs["stdout"] in (None, subprocess.STDOUT):
kwargs["stdout"] = subprocess.PIPE

def stream_stdout() -> None:
assert proc.stdout is not None # for mypy
for line in proc.stdout:
prefix = f"{time.time():.3f} {proc_name} ".encode()
try:
sys.stdout.buffer.write(prefix + line)
except ValueError:
# "I/O operation on closed file"
pass

if kwargs["stderr"] in (subprocess.STDOUT, None):
kwargs["stdout"] = subprocess.PIPE

def stream_stderr() -> None:
assert proc.stderr is not None # for mypy
for line in proc.stderr:
prefix = f"{time.time():.3f} {proc_name} ".encode()
try:
sys.stdout.buffer.write(prefix + line)
except ValueError:
# "I/O operation on closed file"
pass

proc = subprocess.Popen(command, **kwargs)
if stream_stdout is not None:
threading.Thread(target=stream_stdout, name="stream_stdout").start()
if stream_stderr is not None:
threading.Thread(target=stream_stderr, name="stream_stderr").start()
return proc


class DirectoryBasedController(_BaseController):
Expand Down
10 changes: 8 additions & 2 deletions irctest/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -842,16 +842,22 @@ def mark_services(cls: TClass) -> TClass:
def mark_specifications(
*specifications_str: str, deprecated: bool = False, strict: bool = False
) -> Callable[[TCallable], TCallable]:
specifications = frozenset(
specifications = {
Specifications.from_name(s) if isinstance(s, str) else s
for s in specifications_str
)
}
if None in specifications:
raise ValueError("Invalid set of specifications: {}".format(specifications))

is_implementation_specific = all(
spec.is_implementation_specific() for spec in specifications
)

def decorator(f: TCallable) -> TCallable:
for specification in specifications:
f = getattr(pytest.mark, specification.value)(f)
if is_implementation_specific:
f = getattr(pytest.mark, "implementation-specific")(f)
if strict:
f = pytest.mark.strict(f)
if deprecated:
Expand Down
Loading
Loading