Skip to content

Commit 08ada59

Browse files
authored
Merge pull request splitio#53 from splitio/fixAlgoDefault
Fix algo default
2 parents 285a6da + 615ce63 commit 08ada59

File tree

3 files changed

+76
-4
lines changed

3 files changed

+76
-4
lines changed

splitio/splits.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ def __init__(self, name, seed, killed, default_treatment, traffic_type_name,
6464
self._status = status
6565
self._change_number = change_number
6666
self._conditions = conditions if conditions is not None else []
67-
self._algo = HashAlgorithm(algo) if algo else HashAlgorithm.LEGACY
67+
try:
68+
self._algo = HashAlgorithm(algo)
69+
except ValueError:
70+
self._algo = HashAlgorithm.LEGACY
6871

6972
@property
7073
def name(self):

splitio/tests/algoSplits.json

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,67 @@
196196
]
197197
}
198198
]
199+
},
200+
{
201+
"orgId": null,
202+
"environment": null,
203+
"trafficTypeId": null,
204+
"trafficTypeName": null,
205+
"name": "some_feature_5",
206+
"algo": 38,
207+
"seed": 1548363147,
208+
"changeNumber":1325599980,
209+
"status": "ACTIVE",
210+
"killed": false,
211+
"defaultTreatment": "off",
212+
"conditions": [
213+
{
214+
"matcherGroup": {
215+
"combiner": "AND",
216+
"matchers": [
217+
{
218+
"matcherType": "IN_SEGMENT",
219+
"negate": false,
220+
"userDefinedSegmentMatcherData": {
221+
"segmentName": "employees"
222+
},
223+
"whitelistMatcherData": null
224+
}
225+
]
226+
},
227+
"partitions": [
228+
{
229+
"treatment": "on",
230+
"size": 100
231+
}
232+
]
233+
},
234+
{
235+
"matcherGroup": {
236+
"combiner": "AND",
237+
"matchers": [
238+
{
239+
"matcherType": "IN_SEGMENT",
240+
"negate": false,
241+
"userDefinedSegmentMatcherData": {
242+
"segmentName": "human_beigns"
243+
},
244+
"whitelistMatcherData": null
245+
}
246+
]
247+
},
248+
"partitions": [
249+
{
250+
"treatment": "on",
251+
"size": 30
252+
},
253+
{
254+
"treatment": "off",
255+
"size": 70
256+
}
257+
]
258+
}
259+
]
199260
}
200261
],
201262
"since": -1,

splitio/tests/test_splits.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@
1212
import json
1313
from splitio.splits import (InMemorySplitFetcher, SelfRefreshingSplitFetcher, SplitChangeFetcher,
1414
ApiSplitChangeFetcher, SplitParser, AllKeysSplit,
15-
CacheBasedSplitFetcher)
15+
CacheBasedSplitFetcher, HashAlgorithm)
1616
from splitio.matchers import (AndCombiner, AllKeysMatcher, UserDefinedSegmentMatcher,
1717
WhitelistMatcher, AttributeMatcher)
1818
from splitio.tests.utils import MockUtilsMixin
1919
from os.path import join, dirname
2020
from splitio.hashfns import _murmur_hash, get_hash_fn
2121
from splitio.hashfns.legacy import legacy_hash
22-
from splitio.splits import HashAlgorithm
2322
from splitio.redis_support import get_redis, RedisSegmentCache, RedisSplitParser
2423
from splitio.uwsgi import get_uwsgi, UWSGISegmentCache, UWSGISplitParser
2524

@@ -932,6 +931,11 @@ def setUp(self):
932931
'body': rawData[3],
933932
'algo': HashAlgorithm.LEGACY,
934933
'hashfn': legacy_hash
934+
},
935+
{
936+
'body': rawData[4],
937+
'algo': HashAlgorithm.LEGACY,
938+
'hashfn': legacy_hash
935939
}]
936940

937941
def testAlgoHandlers(self):
@@ -941,7 +945,6 @@ def testAlgoHandlers(self):
941945
segment_cache = RedisSegmentCache(redis)
942946
split_parser = RedisSplitParser(segment_cache)
943947
for sp in self._testData:
944-
print(sp)
945948
split = split_parser.parse(sp['body'], True)
946949
self.assertEqual(split.algo, sp['algo'])
947950
self.assertEqual(get_hash_fn(split.algo), sp['hashfn'])
@@ -973,6 +976,11 @@ def setUp(self):
973976
'body': rawData[3],
974977
'algo': HashAlgorithm.LEGACY,
975978
'hashfn': legacy_hash
979+
},
980+
{
981+
'body': rawData[4],
982+
'algo': HashAlgorithm.LEGACY,
983+
'hashfn': legacy_hash
976984
}]
977985

978986
def testAlgoHandlers(self):

0 commit comments

Comments
 (0)