You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by as...@apache.org on 2023/04/11 21:38:46 UTC

[qpid-proton] branch main updated: PROTON-2401: [Python] on_xxx_closed should be called on locally closed after remote close

This is an automated email from the ASF dual-hosted git repository.

astitcher pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-proton.git


The following commit(s) were added to refs/heads/main by this push:
     new 0847d3aed PROTON-2401: [Python] on_xxx_closed should be called on locally closed after remote close
0847d3aed is described below

commit 0847d3aed940714c4da57353ccf753a88e456983
Author: Sebastiaan la Fleur <se...@ns.nl>
AuthorDate: Fri Jun 25 15:17:51 2021 +0200

    PROTON-2401: [Python] on_xxx_closed should be called on locally closed after remote close
    
    When links/sessions/connections are remotely closed then locally closed the on_xxx_closed
    event should still fire. The existing code only fires this event for local then remote close.
---
 python/proton/_handlers.py           | 12 +++++++++
 python/tests/proton_tests/reactor.py | 49 ++++++++++++++++++++++++++++++++++++
 2 files changed, 61 insertions(+)

diff --git a/python/proton/_handlers.py b/python/proton/_handlers.py
index 1d390886c..b9e553b4b 100644
--- a/python/proton/_handlers.py
+++ b/python/proton/_handlers.py
@@ -406,6 +406,10 @@ class EndpointStateHandler(Handler):
             self.on_link_closing(event)
         event.link.close()
 
+    def on_link_local_close(self, event: Event) -> None:
+        if self.is_remote_closed(event.link):
+            self.on_link_closed(event)
+
     def on_session_remote_close(self, event: Event) -> None:
         if event.session.remote_condition:
             self.on_session_error(event)
@@ -415,6 +419,10 @@ class EndpointStateHandler(Handler):
             self.on_session_closing(event)
         event.session.close()
 
+    def on_session_local_close(self, event: Event) -> None:
+        if self.is_remote_closed(event.session):
+            self.on_session_closed(event)
+
     def on_connection_remote_close(self, event: Event) -> None:
         if event.connection.remote_condition:
             if event.connection.remote_condition.name == "amqp:connection:forced":
@@ -428,6 +436,10 @@ class EndpointStateHandler(Handler):
             self.on_connection_closing(event)
         event.connection.close()
 
+    def on_connection_local_close(self, event: Event) -> None:
+        if self.is_remote_closed(event.connection):
+            self.on_connection_closed(event)
+
     def on_connection_local_open(self, event: Event) -> None:
         if self.is_remote_open(event.connection):
             self.on_connection_opened(event)
diff --git a/python/tests/proton_tests/reactor.py b/python/tests/proton_tests/reactor.py
index fbc376b1e..1107c4143 100644
--- a/python/tests/proton_tests/reactor.py
+++ b/python/tests/proton_tests/reactor.py
@@ -636,6 +636,55 @@ class ContainerTest(Test):
         assert client_handler.connect_failed
         assert client_handler.server_addr is None, client_handler.server_addr
 
+    class _ClosingServerHandler(MessagingHandler):
+        def __init__(self, host):
+            super().__init__()
+            self.host = host
+            self.port = free_tcp_port()
+            self.client_addr = None
+            self.peer_hostname = None
+            self.closed = None
+            self.listener = None
+
+        def on_connection_opened(self, event):
+            self.client_addr = event.connected_address
+            self.peer_hostname = event.connection.remote_hostname
+            event.connection.close()
+            self.listener.close()
+
+        def on_connection_closed(self, event):
+            assert not self.closed
+            self.closed = True
+
+        def listen(self, container):
+            self.listener = container.listen("%s:%s" % (self.host, self.port))
+
+    class _ClosedClientHandler(MessagingHandler):
+        def __init__(self):
+            super().__init__()
+            self.server_addr = None
+            self.closed = None
+
+        def on_connection_opened(self, event):
+            self.server_addr = event.connected_address
+
+        def on_connection_closing(self, event):
+            event.connection.close()
+
+        def on_connection_closed(self, event):
+            assert not self.closed
+            self.closed = True
+
+    def test_closed_event(self):
+        server_handler = ContainerTest._ClosingServerHandler("localhost")
+        client_handler = ContainerTest._ClosedClientHandler()
+        container = Container(server_handler)
+        server_handler.listen(container)
+        container.connect(url="localhost:%s" % server_handler.port,
+                          handler=client_handler, reconnect=False)
+        container.run()
+        assert server_handler.closed
+        assert client_handler.closed
 
 class SelectorTest(Test):
     """Test the Selector"""


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org