Mayil-AI-Sandbox / loguru-Jan2023

MIT License
0 stars 0 forks source link

0.6.0: test_time_rotation_reopening_native fails (hashtag658) #65

Closed vikramsubramanian closed 2 months ago

vikramsubramanian commented 2 months ago

Hi! I'm currently working on packaging 0.6.0 for Arch Linux. In the packaging environment we usually run the test suite of upstream projects to have easy integration testing upon upgrades.

Unfortunately the mentioned test fails and I'm not sure why:

=================================== FAILURES ===================================
__________________ test_time_rotation_reopening_native[False] __________________

tmpdir_local = PosixPath('tmpwuh0s_ls'), delay = False

>   ???
E   AssertionError: assert 1 == 2
E    +  where 1 = len([PosixPath('tmpwuh0s_ls/test.log')])
E    +    where [PosixPath('tmpwuh0s_ls/test.log')] = list(<generator object Path.iterdir at 0x6073b9e53300>)
E    +      where <generator object Path.iterdir at 0x6073b9e53300> = <bound method Path.iterdir of PosixPath('tmpwuh0s_ls')>()
E    +        where <bound method Path.iterdir of PosixPath('tmpwuh0s_ls')> = PosixPath('tmpwuh0s_ls').iterdir

tests/test_filesink_rotation.py:292: AssertionError
__________________ test_time_rotation_reopening_native[True] ___________________

tmpdir_local = PosixPath('tmprccpxuyr'), delay = True

     [False, True])
    def test_time_rotation_reopening_native(tmpdir_local, delay):
        filepath = str(tmpdir_local / "test.log")
        i = logger.add(filepath, format="{message}", delay=delay, rotation="1 s")
        logger.info("1")
        time.sleep(0.75)
        logger.info("2")
        logger.remove(i)
        i = logger.add(filepath, format="{message}", delay=delay, rotation="1 s")
        logger.info("3")

        assert len(list(tmpdir_local.iterdir())) == 1
        assert (tmpdir_local / "test.log").read_text() == "1\n2\n3\n"

        time.sleep(0.5)
        logger.info("4")

>       assert len(list(tmpdir_local.iterdir())) == 2
E       AssertionError: assert 1 == 2
E        +  where 1 = len([PosixPath('tmprccpxuyr/test.log')])
E        +    where [PosixPath('tmprccpxuyr/test.log')] = list(<generator object Path.iterdir at 0x6073b9d40c80>)
E        +      where <generator object Path.iterdir at 0x6073b9d40c80> = <bound method Path.iterdir of PosixPath('tmprccpxuyr')>()
E        +        where <bound method Path.iterdir of PosixPath('tmprccpxuyr')> = PosixPath('tmprccpxuyr').iterdir

tests/test_filesink_rotation.py:292: AssertionError
=========================== short test summary info ============================
FAILED tests/test_filesink_rotation.py::test_time_rotation_reopening_native[False]
FAILED tests/test_filesink_rotation.py::test_time_rotation_reopening_native[True]
================== 2 failed, 1349 passed, 1 skipped in 33.03s ==================

Maybe you have a clue? :)

This is with

vikramsubramanian commented 2 months ago

Hey thanks for the report.

Tests are working fine on my Arch installation.

I'm thinking to either timing issue or missing [xattr]( support for settings the file creation time.

Is the error systematic or sporadic?

Do you have the possibility to replace time.sleep(0.5) with time.sleep(2) and see if it improves things?

Can you run the following and share the output please:

import inspect
import tempfile
import os
from loguru._ctime_functions import set_ctime, get_ctime

print("== set_ctime ==")
print(inspect.getsource(set_ctime))

print("== get_ctime ==")
print(inspect.getsource(get_ctime))

with tempfile.TemporaryDirectory(dir=".") as tmp_dir:
    filepath = os.path.join(tmp_dir, "foo.txt")
    with open(filepath, "w") as file:
        pass

    print("== ctime ==")
    set_ctime(filepath, 123.456)
    res = get_ctime(filepath)
    print(res)

    print("== xattr ==")
    os.setxattr(filepath, b"user.loguru_test", b"test")
    res = os.getxattr(filepath, b"user.loguru_test")
    print(res)
vikramsubramanian commented 2 months ago

I refactored the test a little bit. I increased the sleep times and also added a check to skip the test if the platform does not seem to support getting/setting file creation time.

If you're still experiencing the issue, please re-open this ticket so we can investigate it further. :+1: