MCPcopy Index your code
hub / github.com/pyload/pyload / APIExerciser

Class APIExerciser

module/common/APIExerciser.py:36–157  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34 APIExerciser(core).start()
35
36class APIExerciser(Thread):
37
38
39 def __init__(self, core, thrift=False, user=None, pw=None):
40 global idPool
41
42 Thread.__init__(self)
43 self.setDaemon(True)
44 self.core = core
45 self.count = 0 #number of methods
46 self.time = time()
47
48 if thrift:
49 self.api = ThriftClient(user=user, password=pw)
50 else:
51 self.api = core.api
52
53
54 self.id = idPool
55
56 idPool += 1
57
58 #self.start()
59
60 def run(self):
61
62 self.core.log.info("API Excerciser started %d" % self.id)
63
64 out = open("error.log", "ab")
65 #core errors are not logged of course
66 out.write("\n" + "Starting\n")
67 out.flush()
68
69 while True:
70 try:
71 self.testAPI()
72 except Exception:
73 self.core.log.error("Excerciser %d throw an execption" % self.id)
74 print_exc()
75 out.write(format_exc() + 2 * "\n")
76 out.flush()
77
78 if not self.count % 100:
79 self.core.log.info("Exerciser %d tested %d api calls" % (self.id, self.count))
80 if not self.count % 1000:
81 out.flush()
82
83 if not sumCalled % 1000: #not thread safe
84 self.core.log.info("Exercisers tested %d api calls" % sumCalled)
85 persec = sumCalled / (time() - self.time)
86 self.core.log.info("Approx. %.2f calls per second." % persec)
87 self.core.log.info("Approx. %.2f ms per call." % (1000 / persec))
88 self.core.log.info("Collected garbage: %d" % gc.collect())
89
90
91 #sleep(random() / 500)
92
93 def testAPI(self):

Callers 1

startApiExerciserFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected