def test_limit_exceeded(self): """ A rare case Checks whether length of individual chunks is always 1 after FD limit is exceeded. """ lim_u = int(scan._file_descriptor_resource_limit() * scan._MAGIC_NUMBER_SPLIT_UPPER_THRESHOLD) lim_l = int(scan._file_descriptor_resource_limit() * scan._MAGIC_NUMBER_SPLIT_LOWER_THRESHOLD) rng = int(self._patches['fd_res_lim'].new.return_value[0] * lim_l) o_fd_mock = self._patches['o_fds'].new self.assertLess(o_fd_mock.return_value, lim_l) for l in scan._split(range(rng)): if o_fd_mock.return_value < lim_l: self.assertTrue(1 < len(l) <= lim_u) o_fd_mock.return_value += 1 else: self.assertEqual(len(l), 1) self.assertGreaterEqual(o_fd_mock.return_value, lim_l)
def test_split_lengths(self): """ A normal use case. Checks whether length of individual chunks does not exceed resource limits. """ rng = int(self._patches['fd_res_lim'].new.return_value[0] * 5) lim = int(scan._file_descriptor_resource_limit() * scan._MAGIC_NUMBER_SPLIT_UPPER_THRESHOLD) for l in scan._split(range(rng)): self.assertLessEqual(len(l), lim)