Example #1
0
 def test_normal_managed_pool(self):
     settings.set_parallelism_enabled(True)
     usage_out = []
     res = maybe_parallel_map(None, map_fn, self.data, usage_out=usage_out)
     self.assertEqual(self.res, list(res))
     self.assertEqual(MappingType.ParallelManaged, usage_out[0])
     settings.set_parallelism_enabled(False)
Example #2
0
 def test_normal_provided_pool(self):
     settings.set_parallelism_enabled(True)
     pool = Pool()
     usage_out = []
     res = maybe_parallel_map(pool, map_fn, self.data, usage_out=usage_out)
     self.assertEqual(self.res, list(res))
     self.assertEqual(MappingType.ParallelUnmanaged, usage_out[0])
     pool.close()
     settings.set_parallelism_enabled(False)
Example #3
0
 def test_parallel_condition_bad(self):
     settings.set_parallelism_enabled(True)
     usage_out = []
     res = maybe_parallel_map(None,
                              map_fn,
                              self.data,
                              usage_out=usage_out,
                              condition=lambda: len(self.data) > 10)
     self.assertEqual(self.res, list(res))
     self.assertEqual(MappingType.Serial, usage_out[0])
     settings.set_parallelism_enabled(False)
Example #4
0
 def setUp(self) -> None:
     self.para_env_key: str = "REDVOX_ENABLE_PARALLELISM"
     if self.para_env_key in os.environ:
         del os.environ[self.para_env_key]
     settings.set_parallelism_enabled(None)
Example #5
0
 def test_set_parallelism_enabled_false(self):
     settings.set_parallelism_enabled(False)
     self.assertFalse(settings.is_parallelism_enabled())
Example #6
0
 def test_set_parallelism_enabled_true(self):
     settings.set_parallelism_enabled(True)
     self.assertTrue(settings.is_parallelism_enabled())
Example #7
0
 def tearDown(self) -> None:
     if self.para_env_key in os.environ:
         del os.environ[self.para_env_key]
     settings.set_parallelism_enabled(None)