Commits

Benjamin Smith committed fb9db75

Catch socket exception when not connected. Test for polling.

  • Participants
  • Parent commits 2629497

Comments (0)

Files changed (2)

             self._send_command("DISCONNECT", conf)
         except self.NotConnectedError:
             pass
-        self.sock.shutdown(0)
+        try:
+            self.sock.shutdown(0)
+        except socket.error, exc:
+            # likely wasn't connected
+            pass
         self.connected = False
 
     def send(self, conf=None):

tests/test_stomp.py

         assert self.frame.calls('send_frame', send_args.as_string())
         assert self.stomp.sock.calls('shutdown', 0)
 
+    def should_raise_not_connected_error(self):
+        self.stomp.disconnect()
+        
 
 class WhenProducingMessages(DingusTestCase(Stomp)):
 
         assert built_frame_args['command'] == 'SUBSCRIBE'
         assert self.frame.calls('send_frame', send_args.as_string())
 
+    def should_poll(self):
+        this_frame = self.stomp.poll()
+        assert self.stomp.frame.calls('get_message', nb=True)
+
     def should_receive_and_ack(self):
         this_frame = self.stomp.receive_frame()
         assert self.stomp.frame.calls('get_message')
         self.failUnlessRaises(stompy.NotConnectedError, mystomp.send,
                               {"body": "f"})
 
-    def should_raise_nc(self):
+    def should_raise_nc_when_sending(self):
         mystomp = Stomp('localhost', 99999)
         try:
             mystomp.send({"body": "Vandelay Industries"})
             return
         assert False # Should raise not connected
 
+    def should_set_disconnected_even_when_nc(self):
+        mystomp = Stomp('localhost', 99999)
+        mystomp.disconnect()
+        assert not mystomp.connected
 
 class WhenSocketCantConnect(TestCase):