Skip to content

Commit 978dc11

Browse files
authored
Merge pull request #147 from splitio/development
Development
2 parents 9a2f178 + 5117708 commit 978dc11

File tree

4 files changed

+139
-7
lines changed

4 files changed

+139
-7
lines changed

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
8.1.1 (14 Jun, 2019)
2+
- Fixed python3 compatibility issue in uwsgi caching mode.
13
8.1.0 (3 Jun, 2019)
24
- Added properties to track method.
35
- Input Validation: added validation for traffic types, split names and multiple factory instantiation.

splitio/tasks/uwsgi_wrappers.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def uwsgi_update_segments(user_config):
8080
HttpClient(1500, config.get('sdk_url'), config.get('events_url')), config['apikey']
8181
),
8282
UWSGISegmentStorage(get_uwsgi()),
83-
None, # Split sotrage not needed, segments provided manually,
83+
None, # Split storage not needed, segments provided manually,
8484
None, # Period not needed, task executed manually
8585
None # Flag not needed, never consumed or set.
8686
)
@@ -90,9 +90,8 @@ def uwsgi_update_segments(user_config):
9090
split_storage = UWSGISplitStorage(get_uwsgi())
9191
while True:
9292
try:
93-
for split in split_storage.get_all_splits():
94-
for segment_name in split.get_segment_names():
95-
pool.submit_work(segment_name)
93+
for segment_name in split_storage.get_segment_names():
94+
pool.submit_work(segment_name)
9695
time.sleep(seconds)
9796
except Exception: #pylint: disable=broad-except
9897
_LOGGER.error('Error updating segments')
@@ -124,7 +123,7 @@ def uwsgi_report_impressions(user_config):
124123
while True:
125124
try:
126125
impressions_sync_task._send_impressions() #pylint: disable=protected-access
127-
for _ in xrange(0, seconds):
126+
for _ in range(0, seconds):
128127
if storage.should_flush():
129128
storage.acknowledge_flush()
130129
break
@@ -157,7 +156,7 @@ def uwsgi_report_events(user_config):
157156
while True:
158157
try:
159158
task._send_events() #pylint: disable=protected-access
160-
for _ in xrange(0, seconds):
159+
for _ in range(0, seconds):
161160
if storage.should_flush():
162161
storage.acknowledge_flush()
163162
break

splitio/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '8.1.0'
1+
__version__ = '8.1.1'

