File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change
1
+ from multiprocessing import cpu_count
2
+
3
+ from django .test import TestCase
4
+
5
+ from django_elastic_migrations .utils .multiprocessing_utils import DjangoMultiProcess
6
+
7
+
8
+ def add_1 (num ):
9
+ return { 'job_id' : num , 'result' : num + 1 }
10
+
11
+
12
+ class TestMultiprocessingUtils (TestCase ):
13
+
14
+ def test_basic_multiprocessing (self ):
15
+ """
16
+ Do a basic test of DjangoMultiProcess that doesn't touch the database
17
+ :return:
18
+ :rtype:
19
+ """
20
+
21
+ one_to_ten = range (1 , 10 )
22
+
23
+ workers = cpu_count ()
24
+ django_multiprocess = DjangoMultiProcess (workers , log_debug_info = 3 )
25
+
26
+ with django_multiprocess :
27
+ django_multiprocess .map (add_1 , one_to_ten )
28
+
29
+ results = django_multiprocess .results ()
30
+
31
+ for result_obj in results :
32
+ job_id = result_obj .get ('job_id' )
33
+ result = result_obj .get ('result' )
34
+ self .assertEqual (job_id + 1 , result )
You can’t perform that action at this time.
0 commit comments