diff options
author | Nikolaus Rath <Nikolaus@rath.org> | 2016-10-10 11:18:00 -0700 |
---|---|---|
committer | Nikolaus Rath <Nikolaus@rath.org> | 2016-10-10 11:47:29 -0700 |
commit | 2044df660f193d6eb26e2e5121fb33d2f1dcc145 (patch) | |
tree | e7f32d8a75448f382fdca47e05f738fc4ab70171 /test | |
parent | 71064a41f823d2c857813330e8a3bce876e43553 (diff) |
Fix race condition in notify_* examples
The fix in commit cf4159156b was incomplete. While some false positives
are caused by sleep() in the file system taking longer than expected,
there was also a race condition where the file system would run before
the contents are initialized properly.
Diffstat (limited to 'test')
-rwxr-xr-x | test/test_examples.py | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/test/test_examples.py b/test/test_examples.py index 2990d25..e0f9be4 100755 --- a/test/test_examples.py +++ b/test/test_examples.py @@ -151,21 +151,16 @@ def test_notify1(tmpdir, name, options, notify): mnt_dir = str(tmpdir) cmdline = base_cmdline + \ [ pjoin(basename, 'example', name), - '-f', '--update-interval=2', mnt_dir ] + options + '-f', '--update-interval=1', mnt_dir ] + options if not notify: cmdline.append('--no-notify') mount_process = subprocess.Popen(cmdline) try: wait_for_mount(mount_process, mnt_dir) filename = pjoin(mnt_dir, 'current_time') - # Wait until first update - while True: - with open(filename, 'r') as fh: - read1 = fh.read() - if read1: - break - safe_sleep(2) - safe_sleep(6) + with open(filename, 'r') as fh: + read1 = fh.read() + safe_sleep(2) with open(filename, 'r') as fh: read2 = fh.read() if notify: @@ -183,8 +178,8 @@ def test_notify_inval_entry(tmpdir, notify): mnt_dir = str(tmpdir) cmdline = base_cmdline + \ [ pjoin(basename, 'example', 'notify_inval_entry'), - '-f', '--update-interval=2', - '--timeout=10', mnt_dir ] + '-f', '--update-interval=1', + '--timeout=5', mnt_dir ] if not notify: cmdline.append('--no-notify') mount_process = subprocess.Popen(cmdline) @@ -199,10 +194,10 @@ def test_notify_inval_entry(tmpdir, notify): fname = pjoin(mnt_dir, os.listdir(mnt_dir)[0]) os.stat(fname) - safe_sleep(4) + safe_sleep(2) if not notify: os.stat(fname) - safe_sleep(10) + safe_sleep(5) with pytest.raises(FileNotFoundError): os.stat(fname) except: |