retry df test up to 5 times if it fails due to some other program writing/deleting...
authorGerd von Egidy <gerd.von.egidy@intra2net.com>
Thu, 17 Dec 2015 10:19:52 +0000 (11:19 +0100)
committerGerd von Egidy <gerd.von.egidy@intra2net.com>
Thu, 17 Dec 2015 10:19:52 +0000 (11:19 +0100)
test/test_filefunc.cpp

index 3d74a9d..e1d68fd 100644 (file)
@@ -592,12 +592,29 @@ BOOST_AUTO_TEST_CASE(FileContentDiffersEqualSize)
 
 BOOST_AUTO_TEST_CASE(FreeDiskSpace1)
 {
-    string dfstr=capture_exec("df -B 1 --output=avail /tmp | tail -n 1");
+    long long dfout;
+    long long get_free_diskspace_tmp;
 
-    long long dfout=-1;
-    string_to<long long>(dfstr,dfout);
+    // we need a partition to do this test. we can't create our own because that would require root
+    // so we use /tmp and retry it a few times in case of an error
+    int retries = 5;
+    while (retries > 0)
+    {
+        string dfstr=capture_exec("df -B 1 --output=avail /tmp | tail -n 1");
+
+        dfout=-1;
+        string_to<long long>(dfstr,dfout);
+
+        get_free_diskspace_tmp=get_free_diskspace("/tmp");
+        
+        if ( dfout == get_free_diskspace_tmp )
+            break;
+        
+        retries--;
+    }
 
-    BOOST_CHECK_EQUAL( dfout, get_free_diskspace("/tmp") );
+    // do the check again with BOOST_CHECK_EQUAL to show it in the unit test output
+    BOOST_CHECK_EQUAL( dfout, get_free_diskspace_tmp );
 }
 
 BOOST_AUTO_TEST_CASE(FreeDiskSpace2)