def test_concurrency_none(self): checks = [ SleepCheck(0.5, system=self.system, resources=self.resources), SleepCheck(0.5, system=self.system, resources=self.resources), SleepCheck(0.5, system=self.system, resources=self.resources) ] num_checks = len(checks) self.set_max_jobs(1) self.runner.runall(checks, self.system) # Ensure that all tests were run and without failures. self.assertEqual(len(checks), self.runner.stats.num_cases()) self.assertEqual(0, self.runner.stats.num_failures()) # Ensure that a single task was running all the time self.assertEqual(1, max(self.monitor.num_tasks)) # Read the timestamps sorted to permit simple concurrency tests. self.read_timestamps(self.monitor.tasks) # Ensure that the jobs were run after the previous job had finished # (e.g. begin[1] > end[0]). begin_after_end = ( b > e for b, e in zip(self.begin_stamps[1:], self.end_stamps[:-1])) self.assertTrue(all(begin_after_end))
def test_concurrency_unlimited(self): checks = [ SleepCheck(0.5, system=self.system, resources=self.resources), SleepCheck(0.5, system=self.system, resources=self.resources), SleepCheck(0.5, system=self.system, resources=self.resources) ] self.set_max_jobs(len(checks)) self.runner.runall(checks, self.system) # Ensure that all tests were run and without failures. self.assertEqual(len(checks), self.runner.stats.num_cases()) self.assertEqual(0, self.runner.stats.num_failures()) # Ensure that maximum concurrency was reached as fast as possible self.assertEqual(len(checks), max(self.monitor.num_tasks)) self.assertEqual(len(checks), self.monitor.num_tasks[len(checks)]) self.read_timestamps(self.monitor.tasks) # Warn if not all tests were run in parallel; the corresponding strict # check would be: # # self.assertTrue(self.begin_stamps[-1] <= self.end_stamps[0]) # if self.begin_stamps[-1] > self.end_stamps[0]: self.skipTest('the system seems too much loaded.')
def test_concurrency_none(self): checks = [ SleepCheck(0.5, system=self.system, resources=self.resources), SleepCheck(0.5, system=self.system, resources=self.resources), SleepCheck(0.5, system=self.system, resources=self.resources) ] num_checks = len(checks) self.set_max_jobs(1) self.runner.runall(checks, self.system) # Ensure that all tests were run and without failures. self.assertEqual(num_checks, self.runner.stats.num_cases()) self.assertEqual(0, self.runner.stats.num_failures()) # Ensure that there was only one active job at a time. self.assertEqual(len(self.debug_policy.num_active_cases), num_checks) self.assertEqual(max(self.debug_policy.num_active_cases), 1) # Read the timestamps sorted to permit simple concurrency tests. self.read_timestamps_sorted() # Ensure that the jobs were run after the previous job had finished # (e.g. begin[1] > end[0]). begin_after_end = [ b > e for b, e in zip(self.begin_stamps[1:], self.end_stamps[:-1]) ] self.assertTrue(all(begin_after_end))
def test_concurrency_unlimited(self): checks = [ SleepCheck(0.5, system=self.system, resources=self.resources), SleepCheck(0.5, system=self.system, resources=self.resources), SleepCheck(0.5, system=self.system, resources=self.resources) ] num_checks = len(checks) self.set_max_jobs(num_checks) self.runner.runall(checks, self.system) # Ensure that all tests were run and without failures. self.assertEqual(num_checks, self.runner.stats.num_cases()) self.assertEqual(0, self.runner.stats.num_failures()) # Ensure that all tests were simultaneously active. self.assertEqual(len(self.debug_policy.num_active_cases), num_checks) self.assertEqual(self.debug_policy.num_active_cases[-1], num_checks) # Read the timestamps sorted to permit simple concurrency tests. self.read_timestamps_sorted() # Warn if not all tests were run in parallel; the corresponding strict # check would be: # self.assertTrue(self.begin_stamps[-1] <= self.end_stamps[0]) if self.begin_stamps[-1] > self.end_stamps[0]: self.skipTest('the system seems too loaded.')
def test_kbd_interrupt_in_wait_with_concurrency(self): checks = [ KeyboardInterruptCheck(system=self.system, resources=self.resources), SleepCheck(10, system=self.system, resources=self.resources), SleepCheck(10, system=self.system, resources=self.resources), SleepCheck(10, system=self.system, resources=self.resources) ] self._run_checks(checks, 4)
def test_kbd_interrupt_in_setup_with_limited_concurrency(self): checks = [ SleepCheck(1, system=self.system, resources=self.resources), SleepCheck(1, system=self.system, resources=self.resources), SleepCheck(1, system=self.system, resources=self.resources), KeyboardInterruptCheck(phase='setup', system=self.system, resources=self.resources), ] self._run_checks(checks, 2)
def test_kbd_interrupt_in_wait_with_limited_concurrency(self): # The general idea for this test is to allow enough time for all the # four checks to be submitted and at the same time we need the # KeyboardInterruptCheck to finish first (the corresponding wait should # trigger the failure), so as to make the framework kill the remaining # three. checks = [ KeyboardInterruptCheck(system=self.system, resources=self.resources), SleepCheck(10, system=self.system, resources=self.resources), SleepCheck(10, system=self.system, resources=self.resources), SleepCheck(10, system=self.system, resources=self.resources) ] self._run_checks(checks, 2)
def test_concurrency_limited(self): # The number of checks must be <= 2*max_jobs. checks = [ SleepCheck(0.5, system=self.system, resources=self.resources), SleepCheck(0.5, system=self.system, resources=self.resources), SleepCheck(0.5, system=self.system, resources=self.resources), SleepCheck(0.5, system=self.system, resources=self.resources), SleepCheck(0.5, system=self.system, resources=self.resources) ] num_checks = len(checks) max_jobs = num_checks - 2 self.set_max_jobs(max_jobs) self.runner.runall(checks, self.system) # Ensure that all tests were run and without failures. self.assertEqual(num_checks, self.runner.stats.num_cases()) self.assertEqual(0, self.runner.stats.num_failures()) # Ensure that #max_jobs tests were simultaneously active. self.assertEqual(len(self.debug_policy.num_active_cases), num_checks) self.assertEqual(self.debug_policy.num_active_cases[max_jobs - 1], max_jobs) # Read the timestamps sorted to permit simple concurrency tests. self.read_timestamps_sorted() # Ensure that the jobs after the first #max_jobs were each run after # one of the previous #max_jobs jobs had finished # (e.g. begin[max_jobs] > end[0]). # Note: we may ensure this strictly as we may ensure serial behaviour. begin_after_end = [ b > e for b, e in zip(self.begin_stamps[max_jobs:], self.end_stamps[:-max_jobs]) ] self.assertTrue(all(begin_after_end)) # NOTE: to ensure that these remaining jobs were also run # in parallel one could do the command hereafter; however, it would # require to substantially increase the sleep time (in SleepCheck), # because of the delays in rescheduling (1s, 2s, 3s, 1s, 2s,...). # We currently prefer not to do this last concurrency test to avoid an # important prolongation of the unit test execution time. # self.assertTrue(self.begin_stamps[-1] < self.end_stamps[max_jobs]) # Warn if the first #max_jobs jobs were not run in parallel; the # corresponding strict check would be: # self.assertTrue(self.begin_stamps[max_jobs-1] <= self.end_stamps[0]) if self.begin_stamps[max_jobs - 1] > self.end_stamps[0]: self.skipTest('the system seems too loaded.')