tests/tasks/test_uwsgi_wrappers.py

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
"""UWSGI Task wrappers test module."""
2+
#pylint: disable=no-self-use,protected-access
3+
from splitio.storage import SplitStorage
4+
from splitio.tasks.split_sync import SplitSynchronizationTask
5+
from splitio.tasks.impressions_sync import ImpressionsSyncTask
6+
from splitio.tasks.events_sync import EventsSyncTask
7+
from splitio.tasks.telemetry_sync import TelemetrySynchronizationTask
8+
from splitio.tasks.util.workerpool import WorkerPool
9+
from splitio.storage.uwsgi import UWSGISplitStorage
10+
from splitio.tasks.uwsgi_wrappers import uwsgi_update_splits, uwsgi_update_segments, \
11+
uwsgi_report_events, uwsgi_report_impressions, uwsgi_report_telemetry
12+
13+
14+
class NonCatchableException(BaseException):
15+
"""Exception to be used to stop sync task's infinite loop."""
16+
17+
pass
18+
19+
20+
class TaskWrappersTests(object):
21+
"""Task wrappers task test cases."""
22+
23+
def test_update_splits(self, mocker):
24+
"""Test split sync task wrapper."""
25+
data = {'executions': 0}
26+
def _update_splits_side_effect(*_, **__):
27+
data['executions'] += 1
28+
if data['executions'] > 1:
29+
raise NonCatchableException('asd')
30+
31+
stmock = mocker.Mock(spec=SplitSynchronizationTask)
32+
stmock._update_splits.side_effect = _update_splits_side_effect
33+
stmock_class = mocker.Mock(spec=SplitSynchronizationTask)
34+
stmock_class.return_value = stmock
35+
mocker.patch('splitio.tasks.uwsgi_wrappers.SplitSynchronizationTask', new=stmock_class)
36+
37+
try:
38+
uwsgi_update_splits({'apikey' : 'asd', 'featuresRefreshRate': 1})
39+
except NonCatchableException:
40+
# Make sure that the task was called before being forced to stop.
41+
assert data['executions'] > 1
42+
assert len(stmock._update_splits.mock_calls) > 1
43+
44+
def test_update_segments(self, mocker):
45+
"""Test split sync task wrapper."""
46+
data = {'executions': 0}
47+
def _submit_work(*_, **__):
48+
data['executions'] += 1
49+
# we mock 2 segments, so we expect this to be called at least twice before ending.
50+
if data['executions'] > 2:
51+
raise NonCatchableException('asd')
52+
53+
wpmock = mocker.Mock(spec=WorkerPool)
54+
wpmock.submit_work.side_effect = _submit_work
55+
wpmock_class = mocker.Mock(spec=WorkerPool)
56+
wpmock_class.return_value = wpmock
57+
mocker.patch('splitio.tasks.uwsgi_wrappers.workerpool.WorkerPool', new=wpmock_class)
58+
59+
mocked_update_segment = mocker.patch.object(SplitStorage, 'get_segment_names')
60+
mocked_update_segment.return_value = ['segment1', 'segment2']
61+
mocked_split_storage_instance = UWSGISplitStorage(True)
62+
split_storage_mock = mocker.Mock(spec=UWSGISplitStorage)
63+
split_storage_mock.return_value = mocked_split_storage_instance
64+
65+
mocker.patch('splitio.tasks.uwsgi_wrappers.UWSGISplitStorage', new=split_storage_mock)
66+
67+
try:
68+
uwsgi_update_segments({'apikey' : 'asd', 'segmentsRefreshRate': 1})
69+
except NonCatchableException:
70+
# Make sure that the task was called before being forced to stop.
71+
assert data['executions'] > 2
72+
assert len(wpmock.submit_work.mock_calls) > 2
73+
74+
def test_post_impressions(self, mocker):
75+
"""Test split sync task wrapper."""
76+
data = {'executions': 0}
77+
def _report_impressions_side_effect(*_, **__):
78+
data['executions'] += 1
79+
if data['executions'] > 1:
80+
raise NonCatchableException('asd')
81+
82+
stmock = mocker.Mock(spec=ImpressionsSyncTask)
83+
stmock._send_impressions.side_effect = _report_impressions_side_effect
84+
stmock_class = mocker.Mock(spec=ImpressionsSyncTask)
85+
stmock_class.return_value = stmock
86+
mocker.patch('splitio.tasks.uwsgi_wrappers.ImpressionsSyncTask', new=stmock_class)
87+
try:
88+
uwsgi_report_impressions({'apikey' : 'asd', 'impressionsRefreshRate': 1})
89+
except NonCatchableException:
90+
# Make sure that the task was called before being forced to stop.
91+
assert data['executions'] > 1
92+
# TODO: Test impressions flushing.
93+
94+
def test_post_events(self, mocker):
95+
"""Test split sync task wrapper."""
96+
data = {'executions': 0}
97+
def _send_events_side_effect(*_, **__):
98+
data['executions'] += 1
99+
if data['executions'] > 1:
100+
raise NonCatchableException('asd')
101+
102+
stmock = mocker.Mock(spec=EventsSyncTask)
103+
stmock._send_events.side_effect = _send_events_side_effect
104+
stmock_class = mocker.Mock(spec=EventsSyncTask)
105+
stmock_class.return_value = stmock
106+
mocker.patch('splitio.tasks.uwsgi_wrappers.EventsSyncTask', new=stmock_class)
107+
try:
108+
uwsgi_report_events({'apikey' : 'asd', 'eventsRefreshRate': 1})
109+
except NonCatchableException:
110+
# Make sure that the task was called before being forced to stop.
111+
assert data['executions'] > 1
112+
# TODO: Test impressions flushing.
113+
114+
def test_post_telemetry(self, mocker):
115+
"""Test split sync task wrapper."""
116+
data = {'executions': 0}
117+
def _flush_telemetry_side_effect(*_, **__):
118+
data['executions'] += 1
119+
if data['executions'] > 1:
120+
raise NonCatchableException('asd')
121+
122+
stmock = mocker.Mock(spec=TelemetrySynchronizationTask)
123+
stmock._flush_telemetry.side_effect = _flush_telemetry_side_effect
124+
stmock_class = mocker.Mock(spec=TelemetrySynchronizationTask)
125+
stmock_class.return_value = stmock
126+
mocker.patch('splitio.tasks.uwsgi_wrappers.TelemetrySynchronizationTask', new=stmock_class)
127+
try:
128+
uwsgi_report_telemetry({'apikey' : 'asd', 'metricsRefreshRate': 1})
129+
except NonCatchableException:
130+
# Make sure that the task was called before being forced to stop.
131+
assert data['executions'] > 1

0 commit comments

Comments
 (0)