Commits

ha...@velum.net  committed e54267f

Fixed logic bug in duplex disconnect.

  • Participants
  • Parent commits ab2f03d

Comments (0)

Files changed (4)

File stompclient/connection.py

     def disconnect(self, conf=None):
         """
         Disconnect from the server, if connected.
+        
+        @raise NotConnectedError: If the connection is not currently connected. 
         """
         if self._sock is None:
-            return
+            raise NotConnectedError()
         try:
             self._sock.close()
         except socket.error:

File stompclient/duplex.py

         Sends DISCONNECT frame and disconnect from the server.
         """
         try:
-            if not self.connection.connected:
+            if self.connection.connected:
                 with self.subscription_lock:
                     # Need a copy since unsubscribe() removes the destination from the collection.
                     subcpy = copy(self.subscribed_destinations)
                         self.unsubscribe(destination)
                 disconnect = frame.DisconnectFrame(extra_headers=extra_headers)
                 result = self.send_frame(disconnect)
-                self.connection.disconnect()
+                try:
+                    self.connection.disconnect()
+                except NotConnectedError:
+                    pass
                 return result
         finally:
             self.shutdown_event.set()

File stompclient/simplex.py

         if self.connection.connected:
             disconnect = frame.DisconnectFrame(extra_headers=extra_headers)
             result = self.send_frame(disconnect)
-            self.connection.disconnect()
+            try:
+                self.connection.disconnect()
+            except NotConnectedError:
+                pass
             return result
         
     def send(self, destination, body=None, transaction=None, extra_headers=None):

File stompclient/tests/test_duplex.py

                
     def test_disconnect(self):
         """ Make sure that disconnect results in expected frames. """
+        self.mockconn.connected = True
         self.client.disconnect()
+        print self.mockconn.send.call_args
         
         (sentframe,) = self.mockconn.send.call_args[0]
         expected = frame.DisconnectFrame()