Skip to content

Commit fdcf226

Browse files
committed
add basic test for multiprocessing_utils so pr coverage does not go down
#35 open multiprocessing log in context handler
1 parent 781c962 commit fdcf226

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

tests/test_multiprocessing_utils.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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)

0 commit comments

Comments
 (0)