Skip to content

Commit

Permalink
Add test to check for failure in case of contention.
Browse files Browse the repository at this point in the history
100% coverage!
  • Loading branch information
musically-ut committed Apr 20, 2015
1 parent 798cfe6 commit 894661d
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions seqfile/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ def test_findNextFile_with_files_non_consecutive_fnamegen():

# Monkey patch _doAtomicFileCreation for testing
_S._oldAtomicCreation = _S._doAtomicFileCreation
def _testAtomicCreationFactory(folder):
def _testAtomicCreationFactory(predicate):

def _testAtomicCreation(filePath):
# Create only the first file in the sequence
if filePath == join(folder, fnameGen(0)):
if predicate(filePath):
# Create the file to simulate concurrent file creation
_os.close( _os.open( filePath, _os.O_CREAT | _os.O_EXCL ) )

Expand All @@ -130,8 +130,18 @@ def _testAtomicCreation(filePath):

def test_findNextFile_concurrent():
with tempDir() as d:
_S._doAtomicFileCreation = _testAtomicCreationFactory(d)
predicate = lambda filePath: filePath == join(d, fnameGen(0))
_S._doAtomicFileCreation = _testAtomicCreationFactory(predicate)
# File created must be the second file in the sequence
assert _S.findNextFile(d, prefix, suffix) == join(d, fnameGen(1))


@raises(OSError)
def test_findNextFile_concurrent_max_attempts_fail():
with tempDir() as d:
# Always create the file, maxattempts will be exhausted
predicate = lambda _filePath: True
_S._doAtomicFileCreation = _testAtomicCreationFactory(predicate)
_S.findNextFile(d, prefix, suffix)


0 comments on commit 894661d

Please sign in to comment.