Skip to content

Commit

Permalink
Ignore and log invalid kwargs passed to Providers
Browse files Browse the repository at this point in the history
fixes #148
  • Loading branch information
BrianJKoopman committed Oct 22, 2020
1 parent b91c9dc commit fc44347
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ocs/agent/aggregator.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing import Dict

import txaio
txaio.use_twisted()

from ocs import ocs_feed

Expand Down Expand Up @@ -151,7 +152,7 @@ class Provider:
txaio logger
"""
def __init__(self, address, sessid, prov_id, frame_length=5*60, fresh_time=3*60):
def __init__(self, address, sessid, prov_id, frame_length=5*60, fresh_time=3*60, **kwargs):
self.address = address
self.sessid = sessid
self.frame_length = frame_length
Expand All @@ -167,6 +168,8 @@ def __init__(self, address, sessid, prov_id, frame_length=5*60, fresh_time=3*60)
self.last_refresh = time.time() # Determines if
self.last_block_received = None

self.log.warn("Recieved unxpected keyword argument(s): {kwarg}", kwarg=kwargs)

def encoded(self):
return {
'last_refresh': self.last_refresh,
Expand Down
7 changes: 7 additions & 0 deletions tests/test_aggregator.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,3 +363,10 @@ def test_g3_cast():
for x in incorrect_tests:
with pytest.raises(TypeError) as e_info:
g3_cast(x)

# Tests related to #148
def test_arbitrary_args_to_provider():
"""Unexpected kwargs should be ignored."""
malformed_agg_params = {'not a valid key': 60,
'frame length': 120}
provider = Provider('test_provider', 'test_sessid', 3, 1, **malformed_agg_params)

0 comments on commit fc44347

Please sign in to comment.