Skip to content

Commit 4fee7a0

Browse files
committed
fix tests
1 parent babbdb2 commit 4fee7a0

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

tests/client/test_factory.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ def _segment_task_init_mock(self, api, storage, split_storage, period, event):
8888
factory.block_until_ready()
8989
time.sleep(1) # give a chance for the bg thread to set the ready status
9090
assert factory.ready
91+
factory.destroy()
9192

9293
def test_redis_client_creation(self, mocker):
9394
"""Test that a client with redis storage is created correctly."""
@@ -165,6 +166,7 @@ def test_redis_client_creation(self, mocker):
165166
factory.block_until_ready()
166167
time.sleep(1) # give a chance for the bg thread to set the ready status
167168
assert factory.ready
169+
factory.destroy()
168170

169171

170172
def test_uwsgi_client_creation(self):
@@ -182,6 +184,7 @@ def test_uwsgi_client_creation(self):
182184
factory.block_until_ready()
183185
time.sleep(1) # give a chance for the bg thread to set the ready status
184186
assert factory.ready
187+
factory.destroy()
185188

186189
def test_destroy(self, mocker):
187190
"""Test that tasks are shutdown and data is flushed when destroy is called."""
@@ -366,7 +369,7 @@ def _make_factory_with_apikey(apikey, *_, **__):
366369
assert _INSTANTIATED_FACTORIES['some_api_key'] == 1
367370
assert factory_module_logger.warning.mock_calls == []
368371

369-
get_factory('some_api_key')
372+
factory2 = get_factory('some_api_key')
370373
assert _INSTANTIATED_FACTORIES['some_api_key'] == 2
371374
assert factory_module_logger.warning.mock_calls == [mocker.call(
372375
"factory instantiation: You already have %d %s with this API Key. "
@@ -377,7 +380,7 @@ def _make_factory_with_apikey(apikey, *_, **__):
377380
)]
378381

379382
factory_module_logger.reset_mock()
380-
get_factory('some_api_key')
383+
factory3 = get_factory('some_api_key')
381384
assert _INSTANTIATED_FACTORIES['some_api_key'] == 3
382385
assert factory_module_logger.warning.mock_calls == [mocker.call(
383386
"factory instantiation: You already have %d %s with this API Key. "
@@ -388,7 +391,7 @@ def _make_factory_with_apikey(apikey, *_, **__):
388391
)]
389392

390393
factory_module_logger.reset_mock()
391-
get_factory('some_other_api_key')
394+
factory4 = get_factory('some_other_api_key')
392395
assert _INSTANTIATED_FACTORIES['some_api_key'] == 3
393396
assert _INSTANTIATED_FACTORIES['some_other_api_key'] == 1
394397
assert factory_module_logger.warning.mock_calls == [mocker.call(
@@ -403,3 +406,6 @@ def _make_factory_with_apikey(apikey, *_, **__):
403406
event.wait()
404407
assert _INSTANTIATED_FACTORIES['some_other_api_key'] == 1
405408
assert _INSTANTIATED_FACTORIES['some_api_key'] == 2
409+
factory2.destroy()
410+
factory3.destroy()
411+
factory4.destroy()

tests/client/test_input_validator.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,9 +1108,13 @@ def test_input_validation_factory(self, mocker):
11081108
]
11091109

11101110
logger.reset_mock()
1111-
assert get_factory(True, config={'uwsgiClient': True}) is not None
1111+
f = get_factory(True, config={'uwsgiClient': True})
1112+
assert f is not None
11121113
assert logger.error.mock_calls == []
1114+
f.destroy()
11131115

11141116
logger.reset_mock()
1115-
assert get_factory(True, config={'redisHost': 'some-host'}) is not None
1117+
f = get_factory(True, config={'redisHost': 'some-host'})
1118+
assert f is not None
11161119
assert logger.error.mock_calls == []
1120+
f.destroy()

tests/integration/test_client_e2e.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#pylint: disable=protected-access,line-too-long,no-self-use
33
import json
44
import os
5+
import time
56

67
from redis import StrictRedis
78

@@ -577,6 +578,7 @@ def test_localhost_e2e(self):
577578
filename = os.path.join(os.path.dirname(__file__), 'files', 'file2.yaml')
578579
factory = get_factory('localhost', config={'splitFile': filename})
579580
factory.block_until_ready()
581+
time.sleep(1)
580582
client = factory.client()
581583
assert client.get_treatment_with_config('key', 'my_feature') == ('on', '{"desc" : "this applies only to ON treatment"}')
582584
assert client.get_treatment_with_config('only_key', 'my_feature') == (

0 commit comments

Comments
 (0)