Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
Merge pull request #716 from mozilla-services/bug/692a
Browse files Browse the repository at this point in the history
feat: Add integration tests for bridges
  • Loading branch information
pjenvey authored Oct 20, 2016
2 parents a6086cd + 5bc3abe commit 97a453a
Show file tree
Hide file tree
Showing 4 changed files with 288 additions and 23 deletions.
21 changes: 13 additions & 8 deletions autopush/router/apns2.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class APNSClient(object):
def __init__(self, cert_file, key_file, topic,
alt=False, use_sandbox=False,
max_connections=APNS_MAX_CONNECTIONS,
logger=None, metrics=None):
logger=None, metrics=None,
load_connections=True):
"""Create the APNS client connector.
The cert_file and key_file can be derived from the exported `.p12`
Expand Down Expand Up @@ -57,24 +58,28 @@ def __init__(self, cert_file, key_file, topic,
:type logger: logger
:param metrics: Metric recorder
:type metrics: autopush.metrics.IMetric
:param load_connections: used for testing
:type load_connections: bool
"""
self.server = SANDBOX if use_sandbox else SERVER
self.port = 2197 if alt else 443
self.ssl_context = hyper.tls.init_context(cert=(cert_file, key_file))
self.log = logger
self.metrics = metrics
self.topic = topic
self._max_connections = max_connections
self.connections = deque(maxlen=max_connections)
if load_connections:
self.ssl_context = hyper.tls.init_context(cert=(cert_file,
key_file))
self.connections.extendleft((HTTP20Connection(
self.server,
self.port,
ssl_context=self.ssl_context,
force_proto='h2') for x in range(0, max_connections)))
if self.log:
self.log.info("Starting APNS connection")

self.connections.extendleft((HTTP20Connection(
self.server,
self.port,
ssl_context=self.ssl_context,
force_proto='h2') for x in range(0, max_connections)))

def send(self, router_token, payload, apns_id,
priority=True, topic=None, exp=None):
"""Send the dict of values to the remote bridge
Expand Down
10 changes: 6 additions & 4 deletions autopush/router/apnsrouter.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class APNSRouter(object):
log = Logger()
apns = None

def _connect(self, rel_channel):
def _connect(self, rel_channel, load_connections=True):
"""Connect to APNS
:param rel_channel: Release channel name (e.g. Firefox. FirefoxBeta,..)
Expand All @@ -38,16 +38,18 @@ def _connect(self, rel_channel):
APNS_MAX_CONNECTIONS),
topic=cert_info.get("topic", default_topic),
logger=self.log,
metrics=self.ap_settings.metrics)
metrics=self.ap_settings.metrics,
load_connections=load_connections)

def __init__(self, ap_settings, router_conf):
def __init__(self, ap_settings, router_conf, load_connections=True):
"""Create a new APNS router and connect to APNS"""
self.ap_settings = ap_settings
self._base_tags = []
self.apns = dict()
self._config = router_conf
for rel_channel in self._config:
self.apns[rel_channel] = self._connect(rel_channel)
self.apns[rel_channel] = self._connect(rel_channel,
load_connections)
self.ap_settings = ap_settings
self.log.debug("Starting APNS router...")

Expand Down
2 changes: 1 addition & 1 deletion autopush/router/fcm.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def _process_reply(self, reply, notification, router_data, ttl):
# acks:
# for reg_id, msg_id in reply.success.items():
# updates
result = reply.get('results', [])[0]
result = reply.get('results', [{}])[0]
if reply.get('canonical_ids'):
old_id = router_data['token']
new_id = result.get('registration_id')
Expand Down
Loading

0 comments on commit 97a453a

Please sign in to comment.