diff options
author | Tomasz Miąsko <tomasz.miasko@gmail.com> | 2018-11-13 00:00:00 +0000 |
---|---|---|
committer | Tomasz Miąsko <tomasz.miasko@gmail.com> | 2018-11-13 16:21:43 +0100 |
commit | 51c1e419c38d1d2078b3bdbd552ad7643c58aaa5 (patch) | |
tree | e70c310dcebf8e19b4ff1fc0ec8ed1e9c8e4121f | |
parent | e581e846fa518ffa2be5dda5b1fc8180114a1976 (diff) | |
download | dconf-51c1e419c38d1d2078b3bdbd552ad7643c58aaa5.tar.gz |
tests: Add test that redundant disk writes are avoided
-rwxr-xr-x | tests/test-dconf.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/test-dconf.py b/tests/test-dconf.py index e520e5b..cc31ef2 100755 --- a/tests/test-dconf.py +++ b/tests/test-dconf.py @@ -409,6 +409,48 @@ class DBusTest(unittest.TestCase): # Lexicographically last value should win: self.assertEqual(dconf_read('/org/file'), '99') + @unittest.expectedFailure + def test_redundant_disk_writes(self): + """Redundant disk writes are avoided. + + When write or reset operations don't modify actual contents of the + database, the database file shouldn't be needlessly rewritten. Check + mtime after each redundant operation to verify that. + """ + + config = os.path.join(self.config_home, 'dconf', 'user') + + def move_time_back(path): + """Moves file mtime 60 seconds back and returns its new value. + + Used to avoid false positives during comparison checks in the case + that mtime is stored with low precision. + """ + atime = os.path.getatime(config) + mtime = os.path.getmtime(config) + + os.utime(config, times=(atime, mtime - 60)) + + return os.path.getmtime(config) + + # Activate service to trigger initial database write. + dconf_write('/prime', '5') + + # Sanity check that database is rewritten when necessary. + saved_mtime = move_time_back(config) + dconf_write('/prime', '13') + self.assertLess(saved_mtime, os.path.getmtime(config)) + + # Write the same value as one already in the database. + saved_mtime = move_time_back(config) + dconf('write', '/prime', '13') + self.assertEqual(saved_mtime, os.path.getmtime(config)) + + # Reset not directory which is not present in the database. + saved_mtime = move_time_back(config) + dconf('reset', '-f', '/non-existing/directory/') + self.assertEqual(saved_mtime, os.path.getmtime(config)) + if __name__ == '__main__': # Make sure we don't pick up mandatory profile. |