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 hanging tests due to a python bug #478

Merged
merged 4 commits into from
Dec 8, 2023
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
6 changes: 3 additions & 3 deletions flake.lock

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

2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
devShell.x86_64-linux = pkgs.mkShell {
buildInputs = with pkgs; [
poetry
python310
python311
python312
];
shellHook = ''
LD_LIBRARY_PATH=${pkgs.lib.makeLibraryPath [stdenv.cc.cc]}
Expand Down
18 changes: 9 additions & 9 deletions src/gallia/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from __future__ import annotations

import atexit
import datetime
import gzip
import io
import logging
Expand All @@ -17,7 +18,6 @@
import traceback
from collections.abc import Iterator
from dataclasses import dataclass
from datetime import datetime
from enum import Enum, IntEnum, unique
from logging.handlers import QueueHandler, QueueListener
from pathlib import Path
Expand All @@ -32,7 +32,7 @@
from logging import _ExcInfoType


tz = datetime.utcnow().astimezone().tzinfo
tz = datetime.datetime.now(datetime.UTC).tzinfo


@unique
Expand Down Expand Up @@ -380,7 +380,7 @@ def _colorize_msg(data: str, levelno: int) -> tuple[str, int]:


def _format_record( # noqa: PLR0913
dt: datetime,
dt: datetime.datetime,
name: str,
data: str,
levelno: int,
Expand Down Expand Up @@ -427,7 +427,7 @@ class PenlogRecord:
module: str
host: str
data: str
datetime: datetime
datetime: datetime.datetime
# FIXME: Enums are slow.
priority: PenlogPriority
tags: list[str] | None = None
Expand Down Expand Up @@ -475,12 +475,12 @@ def parse_json(cls, data: bytes) -> Self:
match record:
case _PenlogRecordV1():
try:
dt = datetime.fromisoformat(record.timestamp)
dt = datetime.datetime.fromisoformat(record.timestamp)
except ValueError:
# Workaround for broken ISO strings. Go produced broken strings. :)
# We have some old logfiles with this shortcoming.
datestr, _ = record.timestamp.split(".", 2)
dt = datetime.strptime(datestr, "%Y-%m-%dT%H:%M:%S")
dt = datetime.datetime.strptime(datestr, "%Y-%m-%dT%H:%M:%S")

if record.tags is not None:
tags = record.tags
Expand All @@ -505,7 +505,7 @@ def parse_json(cls, data: bytes) -> Self:
module=record.module,
host=record.host,
data=record.data,
datetime=datetime.fromisoformat(record.datetime),
datetime=datetime.datetime.fromisoformat(record.datetime),
priority=PenlogPriority(record.priority),
tags=record.tags,
line=record.line,
Expand Down Expand Up @@ -726,7 +726,7 @@ def format(self, record: logging.LogRecord) -> str:
host=self.hostname,
data=record.getMessage(),
priority=PenlogPriority.from_level(record.levelno).value,
datetime=datetime.fromtimestamp(record.created, tz=tz).isoformat(),
datetime=datetime.datetime.fromtimestamp(record.created, tz=tz).isoformat(),
line=f"{record.pathname}:{record.lineno}",
stacktrace=stacktrace,
tags=tags,
Expand Down Expand Up @@ -760,7 +760,7 @@ def format(
)

return _format_record(
dt=datetime.fromtimestamp(record.created),
dt=datetime.datetime.fromtimestamp(record.created),
name=record.name,
data=record.getMessage(),
levelno=record.levelno,
Expand Down
7 changes: 3 additions & 4 deletions tests/test_transports.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ async def listen(self, target: TargetURI) -> None:
async def accept(self) -> TCPTransport:
return await self.queue.get()

async def close(self) -> None:
def close(self) -> None:
self.server.close()
await self.server.wait_closed()


async def _echo_test(
Expand All @@ -66,7 +65,7 @@ async def tcp_server() -> AsyncIterator[TCPServer]:
tcp_server = TCPServer()
await tcp_server.listen(listen_target)
yield tcp_server
await tcp_server.close()
tcp_server.close()


@pytest.mark.asyncio
Expand Down Expand Up @@ -127,7 +126,7 @@ async def test_tcp_linesep_request(tcp_server: TCPServer) -> None:
@pytest.mark.asyncio
async def test_tcp_timeout(tcp_server: TCPServer) -> None:
client = await TCPLinesTransport.connect(TargetURI("tcp-lines://127.0.0.1:1234"))
_ = await tcp_server.accept()
await tcp_server.accept()

with pytest.raises(asyncio.TimeoutError):
await client.request(b"hello", timeout=0.5)
Loading