Skip to content

Commit c5e1ac6

Browse files
Merge b776edc into b156e21
2 parents b156e21 + b776edc commit c5e1ac6

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

optimizely/event/event_processor.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,13 @@ def flush(self):
222222

223223
def _flush_queue(self):
224224
""" Flushes event_queue by dispatching events. """
225-
226-
if len(self._current_batch) == 0:
225+
batch_len = len(self._current_batch)
226+
if batch_len == 0:
227+
self.logger.debug('Nothing to flush.')
227228
return
228229

230+
self.logger.debug('Flushing batch size ' + str(batch_len))
231+
229232
with self.LOCK:
230233
to_process_batch = list(self._current_batch)
231234
self._current_batch = list()
@@ -267,6 +270,7 @@ def _add_to_batch(self, user_event):
267270
user_event: UserEvent Instance.
268271
"""
269272
if self._should_split(user_event):
273+
self.logger.debug('Flush on split.')
270274
self._flush_queue()
271275
self._current_batch = list()
272276

@@ -277,6 +281,7 @@ def _add_to_batch(self, user_event):
277281
with self.LOCK:
278282
self._current_batch.append(user_event)
279283
if len(self._current_batch) >= self.batch_size:
284+
self.logger.debug('Flushing on batch size.')
280285
self._flush_queue()
281286

282287
def _should_split(self, user_event):

tests/test_event_processor.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def test_flush_once_max_timeout(self):
179179
self.optimizely.logger = SimpleLogger(enums.LogLevels.DEBUG)
180180

181181
with mock.patch.object(self.optimizely, 'logger') as mock_config_logging:
182-
self._set_event_processor(event_dispatcher, mock_config_logging)
182+
self._set_event_processor(event_dispatcher, self.optimizely.logger)
183183

184184
user_event = self._build_conversion_event(self.event_name)
185185
self.event_processor.process(user_event)
@@ -192,7 +192,8 @@ def test_flush_once_max_timeout(self):
192192
self.assertTrue(mock_config_logging.debug.called)
193193
mock_config_logging.debug.assert_any_call('Received event of type ConversionEvent for user test_user.')
194194
mock_config_logging.debug.assert_any_call('Flush interval deadline. Flushed queue.')
195-
self.assertTrue(mock_config_logging.debug.call_count == 2)
195+
mock_config_logging.debug.assert_any_call('Flushing batch size 1')
196+
self.assertTrue(mock_config_logging.debug.call_count == 3)
196197
self.optimizely.logger = SimpleLogger()
197198

198199
def test_flush_max_batch_size(self):

0 commit comments

Comments
 (0)