Skip to content

Fix test atime and ctime instabilities #34

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

Closed
wants to merge 2 commits into from

Conversation

maxnikulin
Copy link
Contributor

Some tests failed from time to time due to st_atime or st_ctime stat attributes. I do not see any reason to check them during of comparison of files since they depend on precise timings of file system operations.

Maybe there is a better way to fix the tests.

while python3 -m unittest -v test.test_scrapbook_cache.TestStaticSiteGenerator.test_update01 ; do : ; done

...

======================================================================
FAIL: test_update01 (test.test_scrapbook_cache.TestStaticSiteGenerator) (path='search.html')
Create nonexisting files
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/ubuntu/danny0838/PyWebScrapBook/test/test_scrapbook_cache.py", line 2983, in test_update01
    self.assertEqual(os.stat(file), orig_stats[file])
AssertionError: os.st[106 chars] st_atime=1608267118, st_mtime=1608267117, st_ctime=1608267117) != os.st[106 chars] st_atime=1608267117, st_mtime=1608267117, st_ctime=1608267117)

----------------------------------------------------------------------
FAIL: test_file (test.test_app_actions.TestMove)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/ubuntu/danny0838/PyWebScrapBook/test/test_app_actions.py", line 3825, in test_file
    is_move=True,
  File "/home/ubuntu/danny0838/PyWebScrapBook/test/test_app_actions.py", line 110, in assert_file_equal
    self.assertEqual(datas[0]['stat'], datas[i]['stat'])
AssertionError: os.st[103 chars] st_atime=1608270835, st_mtime=1608270835, st_ctime=1608270835) != os.st[103 chars] st_atime=1608270835, st_mtime=1608270835, st_ctime=1608270836)

----------------------------------------------------------------------

`test.test_app_actions.TestMove.test_file` sometimes failed
due to st_ctime and st_mtime attributes are affected by tests.
`test.test_scrapbook_cache.TestStaticSiteGenerator.test_update01`
sometimes failed on linux. Likely checking file existence
updates `st_atime` attribute.
@danny0838
Copy link
Owner

I cannot reproduce this issue on Linux Ubuntu. What is the OS you are using?

@maxnikulin
Copy link
Contributor Author

It is not a frequent issue. After I noticed it accidentally, I have to run tests in a loop and to wait for some time but usually less than a minute.

git log -1
commit 50affcef66204dd277936863babdb127994576e5 (HEAD -> devel, origin/devel)
Author: Max Nikulin <manikulin а gmail.com>
Date:   Thu Dec 17 12:07:39 2020 +0700

    Convert id to local time in wsb2sb test (#32)
    
    Allow `test_scrapbook_convert_wsb2sb.TestRun.test_meta_icon05`
    to pass in arbitrary timezone.

lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.1 LTS
Release:        20.04
Codename:       focal

python3 -m venv ~/venv/wsb-34
~/venv/wsb-34/bin/python3 --version
Python 3.8.5

~/venv/wsb-34/bin/python3 -m pip install --editable .

time while ~/venv/wsb-34/bin/python3 -m unittest test.test_scrapbook_cache.TestStaticSiteGenerator ; do : ; done

# ~20 successful iterations

................................
----------------------------------------------------------------------
Ran 32 tests in 1.475s                                                
                      
OK
...............................
======================================================================
FAIL: test_update01 (test.test_scrapbook_cache.TestStaticSiteGenerator) (path='icon/toggle.png')
Create nonexisting files
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/ubuntu/danny0838/PyWebScrapBook/test/test_scrapbook_cache.py", line 2983, in test_update01
    self.assertEqual(os.stat(file), orig_stats[file])                 
AssertionError: os.st[104 chars] st_atime=1608527531, st_mtime=1608527530, st_ctime=1608527530) != os.st[104 chars] st_atime=1608527530, st_mtime=1608527530, st_ctime=1608527530)

----------------------------------------------------------------------
Ran 32 tests in 1.481s          
                                                                      
FAILED (failures=1)   

real    0m41.442s
user    0m39.584s               
sys     0m1.848s                                                      

I have seen the issue with Ubuntu-18.04 and python-3.6 as well. In both cases I use LXC containers running on Ubuntu-18.04 host. File system: ext4 with relatime,user_xattr,acl options, kernel 5.4.0-58 x86_64

@danny0838
Copy link
Owner

@maxnikulin This is an old issue. Can you help confirm whether the issue persists in the latest version?

@maxnikulin
Copy link
Contributor Author

@maxnikulin This is an old issue. Can you help confirm whether the issue persists in the latest version?

I do not run tests regularly last time. I have not tried hard and the environment is a bit specific, but I do not see failures any more. Since the code has changed and conflicts have arisen, it would be better to create new issues if st_atime fails will appear again.

I think, you have addressed the issue while fixing #53, see cd2c704#diff-6b0a0a722560defbce2f85c299f9e1bc53b31f304fb78a1fbf5f32d9f06f73c6L3044, and in the course of some refactoring a91fb11#diff-f2a49b1a8d351fe0c6456427c8f8cd831372aa6413030a5b355ba272da8f5cd0L128

P.S. I have got a couple of other failures. I will look closer at them if you ask.

Just for the case that you may guess the reason and may fix it promptly: tests.test_scrapbook_indexer.TestUnSingleHtmlConverter.test_rewrite_svg and tests.test_scrapbook_indexer.TestUnSingleHtmlConverter.test_rewrite_svg_file

-   <script href="313d6864fa48b411d082f7692efd0c0892788fc4.es"></script>
?                                                          ^
+   <script href="313d6864fa48b411d082f7692efd0c0892788fc4.js"></script>
?                                                          ^

I have not filed a dedicated issue since I suspect that it may be caused by my test environment.

@maxnikulin maxnikulin closed this Jan 23, 2024
@maxnikulin maxnikulin deleted the fix-test-atime-ctime branch January 23, 2024 04:55
@danny0838
Copy link
Owner

Just for the case that you may guess the reason and may fix it promptly: tests.test_scrapbook_indexer.TestUnSingleHtmlConverter.test_rewrite_svg and tests.test_scrapbook_indexer.TestUnSingleHtmlConverter.test_rewrite_svg_file

-   <script href="313d6864fa48b411d082f7692efd0c0892788fc4.es"></script>
?                                                          ^
+   <script href="313d6864fa48b411d082f7692efd0c0892788fc4.js"></script>
?                                                          ^

I have not filed a dedicated issue since I suspect that it may be caused by my test environment.

It seems like your system has something wrong about mimetypes definitions. Do you have custom mimetypes? If not, it may be an issue as the tests are mostly designed to work on any devices.

@maxnikulin
Copy link
Contributor Author

It seems like your system has something wrong about mimetypes definitions. Do you have custom mimetypes? If not, it may be an issue as the tests are mostly designed to work on any devices.

Thank you for the hint. I have filed #75.

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

Successfully merging this pull request may close these issues.

2 participants