Skip to content

Commit

Permalink
Merge branch 'build-fix'
Browse files Browse the repository at this point in the history
  • Loading branch information
kp-cat committed Aug 11, 2019
2 parents 0c61901 + 1297b5d commit b9ce887
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 19 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Expand Up @@ -14,14 +14,14 @@ install:
- "virtualenv venv --no-site-packages"
- "source venv/bin/activate"
- pip install --upgrade pip setuptools
- pip install coverage
- pip install pytest --upgrade
- pip install pytest-cov --upgrade
- pip install codecov
- pip install --force-reinstall twine==1.12.1
- pip install -r requirements.txt
# command to run tests
script:
- coverage run --source configcatclient --omit "venv/*" -m unittest discover configcatclienttests "test_*.py"
- coverage report -m
- py.test --cov=configcatclient configcatclienttests
after_success:
- codecov
deploy:
Expand Down
20 changes: 10 additions & 10 deletions configcatclient/autopollingcachepolicy.py
Expand Up @@ -30,10 +30,19 @@ def __init__(self, config_fetcher, config_cache,
self._start_time = datetime.datetime.utcnow()
self._lock = ReadWriteLock()

self.thread = Thread(target=self.run, args=())
self.thread = Thread(target=self._run, args=[])
self.thread.daemon = True
self.thread.start()

def _run(self):
if self._is_running:
return

self._is_running = True
while self._is_running:
self.force_refresh()
time.sleep(self._poll_interval_seconds)

def get(self):
while not self._initialized \
and datetime.datetime.utcnow() < self._start_time + self._max_init_wait_time_seconds:
Expand All @@ -45,15 +54,6 @@ def get(self):
finally:
self._lock.release_read()

def run(self):
if self._is_running:
return
self._is_running = True

while self._is_running:
self.force_refresh()
time.sleep(self._poll_interval_seconds)

def force_refresh(self):
try:
self._lock.acquire_read()
Expand Down
7 changes: 4 additions & 3 deletions configcatclienttests/test_autopollingcachepolicy.py
@@ -1,3 +1,4 @@
import logging
import unittest
import time
from requests import HTTPError
Expand All @@ -7,6 +8,9 @@
from configcatclienttests.mocks import ConfigFetcherMock, ConfigFetcherWithErrorMock, ConfigFetcherWaitMock, \
ConfigFetcherCountMock, TEST_JSON, CallCounter, TEST_JSON2

logging.basicConfig()
log = logging.getLogger(__name__)


class AutoPollingCachePolicyTests(unittest.TestCase):
def test_wrong_params(self):
Expand Down Expand Up @@ -96,7 +100,6 @@ def test_rerun(self):
config_fetcher = ConfigFetcherMock()
config_cache = InMemoryConfigCache()
cache_policy = AutoPollingCachePolicy(config_fetcher, config_cache, 2, 5, None)
cache_policy.run()
time.sleep(2.200)
self.assertEqual(config_fetcher.get_call_count, 2)
cache_policy.stop()
Expand All @@ -106,7 +109,6 @@ def test_callback(self):
config_fetcher = ConfigFetcherMock()
config_cache = InMemoryConfigCache()
cache_policy = AutoPollingCachePolicy(config_fetcher, config_cache, 2, 5, call_counter.callback)
cache_policy.run()
time.sleep(1)
self.assertEqual(config_fetcher.get_call_count, 1)
self.assertEqual(call_counter.get_call_count, 1)
Expand All @@ -124,7 +126,6 @@ def test_callback_exception(self):
config_fetcher = ConfigFetcherMock()
config_cache = InMemoryConfigCache()
cache_policy = AutoPollingCachePolicy(config_fetcher, config_cache, 2, 5, call_counter.callback_exception)
cache_policy.run()
time.sleep(1)
self.assertEqual(config_fetcher.get_call_count, 1)
self.assertEqual(call_counter.get_call_count, 1)
Expand Down
3 changes: 3 additions & 0 deletions configcatclienttests/test_configcache.py
@@ -1,8 +1,11 @@
import logging
import unittest

from configcatclient.configcache import InMemoryConfigCache
from configcatclienttests.mocks import TEST_JSON

logging.basicConfig()


class ConfigCacheTests(unittest.TestCase):

Expand Down
8 changes: 5 additions & 3 deletions configcatclienttests/test_configcatclient.py
@@ -1,9 +1,11 @@
import logging
import unittest

from configcatclient import ConfigCatClientException
from configcatclient.configcatclient import ConfigCatClient
from configcatclienttests.mocks import ConfigCacheMock
from collections import Counter

logging.basicConfig()


class ConfigCatClientTests(unittest.TestCase):
Expand Down Expand Up @@ -47,8 +49,8 @@ def test_invalidation(self):
def test_get_all_keys(self):
client = ConfigCatClient('test', 0, 0, None, 0, config_cache_class=ConfigCacheMock)
# Two list should have exactly the same elements, order doesn't matter.
self.assertEqual(Counter(['testBoolKey', 'testStringKey', 'testIntKey', 'testDoubleKey']),
Counter(client.get_all_keys()))
self.assertEqual(set(['testBoolKey', 'testStringKey', 'testIntKey', 'testDoubleKey']),
set(client.get_all_keys()))
client.stop()


Expand Down
4 changes: 4 additions & 0 deletions configcatclienttests/test_integration_configcatclient.py
@@ -1,9 +1,12 @@
import logging
import unittest
import time

import configcatclient
from configcatclient import ConfigCatClientException

logging.basicConfig()

_API_KEY = 'PKDVCLf-Hq-h-kCzMp-L7Q/PaDVCFk9EpmD6sLpGLltTA'


Expand Down Expand Up @@ -136,5 +139,6 @@ def test_client_works_invalid_base_url(self):
self.assertEqual('default value', client.get_value('keySampleText', 'default value'))
client.stop()


if __name__ == '__main__':
unittest.main()
3 changes: 3 additions & 0 deletions configcatclienttests/test_lazyloadingcachepolicy.py
@@ -1,3 +1,4 @@
import logging
import unittest
import time
from requests import HTTPError
Expand All @@ -6,6 +7,8 @@
from configcatclient.lazyloadingcachepolicy import LazyLoadingCachePolicy
from configcatclienttests.mocks import ConfigFetcherMock, ConfigFetcherWithErrorMock, TEST_JSON

logging.basicConfig()


class LazyLoadingCachePolicyTests(unittest.TestCase):
def test_wrong_params(self):
Expand Down
3 changes: 3 additions & 0 deletions configcatclienttests/test_manualpollingcachepolicy.py
@@ -1,10 +1,13 @@
import logging
import unittest
from requests import HTTPError

from configcatclient.configcache import InMemoryConfigCache
from configcatclient.manualpollingcachepolicy import ManualPollingCachePolicy
from configcatclienttests.mocks import ConfigFetcherMock, ConfigFetcherWithErrorMock, TEST_JSON

logging.basicConfig()


class ManualPollingCachePolicyTests(unittest.TestCase):
def test_without_refresh(self):
Expand Down

0 comments on commit b9ce887

Please sign in to comment.