Skip to content
Merged
Prev Previous commit
Next Next commit
changed absolute paths for mock
  • Loading branch information
ashermancinelli committed Dec 20, 2018
commit cbab6cb64c38803f95d29ccf45732a4d0a96e25c
9 changes: 5 additions & 4 deletions test_elasticsearch/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,23 @@ def mock_process_bulk_chunk(*args, **kwargs):


class TestParallelBulk(TestCase):
@mock.patch('elasticsearch.helpers._process_bulk_chunk', side_effect=mock_process_bulk_chunk)
@mock.patch('elasticsearch.helpers.actions._process_bulk_chunk', side_effect=mock_process_bulk_chunk)
def test_all_chunks_sent(self, _process_bulk_chunk):
actions = ({'x': i} for i in range(100))
list(helpers.parallel_bulk(Elasticsearch(), actions, chunk_size=2))

self.assertEquals(50, _process_bulk_chunk.call_count)

@mock.patch(
'elasticsearch.helpers._process_bulk_chunk',
'elasticsearch.helpers.actions._process_bulk_chunk',
# make sure we spend some time in the thread
side_effect=lambda *a: [(True, time.sleep(.001) or threading.current_thread().ident)]
)
def test_chunk_sent_from_different_threads(self, _process_bulk_chunk):
actions = ({'x': i} for i in range(100))
results = list(helpers.parallel_bulk(Elasticsearch(), actions, thread_count=10, chunk_size=2))

print('spawning...')
results = list(helpers.actions.parallel_bulk(Elasticsearch(), actions, thread_count=10, chunk_size=2))
print('got promises')
self.assertTrue(len(set([r[1] for r in results])) > 1)

class TestChunkActions(TestCase):
Expand Down