@@ -67,11 +67,62 @@ def test_all_chunks_sent(self, _process_bulk_chunk: Any) -> None:
67
67
68
68
self .assertEqual (50 , mock_process_bulk_chunk .call_count ) # type: ignore
69
69
70
+ @mock .patch ("opensearchpy.OpenSearch.bulk" )
71
+ def test_with_all_options (self , _bulk : Any ) -> None :
72
+ actions = ({"x" : i } for i in range (100 ))
73
+ list (
74
+ helpers .parallel_bulk (
75
+ OpenSearch (),
76
+ actions = actions ,
77
+ chunk_size = 2 ,
78
+ raise_on_error = False ,
79
+ raise_on_exception = False ,
80
+ max_chunk_bytes = 20 * 1024 * 1024 ,
81
+ request_timeout = 160 ,
82
+ ignore_status = (123 ),
83
+ )
84
+ )
85
+
86
+ self .assertEqual (50 , _bulk .call_count )
87
+ _bulk .assert_called_with (
88
+ '{"index":{}}\n {"x":98}\n {"index":{}}\n {"x":99}\n ' , request_timeout = 160
89
+ )
90
+
91
+ @mock .patch ("opensearchpy.helpers.actions._process_bulk_chunk" )
92
+ def test_process_bulk_chunk_with_all_options (
93
+ self , _process_bulk_chunk : Any
94
+ ) -> None :
95
+ actions = ({"x" : i } for i in range (100 ))
96
+ client = OpenSearch ()
97
+ list (
98
+ helpers .parallel_bulk (
99
+ client ,
100
+ actions = actions ,
101
+ chunk_size = 2 ,
102
+ raise_on_error = True ,
103
+ raise_on_exception = True ,
104
+ max_chunk_bytes = 20 * 1024 * 1024 ,
105
+ request_timeout = 160 ,
106
+ ignore_status = (123 ),
107
+ )
108
+ )
109
+
110
+ self .assertEqual (50 , _process_bulk_chunk .call_count )
111
+ _process_bulk_chunk .assert_called_with (
112
+ client ,
113
+ ['{"index":{}}' , '{"x":98}' , '{"index":{}}' , '{"x":99}' ],
114
+ [({"index" : {}}, {"x" : 98 }), ({"index" : {}}, {"x" : 99 })],
115
+ True ,
116
+ True ,
117
+ 123 ,
118
+ request_timeout = 160 ,
119
+ )
120
+
70
121
@pytest .mark .skip # type: ignore
71
122
@mock .patch (
72
123
"opensearchpy.helpers.actions._process_bulk_chunk" ,
73
124
# make sure we spend some time in the thread
74
- side_effect = lambda * a : [
125
+ side_effect = lambda * args , ** kwargs : [
75
126
(True , time .sleep (0.001 ) or threading .current_thread ().ident ) # type: ignore
76
127
],
77
128
)
0 commit comments