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

0.6.0: test_time_rotation_reopening_native fails #658

Closed
dvzrv opened this issue May 18, 2022 · 2 comments
Closed

0.6.0: test_time_rotation_reopening_native fails #658

dvzrv opened this issue May 18, 2022 · 2 comments
Labels
enhancement Improvement to an already existing feature

Comments

@dvzrv
Copy link

dvzrv commented May 18, 2022

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

    @pytest.mark.parametrize("delay", [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

  • pytest 7.1.2
  • python 3.10.4
@Delgan
Copy link
Owner

Delgan commented May 21, 2022

Hey @dvzrv, 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)

@Delgan Delgan added the enhancement Improvement to an already existing feature label Jun 10, 2022
@Delgan
Copy link
Owner

Delgan commented Jun 10, 2022

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. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvement to an already existing feature
Projects
None yet
Development

No branches or pull requests

2 participants