diff --git a/beat/web/backend/tests.py b/beat/web/backend/tests.py index be2cc170e476c2397b76320f28ac504dbba9a80c..4ea21ef7a04443afaeb60f03711192ce76145db5 100644 --- a/beat/web/backend/tests.py +++ b/beat/web/backend/tests.py @@ -52,6 +52,18 @@ from .management.commands import qsetup from .schedule import schedule +def _sleep(seconds): + """For some reason, time.sleep is not reliable on this test unit. Use this""" + + slept = 0 + while slept < seconds: + #print("Slept %g seconds" % slept) + start = time.time() + time.sleep(seconds - slept) + slept += time.time() - start + #print("End special _sleep after %g seconds" % slept) + + # Example configuration with 3 queues with an increasing amount of resources # running on the same host QUEUES_WITHOUT_PRIORITY = { @@ -2556,7 +2568,7 @@ class WorkingExternally(TransactionTestCase): # actually runs the job (non-blocking) worker.work(self.environments, self.cpulimit, self.process) - time.sleep(5) #wait job completion + _sleep(5) # at this point, split should have been successful which shall # trigger job deletion and block update @@ -2595,7 +2607,7 @@ class WorkingExternally(TransactionTestCase): # actually runs the job (non-blocking) worker.work(self.environments, self.cpulimit, self.process) - time.sleep(5) #wait job completion + _sleep(5) #wait job completion # checks the number of statistics objects has increased by 1 self.assertEqual(HourlyStatistics.objects.count(), current_stats + 1) @@ -2650,7 +2662,7 @@ class WorkingExternally(TransactionTestCase): # actually runs the job (non-blocking) worker.work(self.environments, self.cpulimit, self.process) - time.sleep(5) #wait till done (sqlite doesn't impl. select_for_update()) + _sleep(5) #wait till done (sqlite doesn't impl. select_for_update()) # cancels the experiment xp.cancel() @@ -2659,7 +2671,7 @@ class WorkingExternally(TransactionTestCase): # launch another working cycle to kill the process worker.work(self.environments, self.cpulimit, self.process) - time.sleep(5) #wait till done (sqlite doesn't impl. select_for_update()) + _sleep(5) #wait till done (sqlite doesn't impl. select_for_update()) xp.refresh_from_db() # assert we have no database traces after the last block is done