Skip to content
This repository has been archived by the owner on Nov 23, 2020. It is now read-only.

Commit

Permalink
added test for subscribe connection error
Browse files Browse the repository at this point in the history
  • Loading branch information
lsbardel committed Oct 23, 2016
1 parent a6a0bc4 commit 4d35988
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pulsar/apps/data/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ async def _connect(self, next_time):
)
await gather(*[c.connect() for c in self.channels.values()])
except ConnectionRefusedError:
self.status = StatusType.disconnected
next_time = backoff(next_time) if next_time else RECONNECT_LAG
self.logger.critical(
'%s cannot subscribe - connection error - '
Expand All @@ -194,7 +195,7 @@ async def _connect(self, next_time):
next_time
)
self._loop.call_later(next_time,
self._loop.make_task,
self._loop.create_task,
self.connect(next_time))


Expand Down
21 changes: 21 additions & 0 deletions tests/stores/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,27 @@ def fire(channel, event, data):
await channels.close()
self.assertEqual(channels.status, StatusType.closed)

async def test_fail_subscribe(self):
channels = self.channels()
original, warning, critical = self._patch(
channels, channels.pubsub, 'subscribe'
)
await channels.connect()
args, kw = await critical.end
self.assertEqual(len(args), 3)
self.assertEqual(args[1], channels)
self.assertEqual(args[2], 2)
critical.end = create_future()
args, kw = await critical.end
self.assertEqual(len(args), 3)
self.assertEqual(args[1], channels)
self.assertEqual(args[2], 2.25)
channels.pubsub.subscribe = original
args, kw = await warning.end
self.assertEqual(len(args), 3)
self.assertEqual(args[1], channels)
self.assertEqual(args[2], channels.status_channel)

async def test_fail_publish(self):
channels = self.channels()
original, warning, critical = self._patch(
Expand Down

0 comments on commit 4d35988

Please sign in to comment.