diff --git a/.circleci/config.yml b/.circleci/config.yml index 87453577..f33121db 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -86,9 +86,8 @@ jobs: - run: name: verify typehints command: | - pip install mypy export PATH="/home/circleci/.local/bin:$PATH" - mypy --config-file mypy.ini --python-version 3.5 ldclient/*.py testing/*.py + mypy --config-file mypy.ini ldclient testing - store_test_results: path: test-reports - store_artifacts: diff --git a/README.md b/README.md index 80bd937b..5782eff1 100644 --- a/README.md +++ b/README.md @@ -46,4 +46,3 @@ We encourage pull requests and other contributions from the community. Check out * [docs.launchdarkly.com](https://docs.launchdarkly.com/ "LaunchDarkly Documentation") for our documentation and SDK reference guides * [apidocs.launchdarkly.com](https://apidocs.launchdarkly.com/ "LaunchDarkly API Documentation") for our API documentation * [blog.launchdarkly.com](https://blog.launchdarkly.com/ "LaunchDarkly Blog Documentation") for the latest product updates - * [Feature Flagging Guide](https://github.com/launchdarkly/featureflags/ "Feature Flagging Guide") for best practices and strategies diff --git a/ldclient/event_processor.py b/ldclient/event_processor.py index 6bdb7da9..6174f7f2 100644 --- a/ldclient/event_processor.py +++ b/ldclient/event_processor.py @@ -3,6 +3,7 @@ """ # currently excluded from documentation - see docs/README.md +from calendar import timegm from collections import namedtuple from email.utils import parsedate import errno @@ -361,7 +362,7 @@ def _handle_response(self, r): if server_date_str is not None: server_date = parsedate(server_date_str) if server_date is not None: - timestamp = int(time.mktime(server_date) * 1000) + timestamp = int(timegm(server_date) * 1000) self._last_known_past_time = timestamp if r.status > 299 and not is_http_error_recoverable(r.status): self._disabled = True diff --git a/mypy.ini b/mypy.ini index d345df18..e886c085 100644 --- a/mypy.ini +++ b/mypy.ini @@ -1,3 +1,2 @@ [mypy] -ignore_missing_imports = true -python_version = 3.5 +ignore_missing_imports = true \ No newline at end of file diff --git a/test-requirements.txt b/test-requirements.txt index d73c173e..1f80fcc7 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -6,4 +6,5 @@ coverage>=4.4 jsonpickle==0.9.3 pytest-cov>=2.4.0 codeclimate-test-reporter>=0.2.1 -pytest-mypy==0.7 \ No newline at end of file +pytest-mypy==0.7 +mypy==0.800 \ No newline at end of file diff --git a/testing/test_event_processor.py b/testing/test_event_processor.py index 77ec05e8..0946b583 100644 --- a/testing/test_event_processor.py +++ b/testing/test_event_processor.py @@ -280,6 +280,33 @@ def test_event_can_be_both_tracked_and_debugged(): check_feature_event(output[2], e, True, user) check_summary_event(output[3]) +def test_debug_mode_does_not_expire_if_both_client_time_and_server_time_are_before_expiration_time(): + with DefaultTestProcessor() as ep: + # Pick a server time that slightly different from client time + server_time = now() + 1000 + + # Send and flush an event we don't care about, just to set the last server time + mock_http.set_server_time(server_time) + ep.send_event({ 'kind': 'identify', 'user': { 'key': 'otherUser' }}) + flush_and_get_events(ep) + + # Now send an event with debug mode on, with a "debug until" time that is further in + # the future than both the client time and the server time + debug_until = server_time + 10000 + e = { + 'kind': 'feature', 'key': 'flagkey', 'version': 11, 'user': user, + 'variation': 1, 'value': 'value', 'default': 'default', + 'trackEvents': False, 'debugEventsUntilDate': debug_until + } + ep.send_event(e) + + # Should get a summary event only, not a full feature event + output = flush_and_get_events(ep) + assert len(output) == 3 + check_index_event(output[0], e, user) + check_feature_event(output[1], e, True, user) # debug event + check_summary_event(output[2]) + def test_debug_mode_expires_based_on_client_time_if_client_time_is_later_than_server_time(): with DefaultTestProcessor() as ep: # Pick a server time that is somewhat behind the client time