From bbca721d74cf02983e34cf187d8f032609f7c484 Mon Sep 17 00:00:00 2001 From: Dana Powers Date: Sat, 12 Mar 2016 12:53:47 -0800 Subject: Sync rendered fixture templates to disk to avoid races --- test/fixtures.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'test') diff --git a/test/fixtures.py b/test/fixtures.py index 3c5e694..7da4f52 100644 --- a/test/fixtures.py +++ b/test/fixtures.py @@ -84,6 +84,14 @@ class Fixture(object): template = handle.read() with open(target_file, "w") as handle: handle.write(template.format(**binding)) + handle.flush() + os.fsync(handle) + + # fsync directory for durability + # https://blog.gocept.com/2013/07/15/reliable-file-updates-with-python/ + dirfd = os.open(os.path.dirname(target_file), os.O_DIRECTORY) + os.fsync(dirfd) + os.close(dirfd) class ZookeeperFixture(Fixture): -- cgit v1.2.1