Skip to content

Commit 12c2a46

Browse files
committed
Basic tests for parallel_bulk
1 parent acde15e commit 12c2a46

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

test_elasticsearch/test_helpers.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import mock
2+
import time
3+
import threading
4+
5+
from elasticsearch import helpers, Elasticsearch
6+
7+
from .test_cases import TestCase
8+
9+
class TestParallelBulk(TestCase):
10+
@mock.patch('elasticsearch.helpers._process_bulk_chunk', return_value=[])
11+
def test_all_chunks_sent(self, _process_bulk_chunk):
12+
actions = ({'x': i} for i in range(100))
13+
list(helpers.parallel_bulk(Elasticsearch(), actions, chunk_size=2))
14+
15+
self.assertEquals(50, _process_bulk_chunk.call_count)
16+
17+
@mock.patch(
18+
'elasticsearch.helpers._process_bulk_chunk',
19+
# make sure we spend some time in the thread
20+
side_effect=lambda *a: [(True, time.sleep(.001) or threading.get_ident())]
21+
)
22+
def test_chunk_sent_from_different_threads(self, _process_bulk_chunk):
23+
actions = ({'x': i} for i in range(100))
24+
results = list(helpers.parallel_bulk(Elasticsearch(), actions, thread_count=10, chunk_size=2))
25+
26+
self.assertTrue(len(set([r[1] for r in results])) > 1)
27+

0 commit comments

Comments
 (0)