HyukjinKwon commented on code in PR #60423:
URL: https://github.com/apache/spark/pull/60423#discussion_r4571826574


##########
python/pyspark/sql/tests/connect/streaming/test_parity_listener.py:
##########
@@ -282,6 +282,33 @@ def load_event(event_name, table_name):
             # Remove again to verify this won't throw any error
             self.spark.streams.removeListener(test_listener)
 
+    def 
test_stopped_session_with_listeners_is_collected_without_a_warning(self):
+        # stop() releases the session, which removes its server side listener, 
ends the event
+        # stream and the handler thread, and closes the client. 
SparkSession.__del__ then closes
+        # the listener bus, which must send no removal on the closed client, 
and so warn
+        # nothing, with two listeners as with one.
+        import gc
+        import warnings
+        import weakref
+
+        session = self.spark.newSession()
+        session.streams.addListener(TestListenerLocalV1())
+        session.streams.addListener(TestListenerLocalV2())
+        thread = session.streams._sqlb._execution_thread
+        collected = weakref.ref(session)
+        with warnings.catch_warnings(record=True) as caught:
+            warnings.simplefilter("always")
+            session.stop()

Review Comment:
   Done in b192a8e: the test masks `SPARK_LOCAL_REMOTE` around `stop()`, as 
test_connect_context.py does, so only this session is released and the local 
server of the suite keeps running. The whole module passes locally in the 
default `local[4]` mode, including `test_streaming_progress` after this test.



##########
python/pyspark/sql/tests/connect/streaming/test_parity_listener.py:
##########
@@ -282,6 +282,33 @@ def load_event(event_name, table_name):
             # Remove again to verify this won't throw any error
             self.spark.streams.removeListener(test_listener)
 
+    def 
test_stopped_session_with_listeners_is_collected_without_a_warning(self):
+        # stop() releases the session, which removes its server side listener, 
ends the event
+        # stream and the handler thread, and closes the client. 
SparkSession.__del__ then closes
+        # the listener bus, which must send no removal on the closed client, 
and so warn
+        # nothing, with two listeners as with one.
+        import gc
+        import warnings
+        import weakref
+
+        session = self.spark.newSession()
+        session.streams.addListener(TestListenerLocalV1())
+        session.streams.addListener(TestListenerLocalV2())

Review Comment:
   Done in b192a8e: the test runs with one listener and with two.
   
   Running it showed one more thing: in the local mode of the suite, it also 
passed on master and on 200e25d, with either number. 
`ReusedConnectTestCase.conf()` sets `senderMaxStreamDuration` to 1s and 
`senderMaxStreamSize` to 123 bytes, so the client reattaches the event stream. 
After `stop()`, that reattach fails with `INVALID_HANDLE.SESSION_CLOSED`. The 
error path of the handler then clears the bus before `close()` runs, so no 
version sends a removal.
   
   The test is now in a class of its own, `StreamingListenerSessionStopTests`, 
which sets the two configurations back to their defaults (2m and 1g). There, 
the release ends the event stream, as on a server with the default 
configurations. Locally in `local[4]` mode, it fails on master with one 
listener, fails on 200e25d with both numbers, and passes on this PR. The same 
steps give the same results against a standalone 4.3.0 server.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to