Skip to content

Commit

Permalink
Added new unit-tests, fixed minor issues
Browse files Browse the repository at this point in the history
  • Loading branch information
eandersson committed Aug 21, 2015
1 parent f838526 commit c000c2b
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

### Version 1.2.3-dev
- Added Client-side Heartbeat monitor.
- Added a Connection Timeout to Connection.open.
- Fixed potential bug in the Socket Poller Error handling.

### Version 1.2.2
- Added shortcuts for common properties in the Message class, e.g. message.app_id.
Expand Down
2 changes: 1 addition & 1 deletion amqpstorm/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def _wait_for_connection_to_open(self):
:return:
"""
start_time = time.time()
timeout = self.parameters['timeout']
timeout = self.parameters['timeout'] or 5
while not self.is_open:
if time.time() - start_time > timeout:
raise AMQPConnectionError('Connection timed out')
Expand Down
6 changes: 3 additions & 3 deletions amqpstorm/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ def is_ready(self):
self.timeout)
return bool(ready), bool(write)
except select.error as why:
if why.args[0] == EINTR:
return False, False
self.on_error(why)
if why.args[0] != EINTR:
self.on_error(why)
return False, False


class IO(Stateful):
Expand Down
29 changes: 29 additions & 0 deletions tests/connection_tests.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
__author__ = 'eandersson'

import ssl
import socket
import logging
import threading

from mock import MagicMock

try:
import unittest2 as unittest
except ImportError:
import unittest

from amqpstorm.io import IO
from amqpstorm import Connection
from amqpstorm.exception import *

Expand Down Expand Up @@ -78,3 +83,27 @@ def test_close_state(self):
def test_open_channel_on_closed_connection(self):
connection = Connection('127.0.0.1', 'guest', 'guest', lazy=True)
self.assertRaises(AMQPConnectionError, connection.channel)

def test_wait_for_connection(self):
connection = Connection('127.0.0.1', 'guest', 'guest', timeout=5,
lazy=True)
connection.set_state(connection.OPENING)
io = IO(connection.parameters)
io.socket = MagicMock(name='socket', spec=socket.socket)
connection.io = io

def func(conn):
conn.set_state(conn.OPEN)

threading.Timer(function=func, interval=1, args=(connection, )).start()
connection._wait_for_connection_to_open()

def test_wait_for_connection_raises_on_timeout(self):
connection = Connection('127.0.0.1', 'guest', 'guest', timeout=1,
lazy=True)
connection.set_state(connection.OPENING)
io = IO(connection.parameters)
io.socket = MagicMock(name='socket', spec=socket.socket)
connection.io = io
self.assertRaises(AMQPConnectionError,
connection._wait_for_connection_to_open)
1 change: 0 additions & 1 deletion tests/io_tests.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
__author__ = 'eandersson'

import ssl
import mock
import socket
import logging

Expand Down

0 comments on commit c000c2b

Please sign in to comment.