def test_http_status_handler(self): ProcInfo("proc_0", "group_0", 1, 20, "RUNNING", time.time()) ProcInfo("proc_1", "group_1", 2, 0, "STOPPED", time.time()) # Update ProcInfo 3 times. num_updates = 3 for i in range(num_updates): ProcInfo.updateall() headers = {"authorization": self.token_0.token} response = self.fetch("/status/", method="GET", headers=headers) response_data = json.loads(response.body) self.assertEqual(response.code, 200) self.assertTrue("processes" in response_data) self.assertEqual(len(response_data["processes"][0]["cpu"]), num_updates, "cpu length is %s" % num_updates) self.assertEqual(len(response_data["processes"][0]["mem"]), num_updates, "mem length is %s" % num_updates)
def test_cpu_and_mem_filter(self): before_count_cpu = len(self.proc_0.cpu) before_count_mem = len(self.proc_0.mem) self.assertEqual(before_count_cpu, before_count_mem, "before_count_cpu == before_count_mem") timestamp = time() ProcInfo.updateall() ProcInfo.updateall() ProcInfo.updateall() self.assertEqual(len(self.proc_0.get_cpu(timestamp)), 3, "filtered cpu length == 3") self.assertEqual(len(self.proc_0.get_mem(timestamp)), 3, "filtered cpu length == 3")
def test_updateall(self): before_count_proc_0 = len(self.proc_0.cpu) before_count_proc_1 = len(self.proc_1.cpu) ProcInfo.updateall() ProcInfo.updateall() ProcInfo.updateall() after_count_proc_0 = len(self.proc_0.cpu) after_count_proc_1 = len(self.proc_1.cpu) self.assertEqual( before_count_proc_0 + 3, after_count_proc_0, "after_count_proc_0 is 3 more than before_count_proc_0" ) self.assertEqual( before_count_proc_1 + 3, after_count_proc_1, "after_count_proc_1 is 3 more than before_count_proc_1" )