@@ -98,13 +98,9 @@ def test_closing_connection_closes_commands(self, mock_thrift_client_class):
9898 mock_thrift_client_class: Mock for ThriftBackend class
9999 """
100100
101+ # Test once with has_been_closed_server side, once without
101102 for closed in (True , False ):
102103 with self .subTest (closed = closed ):
103- # Set initial state based on whether the command is already closed
104- initial_state = (
105- CommandState .CLOSED if closed else CommandState .SUCCEEDED
106- )
107-
108104 # Mock the execute response with controlled state
109105 mock_execute_response = Mock (spec = ExecuteResponse )
110106
@@ -114,11 +110,14 @@ def test_closing_connection_closes_commands(self, mock_thrift_client_class):
114110 )
115111 mock_execute_response .has_been_closed_server_side = closed
116112 mock_execute_response .is_staging_operation = False
117- mock_execute_response .command_id = Mock ( spec = CommandId )
113+ mock_execute_response .description = []
118114
119- # Mock the backend that will be used
115+ # Mock the backend that will be used by the real ThriftResultSet
120116 mock_backend = Mock (spec = ThriftDatabricksClient )
121117 mock_backend .staging_allowed_local_path = None
118+ mock_backend .fetch_results .return_value = (Mock (), False )
119+
120+ # Configure the decorator's mock to return our specific mock_backend
122121 mock_thrift_client_class .return_value = mock_backend
123122
124123 # Create connection and cursor
@@ -137,16 +136,22 @@ def test_closing_connection_closes_commands(self, mock_thrift_client_class):
137136 # Execute a command - this should set cursor.active_result_set to our real result set
138137 cursor .execute ("SELECT 1" )
139138
139+ # Verify that cursor.execute() set up the result set correctly
140+ self .assertIsInstance (cursor .active_result_set , ThriftResultSet )
141+ self .assertEqual (
142+ cursor .active_result_set .has_been_closed_server_side , closed
143+ )
144+
140145 # Close the connection - this should trigger the real close chain:
141146 # connection.close() -> cursor.close() -> result_set.close()
142147 connection .close ()
143148
144149 # Verify the REAL close logic worked through the chain:
145150 # 1. has_been_closed_server_side should always be True after close()
146- assert real_result_set .has_been_closed_server_side is True
151+ self . assertTrue ( real_result_set .has_been_closed_server_side )
147152
148- # 2. op_state should always be CLOSED after close()
149- assert real_result_set .op_state == CommandState .CLOSED
153+ # 2. status should always be CLOSED after close()
154+ self . assertEqual ( real_result_set .status , CommandState .CLOSED )
150155
151156 # 3. Backend close_command should be called appropriately
152157 if not closed :
@@ -183,6 +188,7 @@ def test_arraysize_buffer_size_passthrough(
183188 def test_closing_result_set_with_closed_connection_soft_closes_commands (self ):
184189 mock_connection = Mock ()
185190 mock_backend = Mock ()
191+ mock_backend .fetch_results .return_value = (Mock (), False )
186192
187193 result_set = ThriftResultSet (
188194 connection = mock_connection ,
@@ -209,6 +215,7 @@ def test_closing_result_set_hard_closes_commands(self):
209215 mock_session .open = True
210216 type(mock_connection ).session = PropertyMock (return_value = mock_session )
211217
218+ mock_thrift_backend .fetch_results .return_value = (Mock (), False )
212219 result_set = ThriftResultSet (
213220 mock_connection , mock_results_response , mock_thrift_backend
214221 )
0 commit comments