diff options
author | Andrey Zelenkov <zelenkov@nginx.com> | 2017-12-06 15:33:45 +0300 |
---|---|---|
committer | Andrey Zelenkov <zelenkov@nginx.com> | 2017-12-06 15:33:45 +0300 |
commit | 487253754c956d7d7bdb1745d8087cb07b1ece27 (patch) | |
tree | 03593193c056d6c517af0ce10b9e16853c32dfcf | |
parent | 782fa1118d4db0a938e9960cc5c5464b2242d5da (diff) | |
download | unit-487253754c956d7d7bdb1745d8087cb07b1ece27.tar.gz unit-487253754c956d7d7bdb1745d8087cb07b1ece27.tar.bz2 |
Tests: waitforfiles() optimization.
-rw-r--r-- | test/unit.py | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/test/unit.py b/test/unit.py index a06f5479..1383b035 100644 --- a/test/unit.py +++ b/test/unit.py @@ -29,8 +29,8 @@ class TestUnit(unittest.TestCase): '--log', self.testdir + '/unit.log',
'--control', 'unix:' + self.testdir + '/control.unit.sock'])
- if not self._waitforfiles([self.testdir + '/unit.pid',
- self.testdir + '/unit.log', self.testdir + '/control.unit.sock']):
+ if not self._waitforfiles(self.testdir + '/unit.pid',
+ self.testdir + '/unit.log', self.testdir + '/control.unit.sock'):
exit("Could not start unit")
# TODO dependency check
@@ -56,23 +56,24 @@ class TestUnit(unittest.TestCase): if '--leave' not in sys.argv:
shutil.rmtree(self.testdir)
- def _waitforfiles(self, files):
- if isinstance(files, str):
- files = [files]
+ def _waitforfiles(self, *files):
+ for i in range(50):
+ wait = False
+ ret = 0
- count = 0
- for i in range(1, 50):
for f in files:
- if os.path.exists(f):
- count += 1
+ if not os.path.exists(f):
+ wait = True
+ break
- if count == len(files):
- return 1
+ if wait:
+ time.sleep(0.1)
- count = 0
- time.sleep(0.1)
+ else:
+ ret = 1
+ break
- return 0
+ return ret
class TestUnitControl(TestUnit):
|