Skip to content

Commit 1cc83f5

Browse files
authored
fix time zone mishandling that could make event debugging not work (#142)
1 parent 4d2e999 commit 1cc83f5

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

ldclient/event_processor.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44
# currently excluded from documentation - see docs/README.md
55

6+
from calendar import timegm
67
from collections import namedtuple
78
from email.utils import parsedate
89
import errno
@@ -361,7 +362,7 @@ def _handle_response(self, r):
361362
if server_date_str is not None:
362363
server_date = parsedate(server_date_str)
363364
if server_date is not None:
364-
timestamp = int(time.mktime(server_date) * 1000)
365+
timestamp = int(timegm(server_date) * 1000)
365366
self._last_known_past_time = timestamp
366367
if r.status > 299 and not is_http_error_recoverable(r.status):
367368
self._disabled = True

testing/test_event_processor.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,33 @@ def test_event_can_be_both_tracked_and_debugged():
280280
check_feature_event(output[2], e, True, user)
281281
check_summary_event(output[3])
282282

283+
def test_debug_mode_does_not_expire_if_both_client_time_and_server_time_are_before_expiration_time():
284+
with DefaultTestProcessor() as ep:
285+
# Pick a server time that slightly different from client time
286+
server_time = now() + 1000
287+
288+
# Send and flush an event we don't care about, just to set the last server time
289+
mock_http.set_server_time(server_time)
290+
ep.send_event({ 'kind': 'identify', 'user': { 'key': 'otherUser' }})
291+
flush_and_get_events(ep)
292+
293+
# Now send an event with debug mode on, with a "debug until" time that is further in
294+
# the future than both the client time and the server time
295+
debug_until = server_time + 10000
296+
e = {
297+
'kind': 'feature', 'key': 'flagkey', 'version': 11, 'user': user,
298+
'variation': 1, 'value': 'value', 'default': 'default',
299+
'trackEvents': False, 'debugEventsUntilDate': debug_until
300+
}
301+
ep.send_event(e)
302+
303+
# Should get a summary event only, not a full feature event
304+
output = flush_and_get_events(ep)
305+
assert len(output) == 3
306+
check_index_event(output[0], e, user)
307+
check_feature_event(output[1], e, True, user) # debug event
308+
check_summary_event(output[2])
309+
283310
def test_debug_mode_expires_based_on_client_time_if_client_time_is_later_than_server_time():
284311
with DefaultTestProcessor() as ep:
285312
# Pick a server time that is somewhat behind the client time

0 commit comments

Comments
 (0)