Skip to content

Commit

Permalink
Update test_frontend.py
Browse files Browse the repository at this point in the history
  • Loading branch information
kgrygiel committed Aug 26, 2015
1 parent 155d21a commit e712984
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions compute/autoscaler/demo/tests/test_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@


class FakeTime(object):
"""Fake implementations of GetWallTime, GetUserCpuTime and BusyWait.
"""Fake implementations of GetUserCpuTime, GetUserCpuTime and BusyWait.
Each call to BusyWait advances both the cpu and the wall clocks by fixed
intervals (cpu_time_step and wall_time_step, respectively). This can be
used to simulate arbitrary fraction of CPU time available to the process.
Expand All @@ -31,13 +30,13 @@ def __init__(self, cpu_time_step=1.0, wall_time_step=1.0):
self.cpu_time_step = cpu_time_step
self.wall_time_step = wall_time_step

def GetWallTime(self):
def get_walltime(self):
return self.wall_time

def GetUserCpuTime(self):
def get_user_cputime(self):
return self.cpu_time

def BusyWait(self):
def busy_wait(self):
self.wall_time += self.wall_time_step
self.cpu_time += self.cpu_time_step

Expand All @@ -46,24 +45,24 @@ class TestHandlers(unittest.TestCase):
def setUp(self):
self.fake_time = FakeTime()
self.cpu_burner = frontend.CpuBurner()
self.cpu_burner.GetUserCpuTime = self.fake_time.GetUserCpuTime
self.cpu_burner.GetWallTime = self.fake_time.GetWallTime
self.cpu_burner.BusyWait = self.fake_time.BusyWait
self.cpu_burner.get_user_cputime = self.fake_time.get_user_cputime
self.cpu_burner.get_walltime = self.fake_time.get_walltime
self.cpu_burner.busy_wait = self.fake_time.busy_wait

# In this test scenario CPU time advances at 25% of the wall clock rate.
# In this test scenario CPU time advances at 25% of the wall time speed.
# Given the request requires 1 CPU core second, we expect it to finish
# within the timeout (5 seconds) and return success.
def test_ok_response(self):
self.fake_time.cpu_time_step = 0.25
(code, _) = self.cpu_burner.HandleHttpRequest()
(code, _) = self.cpu_burner.handle_http_request()
self.assertEqual(200, code)

# In this test scenario CPU time advances at 15% of the wall clock rate.
# In this test scenario CPU time advances at 15% of the wall time speed.
# Given the request requires 1 CPU core second, we expect it to timeout
# after 5 simulated wall time seconds and return HTTP error 500.
# after 5 simulated wall time seconds and return error 500.
def test_timeout(self):
self.fake_time.cpu_time_step = 0.15
(code, _) = self.cpu_burner.HandleHttpRequest()
(code, _) = self.cpu_burner.handle_http_request()
self.assertEqual(500, code)


Expand Down

0 comments on commit e712984

Please sign in to comment.