Browse Source

Merge pull request #7738 from ThomasWaldmann/fix-disk-full-test-master

fix test_disk_full, fixes #7617
TW 1 year ago
parent
commit
c0001fb6ea
1 changed files with 40 additions and 36 deletions
  1. 40 36
      src/borg/testsuite/archiver/disk_full.py

+ 40 - 36
src/borg/testsuite/archiver/disk_full.py

@@ -1,14 +1,16 @@
 """
 test_disk_full is very slow and not recommended to be included in daily testing.
-for this test, an empty, writable 16MB filesystem mounted on DF_MOUNT is required.
+for this test, an empty, writable 700MB filesystem mounted on DF_MOUNT is required.
 for speed and other reasons, it is recommended that the underlying block device is
 in RAM, not a magnetic or flash disk.
 
-assuming /tmp is a tmpfs (in memory filesystem), one can use this:
-dd if=/dev/zero of=/tmp/borg-disk bs=16M count=1
-mkfs.ext4 /tmp/borg-disk
+assuming /dev/shm is a tmpfs (in memory filesystem), one can use this:
+
+dd if=/dev/zero of=/dev/shm/borg-disk bs=1M count=700
+mkfs.ext4 /dev/shm/borg-disk
 mkdir /tmp/borg-mount
-sudo mount /tmp/borg-disk /tmp/borg-mount
+sudo mount /dev/shm/borg-disk /tmp/borg-mount
+sudo chown myuser /tmp/borg-mount/
 
 if the directory does not exist, the test will be skipped.
 """
@@ -25,42 +27,41 @@ from . import cmd_fixture
 DF_MOUNT = "/tmp/borg-mount"
 
 
-@pytest.mark.skipif(not os.path.exists(DF_MOUNT), reason="needs a 16MB fs mounted on %s" % DF_MOUNT)
-def test_disk_full(cmd_fixture, monkeypatch):
-    def make_files(dir, count, size, rnd=True):
-        shutil.rmtree(dir, ignore_errors=True)
-        os.mkdir(dir)
-        if rnd:
-            count = random.randint(1, count)
-            if size > 1:
-                size = random.randint(1, size)
-        for i in range(count):
-            fn = os.path.join(dir, "file%03d" % i)
-            with open(fn, "wb") as f:
-                data = os.urandom(size)
-                f.write(data)
+def make_files(dir, count, size, rnd=True):
+    shutil.rmtree(dir, ignore_errors=True)
+    os.mkdir(dir)
+    if rnd:
+        count = random.randint(1, count)
+        if size > 1:
+            size = random.randint(1, size)
+    for i in range(count):
+        fn = os.path.join(dir, "file%03d" % i)
+        with open(fn, "wb") as f:
+            data = os.urandom(size)
+            f.write(data)
+
 
+@pytest.mark.skipif(not os.path.exists(DF_MOUNT), reason="needs a 700MB fs mounted on %s" % DF_MOUNT)
+@pytest.mark.parametrize("test_pass", range(10))
+def test_disk_full(test_pass, cmd_fixture, monkeypatch):
     monkeypatch.setenv("BORG_CHECK_I_KNOW_WHAT_I_AM_DOING", "YES")
-    mount = DF_MOUNT
-    assert os.path.exists(mount)
-    repo = os.path.join(mount, "repo")
-    input = os.path.join(mount, "input")
-    reserve = os.path.join(mount, "reserve")
-    for j in range(100):
-        shutil.rmtree(repo, ignore_errors=True)
-        shutil.rmtree(input, ignore_errors=True)
-        # keep some space and some inodes in reserve that we can free up later:
-        make_files(reserve, 80, 100000, rnd=False)
-        rc, out = cmd_fixture(f"--repo={repo}", "rcreate")
-        if rc != EXIT_SUCCESS:
-            print("rcreate", rc, out)
-        assert rc == EXIT_SUCCESS
+    monkeypatch.setenv("BORG_DELETE_I_KNOW_WHAT_I_AM_DOING", "YES")
+    repo = os.path.join(DF_MOUNT, "repo")
+    input = os.path.join(DF_MOUNT, "input")
+    shutil.rmtree(repo, ignore_errors=True)
+    shutil.rmtree(input, ignore_errors=True)
+    rc, out = cmd_fixture(f"--repo={repo}", "rcreate", "--encryption=none")
+    if rc != EXIT_SUCCESS:
+        print("rcreate", rc, out)
+    assert rc == EXIT_SUCCESS
+    try:
         try:
             success, i = True, 0
             while success:
                 i += 1
                 try:
-                    make_files(input, 20, 200000)
+                    # have some randomness here to produce different out of space conditions:
+                    make_files(input, 40, 1000000, rnd=True)
                 except OSError as err:
                     if err.errno == errno.ENOSPC:
                         # already out of space
@@ -74,11 +75,11 @@ def test_disk_full(cmd_fixture, monkeypatch):
                 finally:
                     # make sure repo is not locked
                     shutil.rmtree(os.path.join(repo, "lock.exclusive"), ignore_errors=True)
-                    os.remove(os.path.join(repo, "lock.roster"))
+                    shutil.rmtree(os.path.join(repo, "lock.roster"), ignore_errors=True)
         finally:
             # now some error happened, likely we are out of disk space.
             # free some space such that we can expect borg to be able to work normally:
-            shutil.rmtree(reserve, ignore_errors=True)
+            shutil.rmtree(input, ignore_errors=True)
         rc, out = cmd_fixture(f"--repo={repo}", "rlist")
         if rc != EXIT_SUCCESS:
             print("rlist", rc, out)
@@ -86,3 +87,6 @@ def test_disk_full(cmd_fixture, monkeypatch):
         if rc != EXIT_SUCCESS:
             print("check", rc, out)
         assert rc == EXIT_SUCCESS
+    finally:
+        # try to free the space allocated for the repo
+        cmd_fixture(f"--repo={repo}", "rdelete")