Skip to content
Snippets Groups Projects
Commit 434374bf authored by Jan David Mol's avatar Jan David Mol
Browse files

Task #11020: Hardened checks in test and added assertions on system-provided input

parent 2c41c456
No related branches found
No related tags found
No related merge requests found
from datetime import datetime from datetime import datetime, timedelta
from lofar.common.cache import cache from lofar.common.cache import cache
...@@ -70,6 +70,9 @@ class BasicScheduler(object): ...@@ -70,6 +70,9 @@ class BasicScheduler(object):
# Any resources that we cannot schedule on for some reason # Any resources that we cannot schedule on for some reason
self.unusable_resources = [] self.unusable_resources = []
# Duration must be non-negative or weird stuff will happen
assert self.starttime <= self.endtime
def allocate_resources(self, estimates): def allocate_resources(self, estimates):
""" """
Tries to allocate resources for the given estimates. Tries to allocate resources for the given estimates.
...@@ -471,6 +474,12 @@ class DwellScheduler(PriorityScheduler): ...@@ -471,6 +474,12 @@ class DwellScheduler(PriorityScheduler):
self.max_starttime = max_starttime self.max_starttime = max_starttime
self.duration = duration self.duration = duration
# Duration must be non-negative or weird stuff will happen
assert self.duration >= timedelta(0, 0, 0)
# Time span for starttime must be sane
assert self.min_starttime <= self.max_starttime
def _new_starttime(self, starttime): def _new_starttime(self, starttime):
""" """
Set new start and end time based on the start time Set new start and end time based on the start time
......
...@@ -223,14 +223,6 @@ class BasicSchedulerTest(SchedulerTest): ...@@ -223,14 +223,6 @@ class BasicSchedulerTest(SchedulerTest):
self.scheduler = BasicScheduler(task_id, self.fake_resource_availability_checker, None) self.scheduler = BasicScheduler(task_id, self.fake_resource_availability_checker, None)
def verify_claim(self, claim):
""" Verify whether a claim is correct and complete. """
self.assertIn("status", claim)
self.assertIn("starttime", claim)
self.assertIn("endtime", claim)
self.assertIn("claim_size", claim)
self.assertIn("resource_type_id", claim)
def test_schedule_task(self): def test_schedule_task(self):
""" Whether a task (that fits) can be scheduled. """ """ Whether a task (that fits) can be scheduled. """
...@@ -245,11 +237,21 @@ class BasicSchedulerTest(SchedulerTest): ...@@ -245,11 +237,21 @@ class BasicSchedulerTest(SchedulerTest):
self.assertTrue(self.fake_ra_database.committed) self.assertTrue(self.fake_ra_database.committed)
self.assertFalse(self.fake_ra_database.rolled_back) self.assertFalse(self.fake_ra_database.rolled_back)
# Claims must be present in database and valid # Claim must be present in database
claims = self.fake_ra_database.claims[0] claims = self.fake_ra_database.claims[0]
self.assertTrue(claims) self.assertTrue(claims)
for c in claims: self.assertEqual(len(claims), 1)
self.verify_claim(c)
# Claim must be valid
claim = claims[0]
task = self.fake_ra_database.tasks[0]
self.assertEqual(claim["status"], "claimed")
self.assertEqual(claim["starttime"], task["starttime"])
self.assertEqual(claim["endtime"], task["endtime"])
self.assertEqual(claim["claim_size"], 512)
self.assertEqual(claim["resource_type_id"], FakeResourceAvailabilityChecker.resource_types["bandwidth"])
def test_multiple_resources(self): def test_multiple_resources(self):
""" Whether a task (that fits) can be scheduled. """ """ Whether a task (that fits) can be scheduled. """
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment