Correct tests about periodicity.

Also be more precise about actual status of instance.
Also add new periodicity tests about ignored not started instance
parent 0ad4956a
...@@ -1037,6 +1037,7 @@ class TestSlapgridCPPartitionProcessing (MasterMixin, unittest.TestCase): ...@@ -1037,6 +1037,7 @@ class TestSlapgridCPPartitionProcessing (MasterMixin, unittest.TestCase):
timestamp = str(int(time.time())) timestamp = str(int(time.time()))
instance.timestamp = timestamp instance.timestamp = timestamp
instance.requested_state = 'started'
unwanted_periodicity = 2 unwanted_periodicity = 2
instance.software.setPeriodicity(unwanted_periodicity) instance.software.setPeriodicity(unwanted_periodicity)
self.grid.force_periodicity = True self.grid.force_periodicity = True
...@@ -1050,7 +1051,7 @@ class TestSlapgridCPPartitionProcessing (MasterMixin, unittest.TestCase): ...@@ -1050,7 +1051,7 @@ class TestSlapgridCPPartitionProcessing (MasterMixin, unittest.TestCase):
self.assertNotEqual(unwanted_periodicity,self.grid.maximum_periodicity) self.assertNotEqual(unwanted_periodicity,self.grid.maximum_periodicity)
self.assertEqual(computer.sequence, self.assertEqual(computer.sequence,
['getFullComputerInformation', 'availableComputerPartition', ['getFullComputerInformation', 'availableComputerPartition',
'stoppedComputerPartition', 'getFullComputerInformation']) 'startedComputerPartition', 'getFullComputerInformation'])
def test_one_partition_periodicity_from_file_does_not_disturb_others(self): def test_one_partition_periodicity_from_file_does_not_disturb_others(self):
...@@ -1070,35 +1071,115 @@ class TestSlapgridCPPartitionProcessing (MasterMixin, unittest.TestCase): ...@@ -1070,35 +1071,115 @@ class TestSlapgridCPPartitionProcessing (MasterMixin, unittest.TestCase):
instance0 = computer.instance_list[0] instance0 = computer.instance_list[0]
timestamp = str(int(time.time()-5)) timestamp = str(int(time.time()-5))
instance0.timestamp = timestamp instance0.timestamp = timestamp
instance0.requested_state = 'started'
for instance in computer.instance_list[1:]: for instance in computer.instance_list[1:]:
instance.software = \ instance.software = \
computer.software_list[computer.instance_list.index(instance)] computer.software_list[computer.instance_list.index(instance)]
instance.timestamp = timestamp instance.timestamp = timestamp
wanted_periodicity = 3 wanted_periodicity = 1
instance0.software.setPeriodicity(wanted_periodicity) instance0.software.setPeriodicity(wanted_periodicity)
self.launchSlapgrid() self.launchSlapgrid()
self.assertNotEqual(wanted_periodicity, self.grid.maximum_periodicity)
last_runtime = os.path.getmtime(
os.path.join(instance0.partition_path, '.timestamp'))
time.sleep(wanted_periodicity + 1)
for instance in computer.instance_list[1:]:
self.assertEqual(instance.sequence,
['availableComputerPartition', 'stoppedComputerPartition'])
time.sleep(1)
self.launchSlapgrid()
self.assertEqual(instance0.sequence,
['availableComputerPartition', 'startedComputerPartition',
'availableComputerPartition', 'startedComputerPartition',
])
for instance in computer.instance_list[1:]:
self.assertEqual(instance.sequence,
['availableComputerPartition', 'stoppedComputerPartition'])
self.assertGreater(
os.path.getmtime(os.path.join(instance0.partition_path,'.timestamp')),
last_runtime)
self.assertNotEqual(wanted_periodicity,self.grid.maximum_periodicity) self.assertNotEqual(wanted_periodicity,self.grid.maximum_periodicity)
def test_one_partition_stopped_is_not_processed_after_periodicity(self):
"""
Check that periodicity doesn't force processing a partition if it is not
started.
"""
computer = ComputerForTest(self.software_root,self.instance_root,20,20)
instance0 = computer.instance_list[0]
timestamp = str(int(time.time()-5))
instance0.timestamp = timestamp
for instance in computer.instance_list[1:]:
instance.software = \
computer.software_list[computer.instance_list.index(instance)]
instance.timestamp = timestamp
wanted_periodicity = 1
instance0.software.setPeriodicity(wanted_periodicity)
self.launchSlapgrid()
self.assertNotEqual(wanted_periodicity, self.grid.maximum_periodicity)
last_runtime = os.path.getmtime( last_runtime = os.path.getmtime(
os.path.join(instance0.partition_path, '.timestamp')) os.path.join(instance0.partition_path, '.timestamp'))
time.sleep(wanted_periodicity + 1) time.sleep(wanted_periodicity + 1)
for instance in computer.instance_list[1:]: for instance in computer.instance_list[1:]:
self.assertEqual(instance.sequence, self.assertEqual(instance.sequence,
['availableComputerPartition', 'stoppedComputerPartition']) ['availableComputerPartition', 'stoppedComputerPartition'])
time.sleep(1)
self.launchSlapgrid() self.launchSlapgrid()
self.assertEqual(instance0.sequence, self.assertEqual(instance0.sequence,
['availableComputerPartition', 'stoppedComputerPartition', ['availableComputerPartition', 'stoppedComputerPartition',
'availableComputerPartition', 'stoppedComputerPartition',
]) ])
for instance in computer.instance_list[1:]: for instance in computer.instance_list[1:]:
self.assertEqual(instance.sequence, self.assertEqual(instance.sequence,
['availableComputerPartition', 'stoppedComputerPartition']) ['availableComputerPartition', 'stoppedComputerPartition'])
self.assertGreater( self.assertEqual(
os.path.getmtime(os.path.join(instance0.partition_path,'.timestamp')), os.path.getmtime(os.path.join(instance0.partition_path,'.timestamp')),
last_runtime) last_runtime)
self.assertNotEqual(wanted_periodicity,self.grid.maximum_periodicity) self.assertNotEqual(wanted_periodicity,self.grid.maximum_periodicity)
def test_one_partition_destroyed_is_not_processed_after_periodicity(self):
"""
Check that periodicity doesn't force processing a partition if it is not
started.
"""
computer = ComputerForTest(self.software_root,self.instance_root,20,20)
instance0 = computer.instance_list[0]
timestamp = str(int(time.time()-5))
instance0.timestamp = timestamp
instance0.requested_state = 'stopped'
for instance in computer.instance_list[1:]:
instance.software = \
computer.software_list[computer.instance_list.index(instance)]
instance.timestamp = timestamp
wanted_periodicity = 1
instance0.software.setPeriodicity(wanted_periodicity)
self.launchSlapgrid()
self.assertNotEqual(wanted_periodicity, self.grid.maximum_periodicity)
last_runtime = os.path.getmtime(
os.path.join(instance0.partition_path, '.timestamp'))
time.sleep(wanted_periodicity + 1)
for instance in computer.instance_list[1:]:
self.assertEqual(instance.sequence,
['availableComputerPartition', 'stoppedComputerPartition'])
time.sleep(1)
instance0.requested_state = 'destroyed'
self.launchSlapgrid()
self.assertEqual(instance0.sequence,
['availableComputerPartition', 'stoppedComputerPartition',
])
for instance in computer.instance_list[1:]:
self.assertEqual(instance.sequence,
['availableComputerPartition', 'stoppedComputerPartition'])
self.assertEqual(
os.path.getmtime(os.path.join(instance0.partition_path,'.timestamp')),
last_runtime)
self.assertNotEqual(wanted_periodicity,self.grid.maximum_periodicity)
def test_one_partition_buildout_fail_does_not_disturb_others(self): def test_one_partition_buildout_fail_does_not_disturb_others(self):
""" """
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment