8 from loadtest.RunEte import RunEte
9 from loadtest.TestConfig import TestConfig
12 class TestController(object):
19 soaksubfolder = 'soak_' + str(os.getpid())
22 def __init__(self, options):
26 self.config = TestConfig(duration=options.duration)
27 logging.info(self.config.to_string())
30 starttime = time.time()
31 endtime = starttime + self.config.duration
33 currenttime = time.time()
34 logging.info("{}:{}:{}".format(starttime, endtime, currenttime))
35 while currenttime < endtime:
36 if (profileindex >= len(self.config.profile)):
38 profile = self.config.profile[profileindex]
39 sleeptime = profile[0]
40 currenttime = time.time()
41 if ((currenttime + sleeptime) < endtime):
43 self.schedule(profile)
44 profileindex = profileindex + 1
45 currenttime = time.time()
49 for threadname in self.threads:
50 logging.info("TestController waiting on " + threadname)
51 t = self.threads[threadname]
53 logging.info("Soak test completed")
55 def schedule(self, profile):
56 self.remove_completed_threads()
59 self.schedule_one(test)
61 def schedule_one(self, test):
62 self.test_number = self.test_number + 1
63 self.threadid = self.threadid + 1
64 threadname = "RunEte_" + str(self.threadid)
65 ''' test for max threads '''
66 t = RunEte(test, self.soaksubfolder, str(self.test_number))
69 self.threads[threadname] = t
72 def remove_completed_threads(self):
74 for threadname in self.threads:
75 t = self.threads[threadname]
76 if (t.isAlive() == False):
77 toremove.append(threadname)
78 for threadname in toremove:
79 logging.info("Removing " + threadname)
80 del(self.threads[threadname])