Tests: waitforfiles() optimization.
This commit is contained in:
29
test/unit.py
29
test/unit.py
@@ -29,8 +29,8 @@ class TestUnit(unittest.TestCase):
|
|||||||
'--log', self.testdir + '/unit.log',
|
'--log', self.testdir + '/unit.log',
|
||||||
'--control', 'unix:' + self.testdir + '/control.unit.sock'])
|
'--control', 'unix:' + self.testdir + '/control.unit.sock'])
|
||||||
|
|
||||||
if not self._waitforfiles([self.testdir + '/unit.pid',
|
if not self._waitforfiles(self.testdir + '/unit.pid',
|
||||||
self.testdir + '/unit.log', self.testdir + '/control.unit.sock']):
|
self.testdir + '/unit.log', self.testdir + '/control.unit.sock'):
|
||||||
exit("Could not start unit")
|
exit("Could not start unit")
|
||||||
|
|
||||||
# TODO dependency check
|
# TODO dependency check
|
||||||
@@ -56,23 +56,24 @@ class TestUnit(unittest.TestCase):
|
|||||||
if '--leave' not in sys.argv:
|
if '--leave' not in sys.argv:
|
||||||
shutil.rmtree(self.testdir)
|
shutil.rmtree(self.testdir)
|
||||||
|
|
||||||
def _waitforfiles(self, files):
|
def _waitforfiles(self, *files):
|
||||||
if isinstance(files, str):
|
for i in range(50):
|
||||||
files = [files]
|
wait = False
|
||||||
|
ret = 0
|
||||||
|
|
||||||
count = 0
|
|
||||||
for i in range(1, 50):
|
|
||||||
for f in files:
|
for f in files:
|
||||||
if os.path.exists(f):
|
if not os.path.exists(f):
|
||||||
count += 1
|
wait = True
|
||||||
|
break
|
||||||
|
|
||||||
if count == len(files):
|
if wait:
|
||||||
return 1
|
|
||||||
|
|
||||||
count = 0
|
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
|
||||||
return 0
|
else:
|
||||||
|
ret = 1
|
||||||
|
break
|
||||||
|
|
||||||
|
return ret
|
||||||
|
|
||||||
class TestUnitControl(TestUnit):
|
class TestUnitControl(TestUnit):
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user