@@ -164,6 +164,61 @@ async def test_watchevent_batching(settings, resource, processor, timer,
164
164
assert actual_uid_val_pairs == expected_uid_val_pairs
165
165
166
166
167
+ @pytest .mark .parametrize ('uids, vals, events' , [
168
+
169
+ pytest .param (['uid1' , 'uid1' ], ['a' , 'b' ], [
170
+ {'type' : 'MODIFIED' , 'object' : {'metadata' : {'uid' : 'uid1' }, 'spec' : 'a' }},
171
+ {'type' : 'MODIFIED' , 'object' : {'metadata' : {'uid' : 'uid1' }, 'spec' : 'b' }},
172
+ ], id = 'the same' ),
173
+
174
+ pytest .param (['uid1' , 'uid2' ], ['a' , 'b' ], [
175
+ {'type' : 'MODIFIED' , 'object' : {'metadata' : {'uid' : 'uid1' }, 'spec' : 'a' }},
176
+ {'type' : 'MODIFIED' , 'object' : {'metadata' : {'uid' : 'uid2' }, 'spec' : 'b' }},
177
+ ], id = 'distinct' ),
178
+
179
+ pytest .param (['uid1' , 'uid2' , 'uid1' , 'uid2' , 'uid1' , 'uid3' ], ['a' , 'b' , 'c' , 'd' , 'e' , 'f' ], [
180
+ {'type' : 'ADDED' , 'object' : {'metadata' : {'uid' : 'uid1' }, 'spec' : 'a' }},
181
+ {'type' : 'ADDED' , 'object' : {'metadata' : {'uid' : 'uid2' }, 'spec' : 'b' }},
182
+ {'type' : 'MODIFIED' , 'object' : {'metadata' : {'uid' : 'uid1' }, 'spec' : 'c' }},
183
+ {'type' : 'MODIFIED' , 'object' : {'metadata' : {'uid' : 'uid2' }, 'spec' : 'd' }},
184
+ {'type' : 'DELETED' , 'object' : {'metadata' : {'uid' : 'uid1' }, 'spec' : 'e' }},
185
+ {'type' : 'DELETED' , 'object' : {'metadata' : {'uid' : 'uid3' }, 'spec' : 'f' }},
186
+ ], id = 'mixed' ),
187
+
188
+ ])
189
+ @pytest .mark .usefixtures ('watcher_limited' )
190
+ async def test_watchevent_none_batching (settings , resource , processor , timer ,
191
+ stream , events , uids , vals , event_loop ):
192
+ """ Verify that all stream events are handled if batching is disabled. """
193
+
194
+ # Override the default timeouts to make the tests faster.
195
+ settings .batching .idle_timeout = 100 # should not be involved, fail if it is
196
+ settings .batching .exit_timeout = 100 # should exit instantly, fail if it didn't
197
+ settings .batching .batch_window = None # disable batching entirely
198
+
199
+ # Inject the events of unique objects - to produce few streams/workers.
200
+ stream .feed (events )
201
+ stream .close ()
202
+
203
+ # Run the watcher (near-instantly and test-blocking).
204
+ with timer :
205
+ await watcher (
206
+ namespace = None ,
207
+ resource = resource ,
208
+ settings = settings ,
209
+ processor = processor ,
210
+ )
211
+
212
+ # Was the processor called exactly once for each stream event?
213
+ assert processor .await_count == len (events )
214
+
215
+ expected_uid_val_pairs = set (zip (uids , vals ))
216
+ actual_uid_val_pairs = set ((
217
+ kwargs ['raw_event' ]['object' ]['metadata' ]['uid' ],
218
+ kwargs ['raw_event' ]['object' ]['spec' ])
219
+ for args , kwargs in processor .call_args_list )
220
+ assert actual_uid_val_pairs == expected_uid_val_pairs
221
+
167
222
@pytest .mark .parametrize ('unique, events' , [
168
223
169
224
pytest .param (1 , [
0 commit comments