|  | @@ -5,19 +5,31 @@ from synergine2.utils import ChunkManager
 | 
	
		
			
			| 5 | 5 |  from tests import BaseTest
 | 
	
		
			
			| 6 | 6 |  
 | 
	
		
			
			| 7 | 7 |  
 | 
	
		
			
			|  | 8 | +class MyFakeClass(object):
 | 
	
		
			
			|  | 9 | +    def __init__(self, value):
 | 
	
		
			
			|  | 10 | +        self.value = value
 | 
	
		
			
			|  | 11 | +
 | 
	
		
			
			|  | 12 | +
 | 
	
		
			
			| 8 | 13 |  class TestProcessing(BaseTest):
 | 
	
		
			
			| 9 | 14 |      @staticmethod
 | 
	
		
			
			| 10 |  | -    def _make_job(data_chunk: list) -> tuple:
 | 
	
		
			
			|  | 15 | +    def _make_job_with_scalar(data_chunk: list) -> tuple:
 | 
	
		
			
			| 11 | 16 |          current_pid = os.getpid()
 | 
	
		
			
			| 12 | 17 |          result = sum(data_chunk)
 | 
	
		
			
			| 13 | 18 |          return current_pid, result
 | 
	
		
			
			| 14 | 19 |  
 | 
	
		
			
			| 15 |  | -    def test_parallel_jobs(self):
 | 
	
		
			
			|  | 20 | +    @staticmethod
 | 
	
		
			
			|  | 21 | +    def _make_job_with_object(data_chunk: list) -> tuple:
 | 
	
		
			
			|  | 22 | +        current_pid = os.getpid()
 | 
	
		
			
			|  | 23 | +        data = [o.value for o in data_chunk]
 | 
	
		
			
			|  | 24 | +        result = sum(data)
 | 
	
		
			
			|  | 25 | +        return current_pid, MyFakeClass(result)
 | 
	
		
			
			|  | 26 | +
 | 
	
		
			
			|  | 27 | +    def test_parallel_jobs_with_scalar(self):
 | 
	
		
			
			| 16 | 28 |          chunk_manager = ChunkManager(4)
 | 
	
		
			
			| 17 | 29 |          process_manager = ProcessManager(
 | 
	
		
			
			| 18 | 30 |              process_count=4,
 | 
	
		
			
			| 19 | 31 |              chunk_manager=chunk_manager,
 | 
	
		
			
			| 20 |  | -            job_maker=self._make_job,
 | 
	
		
			
			|  | 32 | +            job_maker=self._make_job_with_scalar,
 | 
	
		
			
			| 21 | 33 |          )
 | 
	
		
			
			| 22 | 34 |  
 | 
	
		
			
			| 23 | 35 |          data = list(range(100))
 | 
	
	
		
			
			|  | @@ -36,3 +48,28 @@ class TestProcessing(BaseTest):
 | 
	
		
			
			| 36 | 48 |  
 | 
	
		
			
			| 37 | 49 |          # Goal is 4950
 | 
	
		
			
			| 38 | 50 |          assert final_result == 4950
 | 
	
		
			
			|  | 51 | +
 | 
	
		
			
			|  | 52 | +    def test_parallel_jobs_with_objects(self):
 | 
	
		
			
			|  | 53 | +        chunk_manager = ChunkManager(4)
 | 
	
		
			
			|  | 54 | +        process_manager = ProcessManager(
 | 
	
		
			
			|  | 55 | +            process_count=4,
 | 
	
		
			
			|  | 56 | +            chunk_manager=chunk_manager,
 | 
	
		
			
			|  | 57 | +            job_maker=self._make_job_with_object,
 | 
	
		
			
			|  | 58 | +        )
 | 
	
		
			
			|  | 59 | +
 | 
	
		
			
			|  | 60 | +        data = [MyFakeClass(v) for v in range(100)]
 | 
	
		
			
			|  | 61 | +        process_id_list = []
 | 
	
		
			
			|  | 62 | +        final_result = 0
 | 
	
		
			
			|  | 63 | +
 | 
	
		
			
			|  | 64 | +        results = process_manager.execute_jobs(data)
 | 
	
		
			
			|  | 65 | +
 | 
	
		
			
			|  | 66 | +        for process_id, result_object in results:
 | 
	
		
			
			|  | 67 | +            final_result += result_object.value
 | 
	
		
			
			|  | 68 | +            process_id_list.append(process_id)
 | 
	
		
			
			|  | 69 | +
 | 
	
		
			
			|  | 70 | +        # Test each process ids are differents
 | 
	
		
			
			|  | 71 | +        assert sorted(process_id_list) == \
 | 
	
		
			
			|  | 72 | +            sorted(list(set(process_id_list)))
 | 
	
		
			
			|  | 73 | +
 | 
	
		
			
			|  | 74 | +        # Goal is 4950
 | 
	
		
			
			|  | 75 | +        assert final_result == 4950
 |