mirror of https://github.com/fail2ban/fail2ban
ENH(BF?): overload open() (for buffering) within filtertestcase to guarantee atomic writing
This is with the hope to further resolve random tests failures ( primarily on fast travis-ci systems ;) )pull/163/merge
parent
ab044b75ea
commit
bf4d4af1d4
|
@ -22,6 +22,7 @@
|
|||
__copyright__ = "Copyright (c) 2004 Cyril Jaquier; 2012 Yaroslav Halchenko"
|
||||
__license__ = "GPL"
|
||||
|
||||
from __builtin__ import open as fopen
|
||||
import unittest
|
||||
import os
|
||||
import sys
|
||||
|
@ -38,6 +39,20 @@ from server.failmanager import FailManagerEmpty
|
|||
# Useful helpers
|
||||
#
|
||||
|
||||
# yoh: per Steven Hiscocks's insight while troubleshooting
|
||||
# https://github.com/fail2ban/fail2ban/issues/103#issuecomment-15542836
|
||||
# adding a sufficiently large buffer might help to guarantee that
|
||||
# writes happen atomically.
|
||||
def open(*args):
|
||||
"""Overload built in open so we could assure sufficiently large buffer
|
||||
|
||||
Explicit .flush would be needed to assure that changes leave the buffer
|
||||
"""
|
||||
if len(args) == 2:
|
||||
# ~50kB buffer should be sufficient for all tests here.
|
||||
args = args + (50000,)
|
||||
return fopen(*args)
|
||||
|
||||
def _killfile(f, name):
|
||||
try:
|
||||
f.close()
|
||||
|
|
Loading…
Reference in New Issue