aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorGravatar Nikolaus Rath <Nikolaus@rath.org>2017-05-31 09:34:40 -0700
committerGravatar Nikolaus Rath <Nikolaus@rath.org>2017-05-31 09:36:51 -0700
commit5e20b4da8ec861573fdf50205221542604be9bbc (patch)
tree042874ecca4ee7962e5dbe3a56fd576559262e42 /test
parent952492ff432a54f54307a368e0256653060648b5 (diff)
tst_link(): wait for RELEASE request
Since RELEASE requests are asynchronous, it is possible that libfuse still considers the file to be open when userspace has closed it, so that a successive unlink() call from userspace actually triggers a rename(). We avoid the resulting test failure by re-trying a few times. Fixes: #157.
Diffstat (limited to 'test')
-rwxr-xr-xtest/test_examples.py25
1 files changed, 16 insertions, 9 deletions
diff --git a/test/test_examples.py b/test/test_examples.py
index 000859a..953eeec 100755
--- a/test/test_examples.py
+++ b/test/test_examples.py
@@ -12,6 +12,7 @@ import pytest
import stat
import shutil
import filecmp
+import time
import errno
from tempfile import NamedTemporaryFile
from util import (wait_for_mount, umount, cleanup, base_cmdline,
@@ -381,20 +382,26 @@ def tst_link(mnt_dir):
assert fstat1.st_nlink == 2
assert os.path.basename(name2) in os.listdir(mnt_dir)
assert filecmp.cmp(name1, name2, False)
-
+
+ # Since RELEASE requests are asynchronous, it is possible that
+ # libfuse still considers the file to be open at this point
+ # and (since -o hard_remove is not used) renames it instead of
+ # deleting it. In that case, the following lstat() call will
+ # still report an st_nlink value of 2 (cf. issue #157).
os.unlink(name2)
-
+
assert os.path.basename(name2) not in os.listdir(mnt_dir)
with pytest.raises(FileNotFoundError):
os.lstat(name2)
- fstat1 = os.lstat(name1)
- # For debugging issue #157
- #assert fstat1.st_nlink == 1
- if fstat1.st_nlink != 1:
- print('Old stat result:', fstat2, file=sys.stdin)
- print('New stat result:', fstat1, file=sys.stdin)
- assert fstat1.st_nlink == 1
+ # See above, we may have to wait until RELEASE has been
+ # received before the st_nlink value is correct.
+ maxwait = time.time() + 2
+ fstat1 = os.lstat(name1)
+ while fstat1.st_nlink == 2 and time.time() < maxwait:
+ fstat1 = os.lstat(name1)
+ time.sleep(0.1)
+ assert fstat1.st_nlink == 1
os.unlink(name1)