summaryrefslogtreecommitdiffstats
path: root/tests/APIExerciser.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/APIExerciser.py')
-rw-r--r--tests/APIExerciser.py54
1 files changed, 28 insertions, 26 deletions
diff --git a/tests/APIExerciser.py b/tests/APIExerciser.py
index d17f81ae2..d7300b1a5 100644
--- a/tests/APIExerciser.py
+++ b/tests/APIExerciser.py
@@ -1,6 +1,8 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
+from __future__ import with_statement
+
import string
from threading import Thread
from random import choice, sample, randint
@@ -60,32 +62,32 @@ class APIExerciser(Thread):
self.core.log.info("API Excerciser started %d" % self.id)
- out = open("error.log", "ab")
- # core errors are not logged of course
- out.write("\n" + "Starting\n")
- out.flush()
-
- while True:
- try:
- self.testAPI()
- except Exception:
- self.core.log.error("Excerciser %d throw an execption" % self.id)
- print_exc()
- out.write(format_exc() + 2 * "\n")
- out.flush()
-
- if not self.count % 100:
- self.core.log.info("Exerciser %d tested %d api calls" % (self.id, self.count))
- if not self.count % 1000:
- out.flush()
-
- if not sumCalled % 1000: #: not thread safe
- self.core.log.info("Exercisers tested %d api calls" % sumCalled)
- persec = sumCalled / (time() - self.time)
- self.core.log.info("Approx. %.2f calls per second." % persec)
- self.core.log.info("Approx. %.2f ms per call." % (1000 / persec))
- self.core.log.info("Collected garbage: %d" % gc.collect())
- # sleep(random() / 500)
+ with open("error.log", "ab") as out:
+ # core errors are not logged of course
+ out.write("\n" + "Starting\n")
+ out.flush()
+
+ while True:
+ try:
+ self.testAPI()
+ except Exception:
+ self.core.log.error("Excerciser %d throw an execption" % self.id)
+ print_exc()
+ out.write(format_exc() + 2 * "\n")
+ out.flush()
+
+ if not self.count % 100:
+ self.core.log.info("Exerciser %d tested %d api calls" % (self.id, self.count))
+ if not self.count % 1000:
+ out.flush()
+
+ if not sumCalled % 1000: #: not thread safe
+ self.core.log.info("Exercisers tested %d api calls" % sumCalled)
+ persec = sumCalled / (time() - self.time)
+ self.core.log.info("Approx. %.2f calls per second." % persec)
+ self.core.log.info("Approx. %.2f ms per call." % (1000 / persec))
+ self.core.log.info("Collected garbage: %d" % gc.collect())
+ # sleep(random() / 500)
def testAPI(self):