Opened 5 years ago

Closed 5 years ago

#30366 closed Bug (fixed)

The StatReloaderTests will fail on Mac OSX when HFS+ is used as a filesystem

Reported by: Martijn Jacobs Owned by: Martijn Jacobs
Component: Testing framework Version: dev
Severity: Normal Keywords: HFS+ OSX Testing
Cc: Martijn Jacobs Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

HFS+ is the default filesystem for Mac OSX Sierra (10.12.x) and below before it was replaced with APFS in High Sierra (10.13.x) and above.

HFS+ has the unfortunate disadvantage of having a timestamp resolution of 1 second.

In the StatReloaderTests class the reloader sleep time is set to 0.01 seconds to speed up the tests:

class StatReloaderTests(ReloaderTests, IntegrationTests):
    RELOADER_CLS = autoreload.StatReloader

    def setUp(self):
        super().setUp()
        # Shorten the sleep time to speed up tests.
        self.reloader.SLEEP_TIME = 0.01

This will result that these tests will fail when using HFS+ as a filesystem because it won't detect that files have been created or changed:

======================================================================
FAIL: test_glob_non_existing_directory (utils_tests.test_autoreload.StatReloaderTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/martijn/.pyenv/versions/3.7.2/lib/python3.7/unittest/case.py", line 59, in testPartExecutor
    yield
  File "/Users/martijn/.pyenv/versions/3.7.2/lib/python3.7/unittest/case.py", line 615, in run
    testMethod()
  File "/Users/martijn/.pyenv/versions/3.7.2/lib/python3.7/unittest/mock.py", line 1195, in patched
    return func(*args, **keywargs)
  File "/Users/martijn/Dev/oss/django/tests/utils_tests/test_autoreload.py", line 418, in test_glob_non_existing_directory
    self.assertEqual(notify_mock.call_count, 1)
  File "/Users/martijn/.pyenv/versions/3.7.2/lib/python3.7/unittest/case.py", line 839, in assertEqual
    assertion_func(first, second, msg=msg)
  File "/Users/martijn/.pyenv/versions/3.7.2/lib/python3.7/unittest/case.py", line 832, in _baseAssertEqual
    raise self.failureException(msg)
AssertionError: 0 != 1

======================================================================
FAIL: test_nonexistent_file (utils_tests.test_autoreload.StatReloaderTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/martijn/.pyenv/versions/3.7.2/lib/python3.7/unittest/case.py", line 59, in testPartExecutor
    yield
  File "/Users/martijn/.pyenv/versions/3.7.2/lib/python3.7/unittest/case.py", line 615, in run
    testMethod()
  File "/Users/martijn/.pyenv/versions/3.7.2/lib/python3.7/unittest/mock.py", line 1195, in patched
    return func(*args, **keywargs)
  File "/Users/martijn/Dev/oss/django/tests/utils_tests/test_autoreload.py", line 384, in test_nonexistent_file
    self.assertEqual(notify_mock.call_count, 1)
  File "/Users/martijn/.pyenv/versions/3.7.2/lib/python3.7/unittest/case.py", line 839, in assertEqual
    assertion_func(first, second, msg=msg)
  File "/Users/martijn/.pyenv/versions/3.7.2/lib/python3.7/unittest/case.py", line 832, in _baseAssertEqual
    raise self.failureException(msg)
AssertionError: 0 != 1

======================================================================
FAIL: test_nonexistent_file_in_non_existing_directory (utils_tests.test_autoreload.StatReloaderTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/martijn/.pyenv/versions/3.7.2/lib/python3.7/unittest/case.py", line 59, in testPartExecutor
    yield
  File "/Users/martijn/.pyenv/versions/3.7.2/lib/python3.7/unittest/case.py", line 615, in run
    testMethod()
  File "/Users/martijn/.pyenv/versions/3.7.2/lib/python3.7/unittest/mock.py", line 1195, in patched
    return func(*args, **keywargs)
  File "/Users/martijn/Dev/oss/django/tests/utils_tests/test_autoreload.py", line 395, in test_nonexistent_file_in_non_existing_directory
    self.assertEqual(notify_mock.call_count, 1)
  File "/Users/martijn/.pyenv/versions/3.7.2/lib/python3.7/unittest/case.py", line 839, in assertEqual
    assertion_func(first, second, msg=msg)
  File "/Users/martijn/.pyenv/versions/3.7.2/lib/python3.7/unittest/case.py", line 832, in _baseAssertEqual
    raise self.failureException(msg)
AssertionError: 0 != 1

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

How to reproduce:

./runtests.py utils_tests.test_autoreload

on a Mac OSX computer which (still) uses HFS+

Change History (4)

comment:1 by Martijn Jacobs, 5 years ago

Cc: Martijn Jacobs added
Owner: changed from nobody to Martijn Jacobs

comment:2 by Martijn Jacobs, 5 years ago

Has patch: set

A possible solution can be found in the pull request here: https://github.com/django/django/pull/11228

comment:3 by Carlton Gibson, 5 years ago

Triage Stage: UnreviewedReady for checkin
Type: UncategorizedBug

After discussion on the PR, we'll got for skipping the few tests on earlier versions of macOS. Ready to go I think.

comment:4 by Carlton Gibson <carlton.gibson@…>, 5 years ago

Resolution: fixed
Status: assignedclosed

In 9141da1a:

Fixed #30366 -- Skipped StatReloaderTests on HFS+ filesystems.

When on MacOS High Sierra or below (<=10.13) it could be that a HFS+
filesystem is used. HFS+ has a time resolution of only one second
which can be too low for some of the tests.

Note: See TracTickets for help on using tickets.
Back to Top