mirror of
https://github.com/internetarchive/warcprox.git
synced 2025-01-18 13:22:09 +01:00
raise exception if heartbeat status_info is missing required fields
This commit is contained in:
parent
c5da679b1d
commit
a1c5a08790
@ -59,6 +59,13 @@ class ServiceRegistry(object):
|
|||||||
Returns updated status info on success, un-updated status info on
|
Returns updated status info on success, un-updated status info on
|
||||||
failure.
|
failure.
|
||||||
'''
|
'''
|
||||||
|
for field in 'role', 'heartbeat_interval', 'load':
|
||||||
|
if not field in status_info:
|
||||||
|
raise Exception(
|
||||||
|
'status_info is missing required field %s', field)
|
||||||
|
val = status_info['heartbeat_interval']
|
||||||
|
if not (isinstance(val, float) or isinstance(val, int)) or val <= 0:
|
||||||
|
raise Exception('heartbeat_interval must be a number > 0')
|
||||||
updated_status_info = dict(status_info)
|
updated_status_info = dict(status_info)
|
||||||
updated_status_info['last_heartbeat'] = r.now()
|
updated_status_info['last_heartbeat'] = r.now()
|
||||||
if not 'first_heartbeat' in updated_status_info:
|
if not 'first_heartbeat' in updated_status_info:
|
||||||
|
2
setup.py
2
setup.py
@ -3,7 +3,7 @@ import codecs
|
|||||||
|
|
||||||
setuptools.setup(
|
setuptools.setup(
|
||||||
name='doublethink',
|
name='doublethink',
|
||||||
version='0.2.0.dev73',
|
version='0.2.0.dev74',
|
||||||
packages=['doublethink'],
|
packages=['doublethink'],
|
||||||
classifiers=[
|
classifiers=[
|
||||||
'Programming Language :: Python :: 2.7',
|
'Programming Language :: Python :: 2.7',
|
||||||
|
@ -80,6 +80,30 @@ def test_leader_election(rr):
|
|||||||
|
|
||||||
def test_service_registry(rr):
|
def test_service_registry(rr):
|
||||||
svcreg = doublethink.ServiceRegistry(rr)
|
svcreg = doublethink.ServiceRegistry(rr)
|
||||||
|
# missing required fields
|
||||||
|
with pytest.raises(Exception) as excinfo:
|
||||||
|
svcreg.heartbeat({})
|
||||||
|
with pytest.raises(Exception) as excinfo:
|
||||||
|
svcreg.heartbeat({"role":"foo","load":1})
|
||||||
|
with pytest.raises(Exception) as excinfo:
|
||||||
|
svcreg.heartbeat({"role":"foo","heartbeat_interval":1.0})
|
||||||
|
with pytest.raises(Exception) as excinfo:
|
||||||
|
svcreg.heartbeat({"heartbeat_interval":1.0,"load":1})
|
||||||
|
|
||||||
|
# invalid heartbeat interval (we accept anything for load and role)
|
||||||
|
with pytest.raises(Exception) as excinfo:
|
||||||
|
svcreg.heartbeat({"heartbeat_interval":-1,"role":"foo","load":1})
|
||||||
|
with pytest.raises(Exception) as excinfo:
|
||||||
|
svcreg.heartbeat({"heartbeat_interval":"strang","role":"foo","load":1})
|
||||||
|
with pytest.raises(Exception) as excinfo:
|
||||||
|
svcreg.heartbeat({"heartbeat_interval":[],"role":"foo","load":1})
|
||||||
|
with pytest.raises(Exception) as excinfo:
|
||||||
|
svcreg.heartbeat({"heartbeat_interval":[1],"role":"foo","load":1})
|
||||||
|
with pytest.raises(Exception) as excinfo:
|
||||||
|
svcreg.heartbeat({"heartbeat_interval":{},"role":"foo","load":1})
|
||||||
|
with pytest.raises(Exception) as excinfo:
|
||||||
|
svcreg.heartbeat({"heartbeat_interval":{1:2},"role":"foo","load":1})
|
||||||
|
|
||||||
assert svcreg.available_service("yes-such-role") == None
|
assert svcreg.available_service("yes-such-role") == None
|
||||||
assert svcreg.available_services("yes-such-role") == []
|
assert svcreg.available_services("yes-such-role") == []
|
||||||
assert svcreg.available_services() == []
|
assert svcreg.available_services() == []
|
||||||
|
Loading…
x
Reference in New Issue
Block a user