Sync rendered fixture templates to disk to avoid races

This commit is contained in:
Dana Powers
2016-03-12 12:53:47 -08:00
parent 590d75a76a
commit bbca721d74

View File

@@ -84,6 +84,14 @@ class Fixture(object):
template = handle.read() template = handle.read()
with open(target_file, "w") as handle: with open(target_file, "w") as handle:
handle.write(template.format(**binding)) 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): class ZookeeperFixture(Fixture):